Bob Ackerman wrote:
>
> On Monday, March 4, 2002, at 12:15 PM, John W. Krahn wrote:
> >
> > print +(split //, "abcd")[1], "\n";
>
> now that is clever! what is the literal meaning/function of the '+'.
> of course, one still must know that a leading paren will be seen by 'print'
> unless there
now that is clever! what is the literal meaning/function of the '+'.
of course, one still must know that a leading paren will be seen by 'print'
unless there is some intervening dummy character. that's ok.
On Monday, March 4, 2002, at 12:15 PM, John W. Krahn wrote:
> print +(split //, "abcd")
Bob Ackerman wrote:
>
> 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 tha
-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 //,"
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.
#!/usr/bin/perl -w
my $x = "abcd";
print substr($x,3,1);
from perldoc perlfunc:
substr EXPR,OFFSET,LENGTH,REPLACEMENT
substr EXPR,OFFSET,LENGTH
substr EXPR,OFFSET
Extracts a substring out of EXPR and returns it. First character
is at offset `0', or whatever you've set `$['
You can use substr($x,2,1) which would get the third character. You can use a
variable for the position and for the number of characters.
Wags ;)
-Original Message-
From: bob ackerman [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 04, 2002 09:13
To: [EMAIL PROTECTED]
Subject: st
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="ab
of course i do suppose the easiest way in perl is to say:
print substr("abcd",2,1),"\n";
i guess that is good enough.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]