--- "McCormick, Rob E" <[EMAIL PROTECTED]> wrote:
> gang,
> 
> # problem:  open a file
> # find lines that meet a condition, put them in an output file
> 
> Could you share some patterns/sample code that you use to accomplish
> this task?  What pattern do you use when the output file doesn't
exist
> when the script begins?
> 
> The code below errors with:
> C:\WINNT\Profiles\rem27920\Desktop\perl>remove_lines.pl
> syntax error at C:\WINNT\Profiles\rem\Desktop\perl\remove_lines.pl
> line 7,
> near ", >" Execution of 
> C:\WINNT\Profiles\rem\Desktop\perl\remove_lines.pl
> aborted due to compilation errors.
> 
> #!c:/perl/bin/perl -w
> use strict;
> 
> my $file = 'c:/winnt/profiles/rem/desktop/old_websites.txt';
> my $outfile = 'c:/winnt/profiles/rem/desktop/old_web2.txt';
> open(INFO, "$file") or die "$!"; # file open w/error check
> open(RESULT, >$outfile);  # tried "$outfile" as well...

That's gotta have quotes. try
 open(RESULT, ">$outfile") or die "$0:$!";

> my @lines = grep { ! /_vti_cnf/ } <INFO>;

Another bug. <INFO> reads the whole file here, so that there'll be
nothing left to read in the statement below.

> while (<INFO>) {
>       print RESULT;
>       }

Try this:
 print RESULT grep { ! /_vti_cnf/ } <INFO>;

That covers the read loop, the record selection, and the output to the
desired file. =o)

Then you can close files as you like.

> #print (@lines, $outfile );  # prints lines to STDOUT, and the
> filename
> # print (join "\n", @lines);  # print files, one per line
> 
> close INFO;
> close RESULT;
> 
> thank you,
> Rob
> --
> Rob McCormick
> [EMAIL PROTECTED] 
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Reply via email to