Hi Noah,

On Tuesday 14 September 2010 17:19:17 Noah wrote:
> Hi there,
> 
> what is the easiest way to change all the keys that are now placed as
> elements in an array to lowercase?
> 
> my @sitenamekeys = sort keys (%sites);
> print "site @sitenamekeys\n";
> exit 0;

To change @sitenamekeys (which I'll call @site_name_keys for clarity) in 
place, say:

[code]
foreach my $key (@site_name_keys)
{
        $key = lc($key);
}
[/code]

This can be shortened into:

[code]
$_ = lc($_) foreach (@site_name_keys);
[/code]

If you want to return a new array, you can use map:

[code]
my @lowercased_keys = (map { lc($_) } @site_name_keys);
[/code]

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
List of Portability Libraries - http://shlom.in/port-libs

God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to