Your skill will accomplish
what the force of many cannot
Can't write files (even redirected from shell)by Flame (Deacon)
|on Jan 14, 2008 at 04:09 UTC||Need Help??|
Flame has asked for the
wisdom of the Perl Monks concerning the following question:
Using Windows ActiveState Perl 5.8.8 build 822.
I'm extremely confused.
I just tossed together a simple script that would scan the Wizards Gatherer web page and spit out a card's ID and name, separated by a semicolon.
Now I'm a little out of practice, but I managed to get it to work first try, printing to STDOUT. I then said to myself "okay, why bother with the file operations, let the shell do it."perl GatherScan.pl > carddb.txt
I come back in a few minutes to find no data in carddb.txt. It's reporting a filesize of 0.
I reworked it using IO::File to do the file writes itself. Thus adding
to the front of my file and changing my print invocations to $file->print.
That done, I ran it again, without the redirect, and found, again, no data in the file. I tried changing the file name to no avail. I added prints to STDERR to verify the data was being retrieved/generated, and I got exactly what I wanted out of it, but no actual data in the file.
Finally, I tried redirecting STDERR to the file and swapping everything (by this time I'd given up on having perl write to the file directly.) Suddenly, the file has data!
Here's the program I ended up with, with the swap completed:
As you can see, it was meant to be a simple little script, doesn't even do proper HTML parsing (I know).
So, the question is, does anyone know why I couldn't get data from STDOUT to a file.. or into a file opened in perl?