in reply to Re^2: First attempt at bringing in file for input/output
in thread First attempt at bringing in file for input/output
To further clarify this and another thread having to do with while loop and $line=<filehande>:
To fix the first error message,...#!usr/bin/perl use strict; use warnings; while (my $line =<DATA> and $line !~ /^\s*$/) { print "do somehing with non blank line\n"; } __END__ Value of <HANDLE> construct can be "0"; test with defined() at C:\User +s\mmtho\Documents\PerlProjects\Monks\test_myVar_inwhile.pl line 5. Global symbol "$line" requires explicit package name (did you forget t +o declare "my $line"?) at C:\Users\mmtho\Documents\PerlProjects\Monks +\test_myVar_inwhile.pl line 5. Execution of C:\Users\mmtho\Documents\PerlProjects\Monks\test_myVar_in +while.pl aborted due to compilation errors.
Back up and fix just this error message...#!usr/bin/perl use strict; use warnings; while (defined (my $line =<DATA>) and $line !~ /^\s*$/) { print "do somehing with non blank line\n"; } __END__ Global symbol "$line" requires explicit package name (did you forget t +o declare "my $line"?) at C:\Users\mmtho\Documents\PerlProjects\Monks +\test_myVar_inwhile_ver2.pl line 6. Execution of C:\Users\mmtho\Documents\PerlProjects\Monks\test_myVar_in +while_ver2.pl aborted due to compilation errors.
To make this work completely:#!usr/bin/perl use strict; use warnings; my $line; while ($line =<DATA> and $line !~ /^\s*$/) { print "do somehing with non blank line\n"; } __END__ Value of <HANDLE> construct can be "0"; test with defined() at C:\User +s\mmtho\Documents\PerlProjects\Monks\test_myVar_inwhile_ver2.pl line +7. do somehing with non blank line do somehing with non blank line
#!usr/bin/perl use strict; use warnings; my $line; while (defined($line =<DATA>) and $line !~ /^\s*$/) { print "do somehing with non blank line\n"; } __END__ do somehing with non blank line do somehing with non blank line do somehing with non blank line do somehing with non blank line
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: First attempt at bringing in file for input/output
by hippo (Archbishop) on Oct 24, 2018 at 08:43 UTC | |
by Marshall (Canon) on Oct 25, 2018 at 18:53 UTC | |
by soonix (Chancellor) on Oct 26, 2018 at 08:15 UTC | |
by Marshall (Canon) on Nov 02, 2018 at 23:37 UTC |