470,594 Members | 1,444 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

A question about EOF

Hi All;

I'm fairly new to PERL. The problem I am running into is that I
need to chop the last line of the output file and place the count
record on that line. As it stands, there is a blank space and this
creates a problem. What can I do to test for an EOF condition, then
chop the last line? Thanks.
open(OUTFILE,'>' .$outfile) || die "cannot create $outfile: $!\n";

%priminput = ();
foreach $line (@firstlist) {
$priminput{$line} = 1;
print OUTFILE "$line \n";
# if (eof) {
# chop $line;
# }
}
{
for ($lineread=0; $lineread<=@firstlist;$lineread++) {
}
$x = $lineread / $linecount;
$x = sprintf ( "%.0f", $x );
print OUTFILE "CR $x\n";
}
close(OUTFILE);
print "finished!\n";
1;
__END__
Jul 19 '05 #1
1 5597
In article <b2**************************@posting.google.com >,
SL_McManus <sl*********@netzero.net> wrote:
Hi All;

I'm fairly new to PERL. The problem I am running into is that I
need to chop the last line of the output file and place the count
record on that line. As it stands, there is a blank space and this
creates a problem. What can I do to test for an EOF condition, then
chop the last line? Thanks.
What EOF are you looking for? The output file? Or some input file, that
you haven't shown? The program below does not run because $outfile has
not been defined and $linecount is zero.

If you are wanting to know what is the last element of @array, use the
$#array variable, which is the subscript of the last element. You can
do a loop like the following:

for my $i ( 0 .. $#firstlist ) {
if( $i == $#firstlist ) {
print OUTFILE $firstlist[$i] . scalar(@firstlist) . "\n";
}else{
print OUTFILE $firstlist[$i] . "\n";
}
}


open(OUTFILE,'>' .$outfile) || die "cannot create $outfile: $!\n";

%priminput = ();
foreach $line (@firstlist) {
$priminput{$line} = 1;
print OUTFILE "$line \n";
# if (eof) {
# chop $line;
# }
}
{
for ($lineread=0; $lineread<=@firstlist;$lineread++) {
}
$x = $lineread / $linecount;
$x = sprintf ( "%.0f", $x );
print OUTFILE "CR $x\n";
}
close(OUTFILE);
print "finished!\n";
1;
__END__


You will get better answers if you post complete, working programs that
are as short as possible.

Also, this group is defunct and shouldn't be used. Try
comp.lang.perl.misc in the future for better responses.
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by eScrewDotCom | last post: by
220 posts views Thread by Brandon J. Van Every | last post: by
8 posts views Thread by eScrewDotCom | last post: by
5 posts views Thread by eScrewDotCom | last post: by
reply views Thread by eScrewDotCom | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.