Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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?

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2018-03-20 04:39 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (247 votes). Check out past polls.