in place - Using perl one-liner in perl script -
i embedded 1 perl one-liner in 1 perl script , purpose of in-place replace 1 string each line of files name extension .ini, found every file backed .bak.
since in one-liner, specify -i
rather -i.bak
, wonder why .bak file generated.
foreach $dir (glob "*.ini") { system qq(perl -i -pe 's|default|utf-8|' $dir); }
another question whether there better,concise perl script achieve same target (without .bak file backed up), regardless of one-liner or not.
i think may looking @ old data files. far know, perl won't assume default file extension of .bak
under circumstances
if specify option -i
attempt edit file in-place deleting input file after has been opened , creating new output file same name. old file remains readable until closed
this technique doesn't work on windows, , error use bare -i
option on platform
there no need shell out second perl process edit files. can done this. internal variable $^i
corresponds value of -i
option on command line. once again, if working on windows system $^i
may not empty string , need set .bak
or similar
{ local @argv = glob 'f.*'; local $^i = ''; # must non-blank on windows while ( <> ) { s/default/utf-8/g; print; } }
Comments
Post a Comment