#!/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 `$[' to (but don't do that). If OFFSET is negative (or more precisely, less than `$['), starts that far from the end of the string. If LENGTH is omitted, returns everything to the end of the string. If LENGTH is negative, leaves that many characters off the end of the string. > -----Original Message----- > From: bob ackerman [mailto:[EMAIL PROTECTED]] > Sent: Monday, March 04, 2002 9:13 AM > 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] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]