actually without parenthesis around the array you are printing, perl gets
confused and returns the error:
Can't use subscript on print at - line 1, near "1]"

W/O the second set of parenthesis, print interperts the first open
parenthises for its function call:

print ("hello", "how are you");

but the subscript is illegal since print already claimed the first () for
itself;
print ("hello", "how are you")[2]; ## really means the following to perl
(print ("hello", "how are you"))[2]; ## which doesn't make sense.



-----Original Message-----
From: bob ackerman [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 04, 2002 1:03 PM
To: Nikola Janceski
Cc: [EMAIL PROTECTED]
Subject: Re: string indexing


ah. thank you. i needed the extra set of parens for the print statement.
although i thought
print (split //,"abcd")[1],"\n";
or
print ((split //,"abcd")[1]),"\n";
should work, i guess the first paren is assigned to 'print' and sees the 
right paren as ending the 'print' statement. seems oddish.


On Monday, March 4, 2002, at 09:24  AM, Nikola Janceski wrote:

> This should work:
> print ( (split(//,"abcd"))[1] ,"\n");
>
>
> -----Original Message-----
> From: bob ackerman [mailto:[EMAIL PROTECTED]]
> Sent: Monday, March 04, 2002 12:13 PM
> To: [EMAIL PROTECTED]
> Subject: string indexing
>
>
> I am used to indexing a string in other languages, so i would like to say
> $x="abcd";
> print $x[3];
> and see 'd' printed, but, of course, this isn't correct in perl.
>
> so i did
> @y=split(//,"abcd");
> print $y[2],"\n";
>
> and that's fine.
>
> now, how do i do that without an intermediate array.
> i want to say
> print split(//,"abcd")[1],"\n";
>
> but i get compilation error.
>
> or is there some built-in way to index a string?
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
----------------------------------------------------------------------------
> --------------------
> The views and opinions expressed in this email message are the sender's
> own, and do not necessarily represent the views and opinions of Summit
> Systems Inc.
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

----------------------------------------------------------------------------
--------------------
The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to