Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: appending to a file

by Fletch (Bishop)
on Mar 19, 2009 at 16:38 UTC ( [id://751782]=note: print w/replies, xml ) Need Help??


in reply to appending to a file

Not checking the return value from things like chdir, opendir, or open certainly could be considered stupid.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: appending to a file
by dwm042 (Priest) on Mar 19, 2009 at 20:16 UTC
    fletch++

    To give a more direct example of what Fletch is talking about, do you know what happens in this piece of code if the change directory does not exist?

    my $dir = "/my/working/directory"; chdir ( $dir ); system ("rm -rf *");
      This removes everything in the dir.
Re^2: appending to a file
by lomSpace (Scribe) on Mar 19, 2009 at 16:56 UTC

    I checked the return values of chdir with Dumper. $in gives me
    a glob memory address. I know that I am in the correct dir
    because my regex matches the file names.

      It will always give you a glob memory address
      #!/usr/bin/perl -- use Data::Dumper; use strict; use warnings; opendir my $dh, "doesnotexist.mustnotexist"; print Dumper( $dh); __END__ $VAR1 = \*{'::$dh'}; D:\dev\misc> D:\dev\misc>perl #!/usr/bin/perl -- use Data::Dumper; use strict; use warnings; for my $dir( "doesnotexist.mustnotexist", "."){ opendir my $dh, $dir; Parentheses missing around "my" list at - line 7. print "dir $dir ", Dumper( $dh); } __END__ dir doesnotexist.mustnotexist $VAR1 = \*{'::$dh'}; dir . $VAR1 = \*{'::$dh'};
      system calls can fail for any reason

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2024-03-28 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found