![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reading each line of a file in perl script | Harikrishna | Shell Programming and Scripting | 3 | 05-29-2008 09:28 AM |
| reading text file line by line | MizzGail | Shell Programming and Scripting | 6 | 04-14-2008 07:58 AM |
| Line by line file reading... and more! | ProFiction | Shell Programming and Scripting | 6 | 07-26-2007 12:32 PM |
| Perl Reading from File | karyn1617 | Shell Programming and Scripting | 1 | 02-17-2005 08:44 PM |
| Reading line by line from file. | akpopa | UNIX for Dummies Questions & Answers | 4 | 08-30-2001 11:20 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
perl - file reading - last line not displayed
Hi, Here is something that am trying with perl Code:
#! /opt/third-party/bin/perl
open(fh, "s") || die "unable to open the file <small>";
@ch = ();
$i = 0;
while( $content = <fh> )
{
if( $i <= 5 ) {
push(@ch, $content);
$i++;
}
else {
$i = 1;
foreach(@ch) {
print "The file content is $_";
}
@ch = ();
}
}
foreach(@ch) {
print "The file content is $_";
}
exit 0
The last line is not displayed in any case, could you please provide some pointers for that? Thanks
|
|
||||
|
Thanks! Here is what you have asked for Code:
>cat s abcd adding more and then wow is that working abcd last line Code:
>>perl script.pl The file content is abcd The file content is adding The file content is more The file content is and then The file content is wow is that working The file content is abcd You could apparently see that the last line from the file 's' is missing |
|
||||
|
Quote:
I dont think this is the right way to do by altering the index counter value as the value suggested will not work for files of different sizes and different lines |
|
||||
|
Do you mean this? Code:
while( $content = <fh> )
{
if( $i <= 5 ) {
push(@ch, $content);
$i++;
}
else {
$i = 1;
foreach(@ch) {
print "The file content is $_";
}
@ch = ($content);
}
}
What would you like to do actually with your program, as I don't really understand? It seems like you may wish to buffer 5 or 6 lines of a file before output, but why do that? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|