Okay, I had to make the title grab you, and Brittany Seems to have that effect, so sue me!

SO I have a bad habit of deleting the wrong directory/file, I wanted to solve that in a perly way, so I made myself a little script to prevent this without letting myself know that I was messin up first. I haven't posted in a while, so I thought I'd give something up. Its not even good code, LOL.
Its not much, but it does the job, and if you have ever deleted the wrong directory/file, then you know how frustrating it can be. I thought this was appropriate for CUFP, so go easy if you disagree. I'm new to using system calls, so please tear it apart and tell me if it could have been done better.

#!/usr/bin/perl -w use strict; use vars qw($temp $read); $temp=$ARGV[0]; if($temp = $ARGV[0]){ &go } else { &err } ######## sub go { ######## print "\nDo you want to remove this file completely? Or Put it in a tem +p dir?\n"; print "(c for Completely t to Archive):"; chomp($read=<STDIN>); if($read =~ m/^[tT]/){ system("mv", "$temp","/var/tmp/deftemp") | +| warn "Error : $!" } else { &go2 } } ######### sub go2 { ######### if($read =~ m/^[cC]/){ system("rm","-R", "$temp") } else { &err } } ######### sub err { ######### print "Invalid Input!\n"; } exit 0;


P.S. I also realize this could be prevented with using the
rm -i
option, but I thought it would be fun to do it in Perl.

-- Yes, I am a criminal. My crime is that of defyance.

In reply to Oops I did it again..... by defyance

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.