Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^2: Perl Syntax

by kbfiles (Initiate)
on Oct 30, 2013 at 21:04 UTC ( #1060449=note: print w/replies, xml ) Need Help??

in reply to Re: Perl Syntax
in thread Perl Syntax

@Suicide - I'm not trying to find what the value is but what does it do? What does 0+ do to $new?

Replies are listed 'Best First'.
Re^3: Perl Syntax
by derby (Abbot) on Oct 30, 2013 at 21:20 UTC

    Uggh ... that is one bad code smell ... basically in that context you're getting the memory address of the reference value and using it as the key for the hash.


      Some call it code smell, others call it the basis for managing inside-out objects.

      Update: Example from Class::Std:

      sub import { my $caller = caller; no strict 'refs'; *{ $caller . '::ident' } = \&Scalar::Util::refaddr;


        Not an especially useful technique for managing inside-out objects. (Not without some care anyway.) Reference addresses can be recycled.

        use strict; use warnings; use Scalar::Util 'refaddr'; use Data::Dumper; for my $i (0..2) { my $hash = [$i]; printf "The hash has refaddr %08X, and contents are...\n", refaddr +($hash); print Data::Dumper->Dump([$hash], ['$hash']); }

        With carefully written CLONE and DESTROY methods, using the refaddr as a hash key can be made to work, but something like Hash::FieldHash saves a lot of work.

        use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2023-01-31 23:39 GMT
Find Nodes?
    Voting Booth?

    No recent polls found