On 2012-03-03 09:08, lina wrote:
$ perl extract.pl try.tex
Bareword "filename" not allowed while "strict subs" in use at extract.pl line 8.
Execution of extract.pl aborted due to compilation errors.


#!/usr/bin/env perl

use strict;
use warnings;

Good.

my $filename = $ARGV[0] ;

open FILE, "<", filename or die $!;
                  ^^^^^^^^
You're trying to read from a bareword 'filename', and not $filename :)

Some would say to rewrite that open statement like this:

open my $file, '<', $filename or die "Can't open $filename: $!";

my @line =<FILE>  ;

That sucks in the entire file into @line all at once, so remove it.

while (<FILE>) {
        print $_;
}

the while() block should be rewritten as such:

while ( my $line = <$file> ){
        print $line;
}

Steve

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to