For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2005 > RE : Forcing array context









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RE : Forcing array context
Jose Nyimi

2005-08-20, 6:56 pm

Try this:

echo hello: world | perl -lne '$aref =3D [ split(/:/, $_) ]; print =
$aref'

[] synthax gives a ref to the array returned by split()

HTH,
Jos=E9.

-----Message d'origine-----
De : Binish A R [mailto:binishar@poornam.com]=20
Envoy=E9 : samedi 20 ao=FBt 2005 17:15
=C0 : Perl Beginners
Objet : Forcing array context


How can I force array context ...=20
like

# echo hello: world | perl -lne '$aref =3D split(/:/, $_); print $aref'

but thatz giving the length of the array ... I want $aref to be a
reference ...
How is that possible ??

A workaround is to use the following

# echo hello: world | perl -lne '@ar =3D split(/:/, $_); $aref =3D =
\@ar;'

But I'm not satisfied with that as I've to use an extra variable @ar ...
:(

Any help ...
=20
=20

--=20


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com