in reply to open and read text file
#!/usr/bin/perl ----^^--------- # you have an "e" here
Also, don't use bareword filehandles, and always check that open() succeeded using its three-arg form, and use warnings; use strict; ...yadayada
use warnings; use strict; my $fh = open '<', 'Test1.txt' or die "can't open the damned file!: $!"; while (<$fh>){ chomp; # this will remove the newline from $_ print "I saw $_ in the file\n"; }
Call with perl script.pl, or to call it without requiring using the perl command, add:
#!/usr/bin/perl
...not:
#/user/bin/perl ----^-- remove the "e"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: open and read text file
by locked_user sundialsvc4 (Abbot) on Jul 22, 2017 at 00:09 UTC | |
by stevieb (Canon) on Jul 22, 2017 at 01:08 UTC | |
by kcott (Archbishop) on Jul 22, 2017 at 03:54 UTC | |
by karlgoethebier (Abbot) on Jul 22, 2017 at 13:10 UTC | |
by kcott (Archbishop) on Jul 23, 2017 at 01:58 UTC | |
| |
|