On Jan 3, Booher Timothy B 1stLt AFRL/MNAC said:
>Why can't I do something like this? Load everything to a buffer then cycle
>through the buffer?
Why would you want to? That requires you to store the ENTIRE file in
memory!
>#!/usr/bin/perl -w
>open(MYFILE,'test2.txt');
>while (<MYFILE>) {
> $buffer .= $_;
>}
>$lnum = 1;
>
>while ($buffer) {
> chomp;
> next if /^\*+/ or /^\s*$/;
> my ($field, $value) = split /\s*:\s+/;
Those are all acting on $_, not $buffer. And what you'd need to do is
REMOVE stuff from $buffer.
> $field =~ s/^\s+//; # remove leading spaces from $field
> $value =~ s/\s+$//; # remove trailing spaces from $value
> print qq{$lnum: "$field","$value"\n};
> $lnum++;
>};
Just loop over the file's contents. Using a buffer like this is a bad
idea.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]