>while (<MYFILE>){
> $line = $_;
> chomp($line);
This can be shortened a few ways. i.e.
chomp ($line = $_);
There is probably a better way to get rid of the whitespace, but the only
one that comes to mind is:
s/^s+|s+$//; #replace any leading or ("|") trailing whitespace.
-Frank
-----Original Message-----
From: Booher Timothy B 1stLt AFRL/MNAC
[mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 03, 2002 9:54 AM
To: [EMAIL PROTECTED]
Subject: remove spaces before and after . . . howdoi?
o.k. my program finally works (thanks for the help yesterday) . . . but
I am
convinced I am doing this the long way . . . I am sure there is a more
elegant solution (prob a one-liner). Any thoughts . . .
thanks,
tim
#!/usr/bin/perl -w
# This program is just to test my ability to parse
open(MYFILE,'test2.txt');
$lNum = 1;
while (<MYFILE>){
$line = $_;
chomp($line);
next if $line =~ (/^\*+/)|(/^\s*$/); # no blank lines or lines that
start with ***
@splitLine = split(/:\s/,$line); # divide
$splitLine[0] =~ s/^\s*//; # remove leading spaces from
each
one
$splitLine[1] =~ s/^\s*//;
$splitLine[0] =~ s/^\s+$//; # remove trailing spaces from
each
one
$splitLine[1] =~ s/^\s+$//;
print "$lNum\: \"$splitLine[0]\",\"$splitLine[1]\"\n";
$lNum++;
};
____________________________________________________
Timothy B Booher, Lt USAF, AFRL/MNAC
101 West Eglin Blvd, Suite 339
Eglin AFB FL 32542-6810
Phone: 850-882-8302 Ext. 3360 (DSN 872-)
FAX: 850-882-2201
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]