in reply to open and read text file

Hello hchana,

Welcome to the monastery. Try this:

Execute it as perl <name.pl> <filename>

#!usr/bin/perl use strict; use warnings; while (<>) { print "$.\t$_"; # updating $. $.\t$_ } continue { close ARGV if eof; }

Update: Adding line output from ($.) to ($.\t$_).

Read more here eof.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: open and read text file
by hchana (Acolyte) on Nov 09, 2017 at 15:27 UTC

    I have managed to get this working on my Mac. My perl scripts needed to be stored in my home directory. Also when running the code using Komodo (as your stated in your reply) you need to write: perl filename.pl. I was not stating the perl pre-fix.The following code now works. Thanks for your help

    #!\usr\bin perl use warnings; use strict; use diagnostics; open(FILE, "Text1.txt"); while(<FILE>){ print "I saw the following in Text.txt file:\n$_\n"; } close FILE;