Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: recursive reference delete subroutine

by chromatic (Archbishop)
on Dec 16, 2004 at 02:43 UTC ( #415270=note: print w/replies, xml ) Need Help??


in reply to Re: recursive reference delete subroutine
in thread recursive reference delete subroutine

I disagree; I think that answer merely hopes for a solution instead of answering the question directly.

use Test::More tests => 2; sub undef_hash { my $ref = shift; undef $ref; } sub assign_hash { my $ref = shift; %$ref = (); } my $hash_one = { qw( foo bar baz quux ) }; undef_hash( $hash_one ); is( keys %$hash_one, 2, 'undef on hash reference should not clear it' ); my $hash_two = { qw( foo bar baz quux ) }; assign_hash( $hash_two ); is( keys %$hash_two, 0, 'assigning empty list to hash reference should clear it' );

Update: Ahh, I misunderstood. Yes, replacing the subcall will probably work.

Replies are listed 'Best First'.
Re^3: recursive reference delete subroutine
by Zed_Lopez (Chaplain) on Dec 16, 2004 at 05:30 UTC

    I was presuming the OP would replace the calls to deleteref with just the undef. You're right, of course, that making a copy of the reference in a subroutine and undeffing that is a no-op.

    use Test::More tests => 2; sub deleteref { my $h = shift; undef $h; } my $c = {d => 3}; deleteref($c); is( keys %$c, 1, 'undef on copy of hashref in a subroutine should not clear it' ); undef $c; is( keys %$c, 0, 'undef on hash reference, not a copy of it in a subroutine, should + clear it' );

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2023-12-04 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (21 votes). Check out past polls.

    Notices?