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

Re: STUPID STUPID STUPID old me.

by grantm (Parson)
on Oct 28, 2002 at 09:17 UTC ( [id://208471]=note: print w/replies, xml ) Need Help??


in reply to STUPID STUPID STUPID old me.

the script is supposed to be run in a cron job to check the directory one step above itself

In fact, it checks the directory one step above the current directory of the cron process. If you need the script to start running in a specific directory, then put a 'chdir("/pathname")' at the beginning of the script.

Alternatively, just open the directory you want to open: opendir("/pathname")

Or, more simply, don't open it at all - use Perl's glob operator in your loop:

foreach my $file (</pathname/*>) { if( ($file ne "index.html") && ($file ne ".") && ($file ne "..") && ($file ne "cgi-bin") ) {$files = 1} }

Also, you might as well break out of the loop once you've set $files to 1 - it's never going to change on subsequent iterations. In fact, you don't really need a loop at all. Try this:

my @files = grep(!/^(\.\.?|index\.html|cgi-bin)$/, </pathname/*>); if(@files) { # send email }

Replies are listed 'Best First'.
Re: Re: STUPID STUPID STUPID old me.
by BrentDax (Hermit) on Oct 30, 2002 at 03:10 UTC
    forea­ch my $file (</pa­thnam­e/*>) {

    Yuck. Using glob is an excellent idea (I've never seen the utility in opendir()), but for the sake of sanity use the function form instead:

    foreach my $file (glob("/pathname/*")) {

    =cut
    --Brent Dax
    There is no sig.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-24 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found