perl kweschun

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: der.hans
Date:  
Subject: perl kweschun
Am 21. May, 2002 schwätzte Kevin Buettner so:

> On May 21, 11:32pm, Roderick Ford wrote:
>
> > Does anybody know if, in perl, I 'push' an empty list or array to an
> > array, does the array still grow by one? Or should I handle the
> > indexing manually in those cases where it is empty. Sometimes my array
> > that I am pushing is empty, but I still want the array to grow by one.
>
> If you do...
>
>     @foo = ();
>     @bar = ();
>     push @bar, @foo;

>
> ...you'll find that @bar is empty afterward.
>
> If you want to push a value on even when @foo is empty, you could do
> it like this:
>
>     push @bar, (@foo ? @foo : undef);


Guess I was wrong :).

Lesson: null string does not constitute and empty list.

$ perl -e '@a = (); print "$#a\n"; push( @a, @a ); print "$#a\n"; push( @a,
"" ); print "$#a\n";'
-1
-1
0
$

ciao,

der.hans
--
# https://www.LuftHans.com/
# Like the maid, I don't do (M$)Windows. - der.hans