[comp.lang.perl] print @ar; bug or feature

ccount@athena.mit.edu (Craig A Counterman) (06/07/90)

Is this a bug?  It doesn't matter much to me, but someone pointed it
out, an now I really would like to know why this is so.

perl -e '$ar[0] = 3;$ar[3] = 5;$\="\n";print @ar;print "@ar";'

prints "33   5".  Why?  It prints @ar only till it hits an undefined
element, but interpolating the @ar in a string constant works as it
should.  print @ar also fails to print the newline.

It looks like 'print @ar' is at some point expanding to
"3\000\000\0005\n", and only the part till the first nul is being
printed.

Curiously,
Craig

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (06/07/90)

In article <1990Jun7.031545.27669@athena.mit.edu> ccount@athena.mit.edu (Craig A Counterman) writes:
: Is this a bug?  It doesn't matter much to me, but someone pointed it
: out, an now I really would like to know why this is so.
: 
: perl -e '$ar[0] = 3;$ar[3] = 5;$\="\n";print @ar;print "@ar";'
: 
: prints "33   5".  Why?  It prints @ar only till it hits an undefined
: element, but interpolating the @ar in a string constant works as it
: should.  print @ar also fails to print the newline.

It's a bug, and will be fixed in the next patch.

: It looks like 'print @ar' is at some point expanding to
: "3\000\000\0005\n", and only the part till the first nul is being
: printed.

Something like that.  Actually, the routine that prints each element of
the array was returning FALSE if you tried to print a non-existent element
when it should have returned TRUE, so the array value printer aborted
in the middle with what it thought was an error.  Hmm, I obviously need
some coffee.

Larry