Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

why "link", "rename", but no "unlink" in CORE::?

by perl-diddler (Hermit)
on Feb 26, 2013 at 16:58 UTC ( #1020729=perlquestion: print w/ replies, xml ) Need Help??
perl-diddler has asked for the wisdom of the Perl Monks concerning the following question:

I was putting an error message wrapper around some file operations like rename and link to get the error handling 'out of band' -- not have it inline w/the code so it obscured the flow of the code. Created a small wrapper:
sub fileop($;$) { my ($op, @argv)=@{my $_=shift}; use Carp qw(cluck); no strict 'refs'; &{"CORE::".$op}(@argv) || do { cluck (P "ERROR: $! doing %s(%s): (%s)%s", $op, (join ', ', @arg +v), $!, @_?" (extra info: ".$_[0].")":""); exit (0+$!) } } # can call this with: fileop(['rename', $from_name, $tmpnam]); fileop(['link', $name_of_to_node, $from_name]);

Went to do the same with "unlink":

sub sched_unlink($$) { fileop(['unlink', $_[0]], "from inode ".$_[1]) + }
But had this coming out from perl:
&CORE::unlink cannot be called directly at <file> line <#>

Note, I had earlier, tried making such calls without the "CORE::" in front of them, but got errors about no such local routines being defined...so thought 'CORE::' was the way to go for perl built-ins...

Why the exceptions?... and do I just have to special case all the ones that give errors as they come up?

I didn't get from my last read of the docs that "unlink" was somehow radically different from "link"... Ideas?

Comment on why "link", "rename", but no "unlink" in CORE::?
Select or Download Code
Re: why "link", "rename", but no "unlink" in CORE::?
by Anonymous Monk on Feb 27, 2013 at 11:48 UTC
      Indeed.

      That might be a cleaner way to do the same, though not sure if it will solve the problem of allowing a direct call or not until I try it (i.e. if I can't call unlink directly, it might not let me override it either? Dunno).

      Thanks for the tip.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (13)
As of 2014-12-22 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (119 votes), past polls