use warnings; use strict; open OUT, '>', 'delme.txt'; print OUT <<TEXT; 1) how can someone know what is the current edited file's name ? quest +ion TEXT close OUT; @ARGV = ('delme.txt'); $^I = ".bak"; while (<>) { if ($. == 1) { print STDOUT "File geing processed is $ARGV\n"; open OUT, '>', $ARGV or die "Can't open $ARGV: $!"; print OUT <<" NEWTEXT"; 2) can someone make modifications on that file, isnt it al +ready opened by the <> diamond operator? NEWTEXT } print; print STDOUT; } close OUT; print "\n"; open IN, '<', 'delme.txt'; print <IN>; close IN;
Prints:
File geing processed is delme.txt 1) how can someone know what is the current edited file's name ? quest +ion 2) can someone make modifications on that file, isnt it al +ready opened by the <> diamond operator?
which shows that the file can be reopened. Notice though that the close must be after the magic file processing has happened in the while loop (close OUT; is after the while loop). If the close is in the same block as the open OUT the "update" gets replaced by the loop version of the update.
Not sure where that would be useful however!
In reply to Re: diamond operator current filename
by GrandFather
in thread diamond operator current filename
by spx2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |