Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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);


Comment on Re: What I am missing here
Select or Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-07-29 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls