Re: string indexing

2002-03-04 Thread John W. Krahn
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

Re: string indexing

2002-03-04 Thread bob ackerman
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")

Re: string indexing

2002-03-04 Thread John W. Krahn
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

RE: string indexing

2002-03-04 Thread Nikola Janceski
-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 //,"

Re: string indexing

2002-03-04 Thread bob ackerman
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.

RE: string indexing

2002-03-04 Thread Stout, Joel R
#!/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 `$['

RE: string indexing

2002-03-04 Thread Wagner-David
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

RE: string indexing

2002-03-04 Thread Nikola Janceski
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

Re: string indexing

2002-03-04 Thread bob ackerman
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]