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

Re^2: shift implicit dereference

by tobyink (Abbot)
on Oct 06, 2013 at 18:45 UTC ( #1057182=note: print w/replies, xml ) Need Help??


in reply to Re: shift implicit dereference
in thread shift implicit dereference

Another place a unary plus is often useful is to protect against the effects of the fat comma:

use constant MONIKER => 'name'; my %hash1 = ( +MONIKER => 'Monica' ); # compared with... my %hash2 = ( MONIKER => 'Monica' ); use Data::Dumper; print Dumper(\%hash1, \%hash2);
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Replies are listed 'Best First'.
Re^3: shift implicit dereference
by kcott (Chancellor) on Oct 06, 2013 at 19:17 UTC

    I get the same results as Sören. I'm using v5.18.1 (darwin-thread-multi-2level).

    (MONIKER() => 'Monica') produces 'name' => 'Monica' in the Dumper output.

    -- Ken

      or maybe putting in parens is more obvious?

      DB<117> use constant MONIKER =>"name" DB<118> %hash1 = ( (MONIKER) => 'Monica' ); => ("name", "Monica") DB<119> $hash1{ (MONIKER) } => "Monica" DB<142> [map { my $y = uc; ({$y => 1}) } "a".."c"] => [{ A => 1 }, { B => 1 }, { C => 1 }] DB<143> print ((1==0) ? "true" : "false") => 1 false DB<144> sub tst { ${ (shift) } } DB<145> tst \"a" => "a"

      Cheers Rolf

      ( addicted to the Perl Programming Language)

Re^3: shift implicit dereference
by Happy-the-monk (Abbot) on Oct 06, 2013 at 19:00 UTC

    That's looking very nice but...

    $VAR1 = { 'MONIKER' => 'Monica' }; $VAR2 = { 'MONIKER' => 'Monica' }; $ perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for i686-linu +x-gnu-thread-multi-64int ...

    Cheers, Sören

    Créateur des bugs mobiles - let loose once, run everywhere.
    (hooked on the Perl Programming language)

      Confirmed, same result with 5.10.1 on my shared hosting account.

      $ ./monktest.pl $VAR1 = { 'MONIKER' => 'Monica' }; $VAR2 = { 'MONIKER' => 'Monica' }; $ perl -v This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
      On time, cheap, compliant with final specs. Pick two.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1057182]
help
Chatterbox?
[stevieb]: it's a reminder to re-inforce it :P
[atcroft]: james28909: That particular questions was a bit of trick, actually (depending on the country you are in). More interesting is, if you are trying to subtract from an epoch time, for instance, you might have to consider when/if DST occurs for a location,
[atcroft]: because you may have to adjust the number of seconds you change from an epoch from 86400 (not to mention leap seconds)....
[atcroft]: james28909: Although if your program is using a database, you might be able to "pass the buck" to the database and ask it to do the date change for you....
[stevieb]: ++ atcroft

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2017-04-29 04:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.