Missing first arg in list causes error
Jacqui Caren
jacqui.caren at ntlworld.com
Sat Feb 11 15:09:38 GMT 2006
Paul Makepeace wrote:
> This just bit me,
>
> $ perl -le 'print [,"",,]'
> syntax error at -e line 1, near "[,"
> Execution of -e aborted due to compilation errors.
> $ perl -le 'print ["",,,]'
> ARRAY(0x814ac28)
> $
>
> Why does the first one fail?
>
> Paul
Because '',,, is consumed in list context into ('')
Try perl -de 1
DB<12> x ['',,,,]
0 ARRAY(0x8355568)
0 ''
DB<13>
Because [,''] is a typo and perl reports this (IMHO a good thing).
it will fail to compile.
DB<7> x [,'']
syntax error at (eval 10)[/usr/lib/perl5/5.8.1/perl5db.pl:618] line 2,
near "[,"
but [(),''] or [undef,''] are valid.
DB<14> x [(),'']
0 ARRAY(0x8395d80)
0 ''
DB<15> x [undef,'']
0 ARRAY(0x835555c)
0 undef
1 ''
DB<16>
Jacqui
More information about the london.pm
mailing list