I'm not sure what you mean by your last question (what pattern do you
use when the output file...).

The error is due to the fact that outside of quotes the > is an operator
(greater than).  Try

        open( RESULT, ">$outfile" ) or die "$!";

With the single greater than ">" the output file will be created.  If it
existed before running the script, the contents of this file will be
erased.

With the double greater than ">>" the output file will be created.  If
it existed before running the script, the contents of this file will
remain and the new information will be appened to the file.

Hope this helps.

Dan


"McCormick, Rob E" 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...
> my @lines = grep { ! /_vti_cnf/ } <INFO>;
> while (<INFO>) {
>         print RESULT;
>         }
> 
> #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]

Reply via email to