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 expression:

  $string =~ s/^.(.*).$/$1/;

Another solution, and most probably a lot faster, is this one:

  $string = substr( $string, 1, (length($string) - 2) );

If you don't need the speed, stick with the first solution.


-- 
Tore Aursand <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to