in reply to reading input from a file

You should always post the code your are using. Since your code does not even compile, we can not reproduce your error.

Post your actual code in code tags: see Writeup Formatting Tips.

use strict and warnings

From the code you have shown, there seems to be no need to read your whole file into an array; you could read it in line-by-line and process it as you go. That would save memory if your input file is large. UNTESTED:

use strict; use warnings; my $file = 'text.txt'; open my $fh, '<', $file or die "can not open $file: $!"; while (<$fh>) { chomp; my ($name, $roll_no, $class) = split /\|/; print "The student $name bearing roll number $roll_no is in class +$class\n"; } close $fh;

If you really do need to read the file into an array, you could slurp that file (and slurp it good!): File::Slurp.

Updated with code example.

Replies are listed 'Best First'.
Re^2: reading input from a file
by Hir@ (Initiate) on Feb 09, 2010 at 11:41 UTC
    i have made a user directory by the name of VOIP2..i went into VOIP2 and made 2 dir file2.pl using mkdir file2.pl and mkdir text.txt the perl script you suggested exists in file2.pl ..and now when i run it once i m in file2.pl it gives the following error: cant open text.txt: NO SUCH FILE OR DIRECTORY AT ./FILE2.PL LINE5. could it be because once i m in file2.pl it cant view text.txt?? should i not be using mkdir?? please help!! thanks