in reply to Still having problems with spanish characters

Speaking of things being written in a "somewhat weird fashion", I find this bothersome (even as corrected by almut):
while ($linein = <FILEIN2>) { chomp $linein; @arrayin = split /:/, $linein; if (exists $arrayin[0] && $arrayin[0] eq "Default") { $englishword = trim( $arrayin[1] ); } if (exists $arrayin[0] && $arrayin[0] eq "Spanish_LatinAmerican|es +_MX") { $spanishword = trim( $arrayin[1] ); } if (exists $arrayin[0] && $arrayin[0] eq "Spanish_LatinAmerican|es +_MX") { $langhash{$spanishword} = $englishword; } }
I think this would make more sense:
while (<FILEIN2>) { next unless ( /.:\s*\S/ ); # necessary/sufficient condition for w +hat follows my ( $lang, $text ) = split /:/, $_, 2; if ( $lang eq "Default" ) { $englishword = trim( $text ); # takes care of chomping } elsif ( $lang eq "Spanish_LatinAmerican|es_MX" ) { $spanishword = trim( $text ); $langhash{$spanishword} = $englishword; } }
It seemed to me that the OP code was doing too many unnecessary tests with all those "if" conditions, and they actually weren't entirely appropriate to the task: you only check for the existence of the first array element, and then do something with the second array element whether it exists or not.

And I would agree with the Anonymonk who thinks that "weird" is an understatement when describing a subroutine with a for loop that does a "return" on each iteration... {grin}

Replies are listed 'Best First'.
Re^2: Still having problems with spanish characters
by almut (Canon) on Sep 29, 2007 at 16:58 UTC
    ... "weird" is an understatement when describing a subroutine with a for loop that does a "return" on each iteration...

    Maybe one should mention (in defense of the OP being wrongfully picked upon), that this particular piece of code had been suggested as is by one of our Grandmasters...
    </Mother-Teresa-mode>

      Ah! Well, then... point well taken, to be sure. And now that you mention it, the first term that sprang to my mind on seeing that snippet was: clever.

      (And as we all know, one person's cleverness might sometimes go in directions where another person might prefer not to follow. ;)