Grygonos has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monks, I have the following code
This code worked fine when I first wrote it. It takes the results of a query and pumps them out to a pipe delimited file. Strangely after I made modifications to other parts of the program... it simply prints the size of the @row array in the results file. The portion of the code in question is where I set the delimiter and print to the filehandle in array context.. Does anyone have an idea of why this stopped working the way I intended?#Open the results file open(OUTPUT,">Q:\\Results\\".$date_time."\\".$1."_results.txt" +) || do{warn "Could not open ".$item."::".$!; writeLogEntry($item." f +ailed to open!");}; $rows = 0; #Write the results while(my @row = $sth->fetchrow_array) { $rows++; #Set output delimiter to the | $,="|"; #Remove trailing spaces map{s/\s*$//g} @row; print OUTPUT @row ."\n"; } #Output the number of rows affected writeLogEntry("Wrote ".$rows." results to ".$1."_results.txt." +); #close the file close OUTPUT;
PS The data is getting into @row correctly.. I changed it to write in scalar context and it worked.. but this still bothers me that it changed somehow
Thanks,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File I/O w/ arrays -- changing behavior
by Anonymous Monk on Dec 05, 2003 at 15:00 UTC | |
by Grygonos (Chaplain) on Dec 05, 2003 at 15:28 UTC |