[KLUG Members] Perl string trim

Jacob Creutzfeldt members@kalamazoolinux.org
Tue, 30 Jul 2002 08:19:01 -0700 (PDT)


--- Tony Gettig <gettig@chartermi.net> wrote:
> Hey there,
> 
> I've looked, googled, and looked again but I must be
> missing something
> obvious. I have a string I need to trim all the
> extra spaces off of. For
> instance, if the variable value is
> "Dude____________" (where all the
> underscores are spaces), #!/usr/bin/perl -w

How about just doing a substitute with a regex
as follows:
-------------------------------------------
#!/usr/bin/perl -w
use strict;
my $string = 'Dude        ';

print "Before $string EOL\n";

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

print "After $string EOL\n"
--------------------------
This results in:

Before Dude         EOL
After Dude EOL




__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com