Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Hacking perl

by shmem (Chancellor)
on Jan 15, 2007 at 11:42 UTC ( [id://594732]=note: print w/replies, xml ) Need Help??


in reply to Hacking perl

Definitely a nice hack, robin++ ... but it leaves a question open. Consider:

local *foo:

*foo = [qw (a b c)]; { local *foo = [qw(1 2 3)]; print "local \@{\*foo{ARRAY}} = qw(@{*foo{ARRAY}})\n"; print "local \@foo = qw(@foo)\n"; } print "global \@foo = qw(@foo)\n"; __END__ local @{*foo{ARRAY}} = qw(1 2 3) local @foo = qw(1 2 3) global @foo = qw(a b c)

my *foo:

*foo = [qw (a b c)]; { my *foo = [qw(1 2 3)]; print "my \@{\*foo{ARRAY}} = qw(@{*foo{ARRAY}})\n"; print "my \@foo = qw(@foo)\n"; } print "global \@foo = qw(@foo)\n"; __END__ my @{*foo{ARRAY}} = qw(1 2 3) my @foo = qw(a b c) global @foo = qw(a b c)

Hmm. The lexical glob is created ok, but other than with local, glob corresponding variables aren't treated as aliases to the typeglob entries in the current scope.

Now, should that happen? I think, it should; but such lookup should also warn about "masking an earlier @foo in the same scope".

What do you think?

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: Hacking perl
by robin (Chaplain) on Jan 16, 2007 at 14:10 UTC
    Yes, I'm inclined to agree.

    I didn't try and do that for this tutorial, because I thought I'd already done enough for demonstration purposes. (Also I'd been hacking all night and it was starting to get light.)

    It would be a fun exercise for someone to figure out how to do what you suggest, and a good way to learn about perl internals. Is anyone up for a challenge?

      Certainly I'm already at it... ;-)

      cheers,
      --shmem

      update: ;) others might be faster, though...

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://594732]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-28 08:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found