Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

RE: RE: A minor epiphany with grep and map

by mwp (Hermit)
on Jul 27, 2000 at 03:57 UTC ( #24604=note: print w/replies, xml ) Need Help??

in reply to RE: A minor epiphany with grep and map
in thread A minor epiphany with grep and map

@$self->{ITEMS} @$x->{y}

$self->{ITEMS} (or $x->{y}) returns a reference or pointer to an array of values. The @-operator dereferences it to be used by the map and grep functions.

This could have been much more clearly written as:

@{ $x->{y} }

But if wishes were fishes... :) My point is that there's nothing magical about this, and doesn't really require an "examination."

Hope this helps, or at least makes sense with all that chaos out there.

I am the lurker that spams in the night.

(UPDATE: I understand what chip is saying, and I'm not trying to be a smartass. I think he's reading into the code a little too deeply. Just wanted to clarify things for some of the less experienced readers. :P)

Replies are listed 'Best First'.
The hash ref hits!--more--You are confused
by chip (Curate) on Jul 28, 2000 at 23:09 UTC
    I'm sorry, Alakaboo, you didn't understand what I wrote at all.

    Given the precedence rules, @$x->{y} is not the same as @{$x->{y}}. Rather, it's the same as (@$x)->{y}. Look at the output of -Dx and -Dts if you don't believe me.

    In fact, now that I try a simple test, the original code can't work:

    $ perl -le '$x={y=>[1]}; print @$x->{y}' Not an ARRAY reference at -e line 1. $ perl -le '$x={y=>[1]}; print @{$x->{y}}' 1

    So let's see the full code to the original, OK?

        -- Chip Salzenberg, Free-Floating Agent of Chaos

      No, I understood *sigh* I'm just an idiot... I was under the impression that @$x->{y} would work and not die. I guess I gave Perl too much of a benefit of the doubt.

      My apologies Chip, it was good of you to point that out. I hope that *I* didn't come across as being snippy.

      Best regards,


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2021-06-23 12:53 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (120 votes). Check out past polls.