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

    The OP’s experience is quite surprising to me, because, when out of curiosity I tried the same thing on my friendly neighborhood Linux box, I got this:

    /user/bin/perl: bad interpreter: No such file or directory

      As do I actually, but it's the only obvious thing that is wrong in the post.

      Perhaps it's because it's a Mac, or some weird way OP is calling the script.

      I know nothing of Mac computers, but I do know they don't have /user/bin. Without further clarification, it's a guessing game (unless a mac person can test).

        "... (unless a mac person can test)."

        I don't think I'd really like "mac person" as an epithet; however, I do have one, and I did test.

        This sub-thread progressed somewhat since I started to prepare my post. I didn't see the replies until after I'd posted. I wholeheartedly agree with your:

        "A lot of squiggly lines and plain text butchery so it's hard to read."

        There also appears to be factual errors in what he wrote, but® «... maybe“(!?)” ‘am’ just™» gettinglost® [in the] pUnCtUaTiOn™.

        — Ken

      A reply falls below the community's threshold of quality. You may see it by logging in.