Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Error in script

by GotToBTru (Priest)
on Aug 15, 2011 at 16:21 UTC ( #920319=note: print w/ replies, xml ) Need Help??


in reply to Error in script

Use -s test:

#!/bin/perl # To remove all 0 byte file in a folder my $dir = "/home/bob/mytemp"; while (<$dir/*>) {unlink $_ unless (-s)}

Update: first line fixed. When testing I had #!/home/edi/perl but I know our installation is unusual, so I just copied the line from the OP to match his environment .. I thought it looked strange!

I leave the parentheses around conditions deliberately. It helps the less perl-literate of my co-workers.

My solution will only delete files in $dir; in the OP it mentions directory and below. find .. -exec rm is the tool to use in that case.


Comment on Re: Error in script
Select or Download Code
Replies are listed 'Best First'.
Re^2: Error in script
by raybies (Chaplain) on Aug 15, 2011 at 16:42 UTC

    Nice.

    Though fix your first line. #! makes us all happy. :)

    (And I don't bother with parens around the -s, but both work fine...)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2015-07-08 04:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls