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.