Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: My very confusing questions

by choroba (Chancellor)
on Jul 08, 2014 at 21:29 UTC ( #1092802=note: print w/replies, xml ) Need Help??

in reply to My very confusing questions

if no array is given then it uses the default @_
Inside a subroutine, shift and pop operate on @_, but in the main body of a program, they operate on @ARGV, which is what you generally want.

Update: Removed unshift and push as they are different. My mistake.

لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: My very confusing questions
by Random_Walk (Prior) on Jul 09, 2014 at 14:52 UTC

    Surely parameterless shift and pop, operate on @ARGV in the main, or @_ in a sub, as described. But unshift and push, unseasoned with parameters, are a syntax error.

    /usr/bin/perl -le '@ARGV=qw(this that more less);pop;shift;print join +"<>", @ARGV;' that<>more /usr/bin/perl -le '@ARGV=qw(this that more less);pop;shift;push;print +join "<>", @ARGV;' Not enough arguments for push at -e line 1, near "push;" /usr/bin/perl -le '@ARGV=qw(this that more less);pop;shift;unshift;pri +nt join "<>", @ARGV;' Not enough arguments for unshift at -e line 1, near "unshift;" /usr/bin/perl -le '@ARGV=qw(this that more less);pop;shift;push "X";pr +int join "<>", @ARGV;' Type of arg 1 to push must be array (not constant item) at -e line 1, +near ""X";" /usr/bin/perl -le '@ARGV=qw(this that more less);pop;shift;unshift "X +";print join "<>", @ARGV;' Type of arg 1 to unshift must be array (not constant item) at -e line +1, near ""X";"

    Or is there a cunning way to make them dance?


    Pereant, qui ante nos nostra dixerunt!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1092802]
[GotToBTru]: $aohoaoh->[0] is a hash reference, so $aohoaoh->[0]->{ key1} would work
[1nickt]: If 1nickt is the some guy, that's not what he said.
[GotToBTru]: thepkd might not know about last hour of cb
[1nickt]: my $x = $aohoaoh->[0]->{' foo'}->[0]->{'bar' }; should work
[thepkd]: its not $aohoaoh->[0]. its $aohoaoh[0]->{'foo '}. Tried it. Its working. Thnaks
[thepkd]: Hey 1nickt sorry man. What
[GotToBTru]: a ref too far ;)
[thepkd]: Yes this is my first time in cb. Trying to work my way around.

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2016-12-06 13:41 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (105 votes). Check out past polls.