Helgi said:
gnari said:
what's the deal with the return within the loop? you realize this
will just return the first argument (fixed), so the loop has no
real purpose, other than a fancy way to do $_=$_[0]
No, gnari, you are wrong. It will return the substituted text.
Try this with and without the return. You can feed the subroutine
either and array or a scalar. It will work with either.
No, it won't. If you feed it with an array (or a list), it will only
return the first element (as expected, since the return() function
interrupts the whole subroutine).
my @text = ('Þjóðlegir þýskir ferðamenn',
'líða ekki fúlar fréttir');
@text = fix_Icelandic_letters(@text);
print "@text\n";
Outputs:
Thjodlegir thyskir ferdamenn
But it can be fixed, of course:
sub fix_Icelandic_letters
{
for (@_)
{
tr/ÁÐÉÍÓÚÝÖáðéíóúýö/ADEIOUYOadeiouyo/;
s/Þ/Th/;
s/Æ/Ae/;
s/þ/th/;
s/æ/ae/;
}
wantarray ? @_ : $_[0];
}