Why doesn't this work? I want to take any leading or trailing white spaces out. 
If I remove the remark it works, but I
do not understand why it requires the second line

 

Script:

 

#!/usr/bin/perl

use strict;

use warnings;

my $string = "   hello   ";

print "$string";

print "Tony";

            $string =~ s/^(\s+)(.*)(\s+)$/$2/;

#          $string =~ s/\s+$//;

print "$string";

print "Tony";

 

results with the remark in place, note the spaces after the second 'hello':

 

sarge-plain:~# ./Perl-2.pl

   hello   Tonyhello   Tonysarge-plain:~#

 

results with the remark removed:

 

sarge-plain:~# ./Perl-2.pl

   hello   TonyhelloTonysarge-plain:~#

 

 

Tony Heal

 

 

Reply via email to