LA.pm: Prepend

Arkadiy Sudarikov asudarikov at xceed.com
Fri Oct 5 14:08:39 CDT 2001


Because I am expecting half a million records... Data comes from database
for Hilton Hotels reservations, like... week's amount of reservations...
worldwide.

-----Original Message-----
From: Andrew Baio [mailto:andy at waxy.org]
Sent: Friday, October 05, 2001 12:03 PM
To: asudarikov at xceed.com; list at la.pm.org
Subject: Re: LA.pm: Prepend


At 01:50 PM 10/05/2001 -0500, you wrote:
>my $sth->prep...
>$sth->execute($foo, $bar$, $baz);
>
>my $records=0;
>while (my $hashref=$sth->fetchrow_hashref) {
>  ++$records;
>  print FILE $hashref->{'Data'}, "\n" }
>
>print FILE $records, "\n";

         There's no way, that I know of, to prepend a
         line to a filehandle without opening and
         reading the file.

         This a FAQ, actually (question 2):

http://www.perldoc.com/perl5.6/pod/perlfaq5.html


         Why not just wait to write the output?

>my ($records, $out);
>while (my $hashref = $sth->fetchrow_hashref) {
>    $records++;
>    $out .= $hashref->{'Data'} . "\n";
>}
>
>print FILE $records . "\n";
>print FILE $out;


                                         -- Andy.




More information about the Losangeles-pm mailing list