Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Remote Pipe

by Robert (Initiate)
on May 31, 2000 at 05:39 UTC ( [id://15551]=note: print w/replies, xml ) Need Help??


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.

Replies are listed 'Best First'.
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();

      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

        i see. i guess my die statements are executed so rarely that i never notice the difference. 8^)
      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: $!";
        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.
      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.
        I cannot reproduce that locally, but it still looks like a precendence problem to me.

        Try changing your open statements and stop mixing, ie, do this

        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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://15551]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found