in reply to Remote Pipe
Ok Folks, now it looks like real code...
$file = 'Win.ini';
$tmp = "$file.tmp";
chdir ("\\\\servername\\winnt") || die "$!\n";
open (FL, "$file") || die "$!\n";
open (TMP,">$tmp") || die "$!\n";
while (<FL>){
$_ =~ s/als/ald/g;
print TMP $_;
}
close FL || die "$!\n";
close TMP || die "$!\n";
rename ($file,"$file\.old") || die "$!\n";
rename ("$file\.tmp",$file) || die "$!\n";
I'm getting the error when I try to create the TMP
filehandle.
RE: Re: Remote Pipe
by mdillon (Priest) on May 31, 2000 at 05:57 UTC
|
[ if you are using the latest version of Perl (5.6) ]
try opening TMP like this:
open(TMP, '>', $tmp) || die "Couldn't open $tmp: $!";
note, die adds a line break on its own so it is
not necessary to put one in your message.
p.s. a pox upon the houses of those who would unduly
censure me with their '--' votes. was it because my sub-par
code didn't work in your version of Perl? or because i do
not fully grasp the intricacies of 'die'?
die $haters if $haters->dont_know_jack(); | [reply] [d/l] [select] |
|
Umm ,actually not really. See, die is pretty funky and looks
at the end of the message. If there is no newline, it adds
the new line along with a whole bunch of other stuff ( like
the line number, etc ).
Sometimes, though, that information is not desired. Especially
when it may confuse the poor end user. So, if you do add the
newline, the only thing that shows up is the message you sent.
Mik - probably going on far longer than anybody really needs
mikfire
| [reply] |
|
i see. i guess my die statements are executed so rarely that
i never notice the difference. 8^)
| [reply] |
|
Probably just a typo on your part, but I think this is what threw
the OP when he tried your code. The second comma: you
probably meant that to be a concatenation operator, yes?
You want
open TMP, ">" . $tmp or die "Couldn't open $tmp: $!";
| [reply] [d/l] |
|
actually, i got confused by the fact that i have Perl 5.6.0
installed and it has a new variant of open with the following
signature:
open HANDLE, MODE, LIST
sorry that i didn't notice it was Perl 5.6 only, but i don't
use files too often. i figured the other signature was there
to avoid cross platform problems easier.
| [reply] [d/l] |
|
This is what I've got:
Too many arguments for open at test1.pl line 5, near "$tmp) "
Execution of test1.pl aborted due to compilation errors.
| [reply] |
|
open( TMP, ">$tmp" ) || die( "A grim and horrible death" );
or do it like this
open TMP, ">$tmp" or die "A grim and horrible death";
I believe the second method is considered more Perlish.
Mik
mikfire | [reply] [d/l] [select] |
|
|