Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: error on file open

by Anonymous Monk
on Nov 25, 2013 at 22:41 UTC ( [id://1064325]=note: print w/replies, xml ) Need Help??


in reply to error on file open

I am very new to Perl, and don't know how to debug this error

There are checklists for that , I use them all the time (don't be fooled by the titles), Basic debugging checklist , brian's Guide to Solving Any Perl Problem, CGI Help Guide , Troubleshooting Perl CGI scripts ... More generic advice :) On debugging, verify everything, talk to teddybear ... checklists and more , perltrap, perltrap, Common Perl Pitfalls / perltrap

"permission denied" is about as clear as it can get: Q: can I have this cookie? A: No.

its because readdir does NOT return the complete path and you forgot to chdir

readdir is very low level, if you use Path::Tiny it can even do the die-ing for you, ex

$ perl -e " use Path::Tiny qw/ path /; path(qw/./)->openrw_raw; " Error open (+<:raw) on '.': Permission denied at -e line 1.

Then you can write functions that take arguments like this

#!/usr/bin/perl -- use strict; use warnings; use POSIX(); use Path::Tiny qw/ path /; Main( @ARGV ); exit( 0 ); sub Main { my $date = POSIX::strftime('%Y-%m-%d', localtime); my $dirp = path( 'f:/lawprod/law/prd9/work/COMDATAFILE/IN/' ); my $diri = $dirp->iterator( { qw/ recurse 0 / }); while( my $file = $diri->() ){ if( $file =~ /^\Q$threenodes\E/ ){ FrobnicateInnoculate( $file->openrw_raw ); } } } sub FrobnicateInnoculate { my( $filehandle ) = @_; ... close $filehandle; }

cpan Path::Tiny

perlintro#Simple matching, quotemeta, eq for string comparison not == (because perlnumber), http://p3rl.orrg/POSIX#strftime

chromatics free book Modern Perl a loose description of how experienced and effective Perl 5 programmers work....You can learn this too.
Learn Perl in about 2 hours 30 minutes
Beginning Perl (free) Chapter 6: Files and Data

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-03-29 07:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found