Prev: Where is the document for \ (backslash operator for creating a reference)
Next: Where is the document for \ (backslash operator for creating a reference)
From: Peng Yu on 4 Jun 2010 11:20 I think that $_[0] should give me 'a' in the following example. But it doesn't. Could you help understand why? How to get the first argument? $ ./main.pl ab b $ cat main.pl #!/usr/bin/env perl use strict; use warnings; sub mysub { print @_, "\n"; print $_[0], print $_[1], "\n"; } mysub 'a', 'b';
From: RedGrittyBrick on 4 Jun 2010 11:36 On 04/06/2010 16:20, Peng Yu wrote: > I think that $_[0] should give me 'a' in the following example. But it > doesn't. Could you help understand why? How to get the first argument? > > $ ./main.pl > ab > b > > $ cat main.pl > #!/usr/bin/env perl > > use strict; > use warnings; > > sub mysub { > print @_, "\n"; > print $_[0], print $_[1], "\n"; print $_[0], $_[1], "\n"; > } > > mysub 'a', 'b'; -- RGB
From: Peter J. Holzer on 5 Jun 2010 18:38
On 2010-06-04 15:20, Peng Yu <pengyu.ut(a)gmail.com> wrote: > I think that $_[0] should give me 'a' in the following example. But it > doesn't. Could you help understand why? How to get the first argument? > > $ ./main.pl > ab > b > That's not true. Your program prints ab <newline> b <newline> a1 <no newline here> (The shell prompt may obscure the last line due to the missing newline, but in any case there is no empty line after "b") As an exercise, figure out why > print $_[0], print $_[1], "\n"; > } prints "b\na1". hp |