sumeetp45 has asked for the wisdom of the Perl Monks concerning the following question:

Pasted below is the snippet of the code that works fine on UNIX machines. But in case of windows, it fails at 'while (<>)' with error 'Can't do inplace edit on <filename>' Any help on why this fails on windows? I have searched and could not find any info. When I tried the traditional way of creating file handles for input and output files and then writing to outfile it works fine. But I was hoping to make use of the below in-place edit. local @ARGV = ($filename); local $^I = '.bk'; while (<>) { if ($. == 1) { print "<vom>\n"; } else { print; } }

Replies are listed 'Best First'.
Re: In place edit does not work on Windows
by rovf (Priest) on Mar 22, 2012 at 09:02 UTC
    What actually *is* the filename where it bails out? Maybe it's one those names which have special meaning on Windows (NUL, PRN,...), which you can happily create on Unix, but can't handle from Windows?

    Does it work if you specify explicitly an extension for the backup file?

    -- 
    Ronald Fischer <ynnor@mm.st>
Re: In place edit does not work on Windows
by Anonymous Monk on Mar 22, 2012 at 09:06 UTC
Re: In place edit does not work on Windows
by sumeetp45 (Initiate) on Mar 22, 2012 at 09:31 UTC

    The filename is proper. Please check below

    I wrote this small perl code and this works fine. But when part of main module, this does not work.

    my $files = "D:\\Documents and Settings\\All Users\\Application Data\\ +cmd-op928.output"; { local ($^I, @ARGV) = ('.bak', $files); while (<>) { if ($. == 1) { print "<test>\n"; } else { print; } } }

      But when part of main module, this does not work.

      Maybe you should show that instead

        Here below is the actual snippet from the main module. This does not work.
        { # Need to add tags of <vom> and <\vom> at the # start and end of the file # Doing this below, but in a different block # of code to not disturb ARGV $out->[1] =~ s/\\/\\\\/g; # for windows local @ARGV = ($out->[1]); local $^I = '.bk'; while (<>) { if ($. == 1) { print "<vom>\n"; } else { print; } } open(APP, ">>$out->[1]"); print APP "\n</vom>\n"; close(APP); }