Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Your favourite gory detail...

by ihb (Deacon)
on Jun 20, 2004 at 23:41 UTC ( #368342=note: print w/replies, xml ) Need Help??


in reply to Re: Your favourite gory detail...
in thread Your favourite gory detail...

Yes, there is a difference.

\() is like a factored out reference operator before every thing inside the parenthesis, so \($foo, @bar, %baz, &frah) is (\$foo, \@bar, \%baz, \&frah), except if there's only one aggregate data type inside it. In that case it gets flattened and the backslash is then applied to each element of that list, as you say. This means that

\((@foo), @bar)
becomes
(\(@foo), \@bar)
which becomes
(\($foo[0], $foo[1], ..., $foo[$#foo]), \@bar)
and finally
((\$foo[0], \$foo[1], ..., \$foo[$#foo]), \@bar)

Another example:

\((@foo, @bar), @baz) (\(@foo, @bar), \@baz) ((\@foo, \@bar)), \@baz)

Update: I just realized that my second example is rather useless as the end result is the same as if there was no inner parenthesis. But the intermediate step perhaps still has a pedagogical value.

(I don't know if this recursive behaviour is how it's actually performed under the hood, but it works this way none the less.)

ihb

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2021-10-24 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?