Jeff 'Japhy' Pinyan wrote:
>
> On Nov 12, Rob Dixon said:
>
> ><[EMAIL PROTECTED]> wrote:
> >>
> >> I have this written in the script to parse it:
> >> while ($line = <OLDFILE>) {
> >> # $line = $line =~ /^\s*(.*)\s*\n$/;
> >> $line =~ s/^ //;
> >> $line =~ s/ $//;
> >> $line =~ s/\t/|/g;
> >> $line =~ s/\s+/ /mg;
> >> $line =~ s/^\s*//mg;
> >> $line =~ s/\s*$//mg;
> >> $line =~ s/\s*$//mg;
> >> ### The following lines mod the files to reflect inches and feet
> >> $line =~ s/"/in./mg;
> >> $line =~ s/'/ft./mg;
> >
> > while (<OLDFILE>) {
> >
> > s/\t/|/g; # change tab separators to pipes
>
> I'd use tr/\t/|/, and add a chomp() before-hand.
>
> > s/^\s+//; # remove all leading space
> > s/\s+$//; # and trailing space
> > s/\s+/ /g; # and compress multiple spaces
>
> I'm assuming by \s we're really just expecting tabs and spaces, but I'll
> include carriage returns and formfeeds. I'd be tempted to change these
> THREE regexes:
>
> # pick ONE of the following TWO:
> tr/\r\t\f / /s; # squashes consecutive [\r\t\f ]'s to a single space
> # or
> s/\s+/ /g;
>
> # then do both of the following:
> s/^ //; # remove a SINGLE leading space
> s/ $//; # remove a SINGLE trailing space
Hi Jeff.
/\s/ is the same as /[\t\n\f\r ]/ so the chomp will be done
by s/\s+$// or tr/\t\n\f\r / /s.
You're right, the tr// would be faster, but I absolutely never
use it unless I need to optimise. Nor do I buy a new machine
unless I can afford one of double the clock rate: nothing else
is noticeable!
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]