in reply to funky $_ with map {}

i bet $_ gets a special instance when inside a sub{}.

whaddyathink?

how about:

map { $_ => eval qq(sub{"<h1>$_</h1>"}) } 1..6

here the $_ gets evaluated inside map{} before being inside the sub{}

hmm?

Replies are listed 'Best First'.
Re: Re: funky $_ with map {}
by Juerd (Abbot) on Mar 03, 2002 at 10:40 UTC
    $_ is less special than you think. It wouldn't have worked with a global named $foo either. The eval-solution you gave has already been given (by yours truly).

    use vars qw($foo); { $foo = 'foo'; sub xyzzy { print "$foo\n"; } } $foo = 'bar'; xyzzy(); # Prints bar now.

    But:
    { my $foo = 'foo'; sub xyzzy { print "$foo\n"; } } my $foo = 'bar'; xyzzy(); # Prints the 'foo' that stayed shared.


    Update - s/\$f\b/\$foo/, thanks Kanji.

    ++ vs lbh qrpbqrq guvf hfvat n ge va Crey :)
    Nabgure bar vs lbh qvq fb jvgubhg ernqvat n znahny svefg.
    -- vs lbh hfrq OFQ pnrfne ;)
        - Whreq