You're viewing a comment by maryum and its responses.

February 09, 2010, 17:45

hello...
i have recently started learning perl.....and having issues when i try to read input from another file. the details of a script that i tried to run are as follows:

i made a text file by the name “text.txt” and the contents were
Sidra|38|BE
Hira|48|BE
Shagufta|50|BE

Then i wrote the following script

open(DAT, "text.txt");
$data_file=" text.txt ";
open(DAT, $data_file);
@raw_data=;

hello...
i have recently started learning perl.....and having issues when i try to read input from another file. the details of a script that i tried to run are as follows:

i made a text file by the name “text.txt” and the contents were
Sidra|38|BE
Hira|48|BE
Shagufta|50|BE

Then i wrote the following script

open(DAT, "text.txt");
$data_file=" text.txt ";
open(DAT, $data_file);
@raw_data=;
close(DAT);
foreach $student (@raw_data)
{
chomp($student);
($name,$roll_no,$class)=split(/\|/,$student);
print "The student $name bearing roll number $roll_no is in class $class";
print "\n";
}

the script produces no output and displays a message saying
“readline () closed filehandle at line ”
I tried the same with another file by the name “text.dat” holding the same data but it did not work either. Please help me out resolving this issue.
Thankyou...

Reply To This Comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the first letter of your name: (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.