leading spaces and Perl.

Sergey Kuznetsov tlug-9a/WvBvX2Qpg9hUCZPvPmw at public.gmane.org
Fri Oct 24 17:57:42 UTC 2003


On October 24, 2003 01:55 pm, Lance F. Squire wrote:
> talexb-SBdzbUvMQDunS0EtXVNi6w at public.gmane.org wrote:
> > Hi Lance,
> >
> > When you say that
> >
> >   s/^\s//;
> >
> > doesn't work (presumably to remove leading spaces), what do you mean? Are
> > you sure you are operating on the right variable? For example, don't do
> >
> >   foreach my $line ( @lines ) {
> >     s/^\s//;
> >   }
> >
> > because $line will remain untouched.
>
> Test code in question.
>
> $Uname = $DB->quote($Uname);
> print "Uname='$Uname'\n<br>";
> #Kill leading and trailing spaces
> $Uname =~ s/^\s+//;
> print "Remove leading spaces = '$Uname'<br>\n";
> $Uname =~ s/\s+$//;
> print "Remove trailing spaces = '$Uname'<br>\n";

just do it in this way:

$Uname =~ s/(?:^\s+|\s+$)//g;

It will remove trailing spaces from both sides in one call.

All the Best!
Serge
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list