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

Re: What I am missing here

by Riales (Hermit)
on Mar 20, 2012 at 20:01 UTC ( #960643=note: print w/replies, xml ) Need Help??

in reply to What I am missing here

When you call pick_a_card, the subroutine is actually getting a copy of @deck. Pass a reference instead:
sub pick_a_card { my $deck = shift; return pop @$deck; } pick_a_card(\@deck);

Replies are listed 'Best First'.
Re^2: What I am missing here
by heatblazer (Scribe) on Mar 21, 2012 at 05:31 UTC

    Hmm.. so it`s just a C-like error of mine. Sorry, I am still learning Perl, so I didn`t know that a special reference will be needed in the case. Well, thanks a lot, I`ll keep in mind that for the future.

    I`ll look into references ( pointers ) asap when I finish the regexp part of perl, which I find a bit confusing. I guess pointers are as powerful as they were in C... I just had no idea there are any since Perl is garbage collected and, dunno... maybe I am a bit noob to this :)

      Well, I would say that references are kind of a step up in terms of abstraction from pointers. For example, in C, you can point a pointer at pretty much any arbitrary space in memory; I don't think you can do that with references in Perl. I also don't think you could perform arithmetic on references (not that this is a great idea in C anyways).

      In my mind, Perl references are much simpler. They always point to a thing, and you just have to remember to dereference it to use the thing it's pointing to.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://960643]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2018-02-20 00:49 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (266 votes). Check out past polls.