I know how it's supposed to be done but when i tried it in a program i'm writing at the moment it isn't working quite how i expected.
The program is, in it's simplest form (which still doesn't work): ------------------------------------------------------ #!perl
for $file (<s2/*>) { push @ARGV, $file; }
Read through this document to find out how the null filehandle (<>) works
perldoc perlop #Search for 'null filehandle'
This will give you info on the -i switch ($^I is a mnemonic for the -i switch)
perldoc perlrun
$^I = "~"; for (<>)
Short answer: change the above line to while (<>) and things will work fine.
Long answer:
The -i switch or the value of $^I apply only when the <> construct is currently processing. The for (<>) is equivalent to slurping in the contents of all the files present in the @ARGV array (perldoc perlsyn). The for construct creates a flat list before actually executing the loop body. <> processing has already finished when the loop body is being executed.
Why is the original file empty?
When the <> construct is processing and the $^I has been set, the filehandle to the currently open file is selected (perldoc -f select, one argument form of select). All print statements without a filehandle argument will be directed at this filehandle (perldoc -f print). As a result of no print statements being made when <> was processing, the original file ends up being empty.
Why does the output appear on the standard output?
This is the result of modifying and printing the contents of the list created by the for construct. Note: The default selected filehandle is STDOUT.
The while loop on the other hand steps through the contents one line at a time (the default behaviour). This means that the loop body is being executed when the <> construct is still processing.
{
s/(<td .*?>)/<td>/g; print; } ------------------------------------------------------
The problem is that the print statement sends everything to the command console output, not the file i'm try to edit in-place. The original file name ends up being completely blank after running the script, but at least the backup is created.
I'm using perl 5.8, and WindowsXP.
Also, yes, that is a search for html tags but it's to do some massive batch conversion on a website i made a few years back so i know what i'm working with and that it will work all work correctly.
The script isn't really the full story... It's just what i'm doing in the most basic form, that still doesn't work ;)
So, can anyone work out what's wrong? Have i done something wrong in my script?
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]