thats is get whatever item of the split array i want without using an
intermediate variable
just curious
Insert the appropriate parenthesis according to the precedence of
operators (that may not always be what you expect) :
print ( (split(/,/,$ARGV[0])) [1] )
--
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
Try print (split /,/,$a)[1];
--
Regards,
Dick
Sent via Deja.com
http://www.deja.com/
"Dick Latshaw" <lats...@my-deja.com> wrote in message
news:91nphd$pmh$1...@nnrp1.deja.com...
Use a "list slice" (see the "Slices" section in perldata.pod):
$second_element = ( split(/,/, $a) )[1]
^ ^
^ ^
Patterns should _look like_ patterns, not like strings.
--
Tad McClellan SGML consulting
ta...@metronet.com Perl programming
Fort Worth, Texas
>this brings up a lot of errors - no compile
For me too..
>>
>> Try print (split /,/,$a)[1];
my $tmp = (split/,/, $string)[1];
print $tmp. "\n";
Works fine..
--
Richard Zilavec
rzil...@tcn.net
which is parsed as
(print (split /,/,$a))[1];
and then doesn't work.
>> Try print (split /,/,$a)[1];
>this brings up a lot of errors - no compile
That is because the parentheses make what's between them the arguments
for print(). Putting a '+' in front of the opening paren will change
that. '+' has no other effect, so +"foo" is still "foo". Or, as Richard
Zilavec wrote, stuff the result of the expression into a variable first,
and use that.
--
Bart.