in reply to •Re: perl 1-liner to join a list?
in thread perl 1-liner to join a list?

Well, yes, actually I did. I thought that

push @a;

was equivalent to

push @a, $_;

in the same manner that

print;

is equivalent to

print $_;

Maybe I need to brush up on when $_ has to be used and when i can be omitted.

Is there a good ref material or camel chapter on this?

Ed

Replies are listed 'Best First'.
Re: Re: •Re: perl 1-liner to join a list?
by Nkuvu (Priest) on Nov 11, 2003 at 21:34 UTC

    perldoc -f push doesn't say anything about defaulting to $_. Also, looking up push in the Camel doesn't show the $_ box like it does for print (which is, conveniently, on the facing page in my Camel 3rd ed.)

    But I'm not criticizing, I might have made the same assumptions.

Re: Re: •Re: perl 1-liner to join a list?
by thens (Scribe) on Nov 12, 2003 at 12:46 UTC

    This is how I try to remember this.  push takes a list as argument and hence  $_ cannot be taken as a default argument for this.

    Update But then as Smylers pointed out  print also takes a list of arguments but still takes $_ as default argument when there is none. puzzling ??

    -T

    use perl; use strict;

      This is how I try to remember this. push takes a list as argument and hence $_ cannot be taken as a default argument for this.

      But print takes a list of things too (and prints them, joined by $,) yet uses $_ as the default, so that doesn't work as a distinguishing feature.

      Smylers