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

Re: Need help

by ELISHEVA (Prior)
on Oct 15, 2012 at 10:22 UTC ( #999057=note: print w/ replies, xml ) Need Help??


in reply to Need help

First, welcome to the monastery, qwerty80, and to Perl.

Second, using scripts to delete files automatically when you don't know scripting is dangerous business. If there is a bug in your script you could end up deleting a LOT more than you intended. Please be careful.

"Delete these file" scripts are not good choices for beginner scripts. If there is any way you can do this manually on the command line I strongly recommend it, even if it will take more time. If you are using a pattern like "abc*.xml", first run a command to list files ( "ls" for unix, "dir" for windows). If you are getting the files you want to delete and only the files you want to delete, then carefully retype the command replacing dir/ls with a command to delete files. If you really must do this via a script, first write your script so that does nothing except print out the list of files, e.g.

foreach my $file (glob "/tmp/somedir/file*.xml") { print "<$file>\n"; }

Only after you are really, really sure that you are looping through the files you want to delete and nothing more, only then, should you replace the print "<$file>\n" with code to delete files. If what I've just said sounds too difficult, then again, doing this via script is not safe at all and you should really do this deletion task manually.

Third, I realize you are feeling desperate, but PerlMonks is not a coding service. We monks do not get real happy about questions like "I need a script give me one", even when one is urgently needed.

We are here to help people learn how to code in Perl, not to solve their homework or work problems for them. Our payback is the realization that we've helped someone become a slightly better coder and a slightly better coder in Perl particularly. We don't get your salary or your degree, just the satisfaction of helping someone learn.

For us to get that satisfaction the person has to show us what they want to learn, not simply ask for a solution. I think you will get a much more friendly response from people if you show the code you tried to write and to ask for help rather than say "script please?!".


Comment on Re: Need help
Select or Download Code
Re^2: Need help
by McA (Curate) on Oct 15, 2012 at 11:04 UTC

    Hi ELISHEVA,

    I hope that with "... much more friendly response ..." doesn't mean that my answer was not friendly. I tried to help as fast as requested. And I'm sure that the above code does delete files which match the pattern. I think, I was also polite not using a path of e.g. /etc/sysconfig/*.conf in my example. But I asumed that qwerty80 would take the 15 seconds to look at the code trying to understand as it took me more than 15 seconds to write an answer.

    Best regards
    McA

    UPDATE: A ++ for ELISHEVA for being much more polite and friendly as it could be expected by the way it was asked.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2014-10-22 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (114 votes), past polls