in reply to Re^2: Cloning shared hashref
in thread Cloning shared hashref
Use this:
use threads; use threads::shared; use Data::Dumper; sub clone { my $ref = shift; my $type = ref $ref; if( $type eq 'HASH' ) { return { map clone( $_ ), %{ $ref } }; } elsif( $type eq 'ARRAY' ) { return [ map clone( $_ ),@{ $ref } ]; } elsif( $type eq 'REF' ) { return \ clone( $$ref ); } else { return $ref; } } my $x :shared = shared_clone({ a => 'Foo', b => 'Bar' }); my $z = clone( $x ); print Dumper( $z );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Cloning shared hashref
by menth0l (Monk) on Jan 21, 2011 at 08:12 UTC | |
by BrowserUk (Patriarch) on Jan 21, 2011 at 08:39 UTC | |
Re^4: Cloning shared hashref
by jwba (Novice) on Mar 16, 2011 at 21:43 UTC | |
by BrowserUk (Patriarch) on Mar 16, 2011 at 23:04 UTC | |
by jwba (Novice) on Mar 17, 2011 at 19:05 UTC |