Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Deleting old files from directory

by TomDLux (Vicar)
on Sep 27, 2011 at 19:39 UTC ( #928158=note: print w/replies, xml ) Need Help??

in reply to Deleting old files from directory

Does that even work? "perldoc -f -X" gives the example:

while (<>) { chomp; next unless -f $_; # ignore specials #... }

From which I gather the filetests don't take a default "$_". But once you've tested "-f $_", you can re-use the data structure from that query for the -M test by specifying a single underscore: "-M _". Personally I would do it as in the example, with a while, rather than loading all the filenames ... potentially a large number. I would also use a variable rather than "$_", because when you nest loops or call routines, the value of $_ might be altered.

As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Replies are listed 'Best First'.
Re^2: Deleting old files from directory
by jwkrahn (Monsignor) on Sep 27, 2011 at 20:13 UTC
    From which I gather the filetests don't take a default "$_".

    Well if you read "perldoc -f -X" you'll see it says:

        -X EXPR
        -X DIRHANDLE
        -X      A file test, where X is one of the letters listed below.  This unary
                operator takes one argument, either a filename, a filehandle, or a
                dirhandle, and tests the associated file to see if something is true
                about it.  If the argument is omitted, tests $_, except for "-t", which
                tests STDIN.  Unless otherwise documented, it returns 1 for true
                and '' for false, or the undefined value if the file doesn't exist.  Despite
                the funny names, precedence is the same as any other named unary operator.

Re^2: Deleting old files from directory
by Anonymous Monk on Sep 27, 2011 at 19:52 UTC
    Um, grep always works with $_, and OP already has named variable $delfiles

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928158]
LanX ... and git in general
[erix]: I've been to Amsterdam before you were born
[LanX]: 1899?
[chacham]: Just paint the white house black again.
dbander snorts
LanX Gesundheit! :)
talexb wonders about dividing developers in those born before the Unix timestamp of zero .. and after. Spoiler: I'm before.
chacham remebers I am a mad scientist
[stevieb]: talexb I'm after by a few years, but we can still be friends because you live in my hometown ;)

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2017-08-18 13:24 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (302 votes). Check out past polls.