Dear all!

I'm writing a module (strictly for in-house use!) for
converting an in-house legacy encoding -- from the time when
you had to fake the ordinary alphabet + whatever special
characters you needed onto the 223 characters of whatever
8-bit encoding your OS happened to support -- to Unicode.

I have no problem with the character transliteration as
such but I want to have an option to the
transliteration subroutine for outputting Unicode
characters as HTML entities.

What I have so far is:

:    use HTML::Entities;
:
:    sub transliterate ($;$){ my($text,$option) = @_;
:
:        # Begin troblesome part!
:        if($option && ref $option ne 'HASH'){
:            die "The second argument to transliterate() must"
:                . "be a hash reference"; }
:        # End troublesome part
:
:        # Doing transliteration stuff to $text here!
:
:        if($$option{html}){
:            $text = encode_entities($text)
:        }
:        return $text;
:    }

so that using the function will look like this:

    $text = transliterate($text,{html = 1});

I want to ensure that the second argument, if it exists, is
a hash reference, and die with a complaint if it is not!
What I wonder is if there is some 'automatic' way to do the
check rather than using the conditional to check within the
sub as I have done, preferably if there is a way to tell the
prototype that it should look for a hash reference.

Also, and perhaps more importantly, is there any way to
tell the module to HTML-encode the output of
transliterate() when I import the module, sort of like use-
ing the module with options:

    use MyTransliterator --html-entities;

Sorry it looks silly, but I don't know how to explain
it better!

TIA,

/Benct

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to