Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > A question about EOF

Reply
Thread Tools

A question about EOF

 
 
SL_McManus
Guest
Posts: n/a
 
      12-03-2003
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__
 
Reply With Quote
 
 
 
 
Jim Gibson
Guest
Posts: n/a
 
      12-04-2003
In article < >,
SL_McManus <> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse Java 67 03-14-2012 12:21 AM
ifstream eof not reporting eof? SpreadTooThin C++ 10 06-15-2007 08:49 AM
if EOF = -1, can't a valid character == EOF and cause problems? Kobu C Programming 10 03-04-2005 10:40 PM
newbie EOF question shan C Programming 36 11-27-2003 01:34 PM
Newbie Question: EOF in MS Visual Studio 2003? entropy123 C Programming 6 07-03-2003 06:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57