in reply to Re: Can't localize lexical variable $var at...
in thread Can't localize lexical variable $var at...

Just for completeness, you can localize an element of a lexical hash or array. How useful this is, I don't know.
#!/usr/bin/perl use warnings; my %hash = (a=>1, b=>2); { local $hash{'a'} = 999; print map {"$_ = $hash{$_}, "} sort keys %hash; print "\n"; } print map {"$_ = $hash{$_}, "} sort keys %hash; print "\n";
I've always been a little confused as to why this was implemented for elements of a lexical hash or array but not scalar

-Lee

"To be civilized is to deny one's nature."

Replies are listed 'Best First'.
Re: Re: Re: Can't localize lexical variable $var at...
by Elian (Parson) on Jun 10, 2002 at 07:18 UTC
    That's one of the things that slipped in under the radar. There's no real difference between elements of a lexical and global array or hash, so you can localize either with no penalty. It's a quirk of the implementation--whether it's a bug or not is arguable. (local's already got a number of problems, mainly when localizing anything with magic)