Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Re: Re: Re: NEWBIE Brain Teaser

by hiroki (Novice)
on Apr 16, 2001 at 19:29 UTC ( #72839=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: NEWBIE Brain Teaser
in thread NEWBIE Brain Teaser

i am not a "more monkish Monk", but i did get curious about this behavior of foreach. This is an alias (example modified from _Advanced Perl Programming_ (O'rielly) by Sriram Srinivasan):
$a = 10; # saclar a @a = (1, 2, 3); # array a *b = *a; # aliases b to a $a++; # increments $a :) $b++; # same as saying $a++ print "$b, $a"; # prints: 12 12 @b[0] = 4; # same as saying $a[0] = 4
as you can see, the aliasing on line 3 makes any manipulation of $b, @b or %b manipulate $a, @a, %a respectively. hope this helps and is not too confusing. if i'm wrong, tell me :)

Replies are listed 'Best First'.
Re (tilly) 5: NEWBIE Brain Teaser
by tilly (Archbishop) on Apr 16, 2001 at 19:53 UTC
    That aliasing command relies on typeglobs to work.

    Therefore it will only work with global variables. (ie you must localize with local, not my.) I stay away from that except when it really doesn't make sense not to. :-)

    The mostly widely used form of that kind of aliasing in modern Perl is for exporting symbols using Exporter.

    FWIW one goal for Perl 6 is to kill typeglobs entirely. The functionality should be available, but by a different mechanism...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://72839]
help
Chatterbox?
[ambrus]: Now it has five people instead of three, some sort of call number ticket system where people wait a lot for their food to get ready (it's the same kinds of grilled meat and fish on the same equipment, it won't actually fry slower),
[ambrus]: it's slow as hell, and the food costs significantly more.
[ambrus]: We no longer eat there.
LanX Everybody quotes it, some people read it, and a few people go by it
[ambrus]: LanX: why would I read it? isn't it a book for managers? I don't want to be a manager.
[ambrus]: I don't quote it either.
[erix]: it's really a software book, albeit about experiences from the 60s-80s. People haven't changed all that much though.
[erix]: a software project book, is probably more exact
[ambrus]: Yes, but I'm not managing software teams either.
[ambrus]: I'm not only not a restaurant manager, but also not a software manager.

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (16)
As of 2017-09-22 13:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (264 votes). Check out past polls.

    Notices?