Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: The strangest use of unlink I know of

by kyle (Abbot)
on Feb 28, 2008 at 16:19 UTC ( #670925=note: print w/ replies, xml ) Need Help??


in reply to The strangest use of unlink I know of

I thought it might be even more tricky still. Since %foo is empty, unlink gets an empty list. I thought that might mean that it would delete whatever is in $_ as if it got no argument, but that doesn't happen.

my $test_file = 'file_of_doom'; die 'file already exists' if -e $test_file; system( "touch $test_file" ); die 'file not created' if ! -e $test_file; $_ = $test_file; my %foo = (); unlink %foo; print "file gone!\n" if ! -e $test_file;

As it is, I think it just does nothing.


Comment on Re: The strangest use of unlink I know of
Select or Download Code
Re^2: The strangest use of unlink I know of
by Anonymous Monk on Feb 28, 2008 at 16:56 UTC
    Look more carefully. %foo is not empty. It was initialized with curly brackets -- almost ALWAYS a sign that the author made a mistake. Not a very humorous answer, but Wayne Jarvis is not paid to be funny.

    :|

    Still however -- the code indeed is a no op in terms of "useful" work. One needs to explicitly require %foo as a scalar:
    unlink scalar %foo;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-08-29 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (289 votes), past polls