in reply to for vs. reverse

This works, maybe this is not as good as the others.
@_ = (@{$_ = [qw{emacs vi}]}, reverse @$_); print "Why do we have to hide from the police, daddy ? Because they us +e ", shift @_, " and we use ", shift @_, ", son.\n" while(@_);
but I can't figure out why this doesn't work. Doesn't shift work on @_ by default?
@_ = (@{$_ = [qw{emacs vi}]}, reverse @$_); print "Why do we have to hide from the police, daddy ? Because they us +e ", shift, " and we use ", shift, ", son.\n" while(@_);

Replies are listed 'Best First'.
Re: Re: for vs. reverse
by chipmunk (Parson) on Mar 28, 2001 at 09:33 UTC
    but I can't figure out why this doesn't work. Doesn't shift work on @_ by default?

    Yes and no: see shift. This is an example of Do What I Mean (DWIM). Inside a subroutine or format, shift works on @_ by default. Outside a subroutine, however, shift works on @ARGV by default.

    #!perl -l @ARGV = '@ARGV'; @_ = '@_'; print '$ARGV[0] = ', shift; mysub(@_); sub mysub { print '$_[0] = ', shift; }