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
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
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 '$_
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
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
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
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
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);