in reply to Re: YAlQ: Yet Another local() Question.
in thread YAlQ: Yet Another local() Question.

Ah, that would also explain why there is the IMHO arbitrary restriction that you can only localize global variables, and not lexical ones. Why something like:
{ my $fh; sub init_print_log { $fh = shift;} sub print_log { print $fh scalar localtime,@_;} sub print_log_altfile { local $fh = shift; print_log(@_);} }
is illegal, even though the -concept-, if not that particular example, is useful.

UPDATE: Yes, save() would be a better name... better than some of the others that have been suggested. Someone also suggested renaming my() to local(). I hope that one doesn't fly.

Replies are listed 'Best First'.
My vs. YAlQ: Yet Another local() Question.
by chip (Curate) on Aug 04, 2000 at 06:38 UTC
    Actually, I have a patch that makes local() work on lexical variables. Larry didn't want to use it because he thought people would be too confused. :-(

    And I wouldn't worry about my() being renamed to local(). Larry chose the word "my" at least in part because it's short and easy to read and write.

        -- Chip Salzenberg, Free-Floating Agent of Chaos