Current location: Hot Scripts Forums » Programming Languages » Perl » reading input from another file in perl scripting.


reading input from another file in perl scripting.

Reply
  #1 (permalink)  
Old 02-06-10, 08:37 AM
Hir@ Hir@ is offline
New Member
 
Join Date: Feb 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
reading input from another file in perl scripting.

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=<DAT>;
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 "<br>\n";
}


the script produces no output and displays a message saying
]“readline () closed filehandle at <filename> line <line number>”.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...

Last edited by Hir@; 02-06-10 at 08:44 AM.
Reply With Quote
  #2 (permalink)  
Old 02-17-10, 08:36 AM
Girish422 Girish422 is offline
New Member
 
Join Date: Feb 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Spin Its working fine

Hi dude i have also started learing perl recently
I tried with the same script and its working pretty well.
Do u have the perl script and the text file in same location??
Reply With Quote
  #3 (permalink)  
Old 02-22-10, 11:09 AM
dayworker dayworker is offline
Newbie Coder
 
Join Date: Feb 2010
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
quote file string

$data_file=" text.txt ";
open(DAT, "$data_file"); ###### CHANGED ###
@raw_data=<DAT>;
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 "<br>\n";
}
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form to Text File Justin171985 PHP 14 02-09-11 11:55 AM
Getting value in input file PHP Warner JavaScript 1 12-06-09 07:05 PM
Manipulating a .txt file with Perl thabo Perl 5 04-03-09 10:35 AM
[SOLVED] Perl scripting with Xchat raziel23x Perl 1 04-10-08 02:24 PM
Use PHP to download .html file from another site (Like LWP::Simple in Perl) ? kevin PHP 4 07-03-03 01:57 AM


All times are GMT -5. The time now is 04:55 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.