Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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 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
Replies are listed 'Best First'.
Re: why "link", "rename", but no "unlink" in CORE::?
by Anonymous Monk on Feb 27, 2013 at 11:48 UTC

      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?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2015-11-28 16:36 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (743 votes), past polls