Re: Chopping off first&last character in a string

2003-10-08 Thread Rob Dixon
William Li wrote: > > Silly question, is there an equal but opposite function to chop in Perl? > I'd like to remove the first and last character of a string and am looking > for a simple way to do it. So far I have: > > # "1234567" -> "23456" > chop($string); # "123456" > $string = reverse($strin

Re: Chopping off first&last character in a string

2003-10-07 Thread Tore Aursand
On Tue, 07 Oct 2003 12:56:50 -0400, Li, William wrote: > Silly question, is there an equal but opposite function to chop in Perl? No. > I'd like to remove the first and last character of a string and am looking > for a simple way to do it. The most elegant way to do it, IMO, is to use a regular

RE: Chopping off first&last character in a string

2003-10-07 Thread david
Rob Hanson wrote: > You could just use a regex... > > $string =~ s/.//; > > Or even substr()... > > substr($string, 0, 1, ''); > > Both look equally efficient. except they are different and they don't work the same way: [panda]$ perl -le '$_="\n1234"; s/.//; print' 234 [panda]$ perl -le '$_

RE: Chopping off first&last character in a string

2003-10-07 Thread david
Rob Hanson wrote: >> $string =~ s/^.(.*).$/$1/; > > It's prettier, but it's very inefficient. It's probably 20+ times slower > then doing it in two steps. > > It has to do with how Perl internally handled string data. When you s/// > or substr() all it does is move a pointer. > this is an

RE: Chopping off first&last character in a string

2003-10-07 Thread Hanson, Rob
eed to rewrite the whole string value, which is pretty expensive in comparison. Rob -Original Message- From: James Edward Gray II [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 07, 2003 6:07 PM To: Li, William Cc: [EMAIL PROTECTED] Subject: Re: Chopping off first&last character in

Re: Chopping off first&last character in a string

2003-10-07 Thread James Edward Gray II
On Tuesday, October 7, 2003, at 11:56 AM, Li, William wrote: Hi, Howdy. Silly question, is there an equal but opposite function to chop in Perl? I'd like to remove the first and last character of a string and am looking for a simple way to do it. So far I have: # "1234567" -> "23456" chop($s

RE: Chopping off first&last character in a string

2003-10-07 Thread Hanson, Rob
off first&last character in a string Hi, Silly question, is there an equal but opposite function to chop in Perl? I'd like to remove the first and last character of a string and am looking for a simple way to do it. So far I have: # "1234567" -> "23456" chop($str

Chopping off first&last character in a string

2003-10-07 Thread Li, William
Hi, Silly question, is there an equal but opposite function to chop in Perl? I'd like to remove the first and last character of a string and am looking for a simple way to do it. So far I have: # "1234567" -> "23456" chop($string); # "123456" $string = reverse($string); # "654321" chop($string);