I have a perl script which is just reading from the file but what I would like to understand is how the counter is moving without using the loop in the script.
Below are the details:
Script to read the above file is as :
when I am executing the above script, it is throwing the output as :
How counter in the file is moving to next row when I am not moving it and I am also not using any loops anywhere? I would just like to understand that? Does that mean loops are not required for moving through the file or I am getting it wrong somewhere?
Thanks in advance for any help on this!
Moderator's Comments:
Use code tags please, see PM.
Last edited by zaxxon; 07-12-2013 at 07:51 AM..
Reason: code tags and indention
Everytime you do read from a filehandle and store it in a scalar variable, then one line of input is read. (By one line, I mean the data until the next record separator).
Here is how it works internally:
When you open a filehandle, lets say, there's a mark that is at the beginning of file. The first time $rec = scalar <$INF> is encountered, the first line from file is read and referred by $rec. Now, the mark that we spoke of earlier, is at the character just after newline character (assuming newline as the default record separator). Now again when $rec = scalar <$INF> is encountered, one more line of data is read.
In the example code you provided in your post, a wrapper routine "readfile" reads one line of data and prints it.
The usual way of reading a file is to use a loop. Then again, that depends on what you really want to do:
Hi,
I am reading and file and writting each word to other file.
where I have used array to store the data.
I am getting below error as
"Use of uninitialized value in concatenation (.) or string at customize_split_raw.pl line 51, <IN_FILE> "
Where my line 51 code is
50 foreach... (8 Replies)
I have a PERL command line embedded in a UNIX script. The script doesn't handle errors coming out of this command. I'm processing large files and occassionally I run out of disk space and end up with half a file.
perl -p -e 's/\n/\r\n/g' < TR_TMP_$4 > $4
How do I handle errors coming out... (1 Reply)
$# some text
$$ some text
$@ some text
$$. some text
Mg1 some text
Mg2 some text
.
.
.
Mg10 some text
The above 10 lines are to be extracted except the lines starting from $#,$$.,... (4 Replies)
Hi All,
I'm pretty new to the forum and also to UNIX. I have a requirement for which I need some help. I have a script (example.script) where I get user inputs using the read command. I would need to pass the read-fetched input to a perl command (explained below) in my script. The part which... (3 Replies)
Hi ,
Is there any way to achieve following using perl program (i.e without using system command).
1.system ("echo 'test' > /usr/spool/ship.csv");
2.system ("cat /usr/ajay_test* >> /usr/spool/RAM/work/patil.csv");
3.system("> /usr/spool/ajay.txt");
e.g
for system("rm -f... (1 Reply)
Hi All,
I am comparing two strings inside an if condition if the strings are same then it should go inside the loop else it should execute code given in else part.
But there is a but inside my script
Even if the if condition is true
it is not going inside the loop also it is executing... (4 Replies)
Hi there,
I'm newby in perl and XML. I can read and parse Xml with XML-Node upper XML::Parser, but how can I create XML tags and pack my individual data in it then send through socket. PLZ lead me :)
Thanks in Advance. (1 Reply)
Hi Experts,
I have a big text file, so I want read it at eof to upper bound !. after I use a fseek to go SEEK_END, is it possible to step up upperbound?
Best Regards.
Note that I'm used perl script. (2 Replies)
here is simple perl script i wanted for my net connection ... just to check if default gateway is pingable or not if not write in log file but problem is that i can not write in file i can print on STDOUT but not in file ...why so ??
same thing was there when i was tying to write on sockets... (7 Replies)
Hi,
I am opening a file......then i am wrting some data into it......and i am reopening the file again but ......i get a error cannot open file.......
$::file= "\adder\testfile.txt"
open(TEST1,$::file);
some write operation
close(TEST1)
open(TEST1,$::file) 'I GET A ERROR CAN OPEN... (2 Replies)