On Sep 14, John_Kennedy said:
>print oBOTH "@UNLOCKED\n";
>
>How can I prevent the blank lines from the grep or how can I remove the
>blank lines from @UNLOCKED?
This was a recently-added question to the FAQ (in perlfaq5, under the
title "Why do I get weird spaces when I print an array of lines?
Why not using chomp instead?
from perlfunc:
"This safer version of chop removes any trailing string that
corresponds to the current value of $/ ..."
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Well, I think a regex is your best bet.
---
$data = 'This is a very long string ';
$data =~ s/\s+$//;
---
That will trim all trailing spaces.
Without a regex you could try something like
---
$data = 'This is a very long string ';
do {
$_ = $data;
$test = chop;
cho
Lightning flashed, thunder crashed and Dave Neill <[EMAIL PROTECTED]> whispered:
| There's also:
|
| $foo =~ s/^\s*//;
You should always use /^\s+/. There's no sense in removing nothing if
nothing is there.
-spp
--
Stephen P Potter [EMAIL PROTECTED]
"You
There's also:
$foo =~ s/^\s*//;
and if you want to strip leading and trailing spaces:
$foo =~ s/^\s*(.*?)\s*$/$1/;
Though some say that the two step:
$foo =~ s/^\s*//;
$foo =~ s/\s*$//;
is faster. There's also a module:
String::Strip
with a function
StripLTSpace()
and it's fore and aft v
Hello,
Of course this regex only removes the leading spaces only, or the
trailing spaces if there are no leading spaces.
You can use
$string =~ s/^ +| +$//g; # g for global matches
or do it in 2 steps:
$str =~ s/^ +//;
$str =~ s/ +$//;
Hope this helps,,,
Aziz,,,
In article <00a301c1101e$ac7d4a
On Thu, Jul 19, 2001 at 12:19:10PM +0530, Rahul Garg wrote:
> well i want to remove spaces if any in the beginning and end of a string.
> how to do this...
perldoc -q 'strip blank space' or
http://www.perldoc.com/perl5.6/pod/perlfaq4.html#How%20do%20I%20strip%20blank%20space%20from%20the%
This should do it for you:
$sring =~ s/^ +| +$//;
Brian Johnson
Partner/Systems Administrator/Programmer
Source1Hosting.tv, LLC (www.source1hosting.tv)
Source1Results.com, LLC (www.source1results.com)
I may be insane, but remember - The only
difference between an insane man and a
genius is his j