or on the web: unlink
Update: I cleaned up and fixed the OP's code:
sub Check_request_file {
my ($file_to_check) = @_;
local *_; # Protect caller's $_.
open(local *FILE, '<', $file_to_check)
or die("Unable to open SPROC file $file_to_check: $!\n");
while (<FILE>) {
if (/SPROC\sName\:(?!\s[rR]eception)/) {
close(FILE); # So we can delete it
unlink($file_to_check)
or die("Unable to delete SPROC file $file_to_check: $!\n");
return; # Optional, since <FILE> will
# return false for a closed file.
}
}
}
- You had two names ($flat_to_check and $file_to_check) for the same var.
- I switched rename to unlink.
- I changed exit to return.
- I fixed the regexp ([r|R] vs [rR]). See perlre.
- I closed the file before attempting to delete it. (Not necessary on all OSs, but required on some.)
- I used the safer 3 argument open.
- I limited the scope of FILE.
- I added error checking to the open.
- I improved the error message for deletion errors.
- I simplified the condition.
- I removed some useless quotes ("$file_to_check" vs $file_to_check).
- I removed the useless empty else clause.
- Update: I protected the caller's $_. while (my $line = <FILE>) would also have worked, if the regexp is matched against $line.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.