[Pdx-pm] implicit hashref return gone awry

Randall Hansen randall at sonofhans.net
Mon Dec 5 16:49:08 PST 2005


this isn't working the way i expect, which means i have an  
opportunity for education :)

     sub four {
         {
             %{ one() },
             label    => 'Bar',
         };
     }

i expected it to return a hashref, but it returns a list.  this  
appears to be related to the de-referencing of &one, since other  
similar situations do return a hashref.  full code below illustrates  
what i mean.

tia,

r


#!/usr/bin/perl
use strict;
use warnings;

use Data::Dumper;

sub one {
     {
         label    => 'Foo',
         data    => [ qw/ baz /],
     };
}

sub two {
     return {
         %{ one() },
         label    => 'Bar',
     };
}

sub three {
     {
         data    => 'test',
         label   => 'Bar',
     };
}

sub four {
     {
         %{ one() },
         label    => 'Bar',
     };
}


print Dumper[ 'ONE',    ref one(),      one() ];
print Dumper[ 'TWO',    ref two(),      two() ];
print Dumper[ 'THREE',  ref three(),    three() ];
print Dumper[ 'FOUR',   ref four(),     four() ];

__DATA__

output:
$VAR1 = [
           'ONE',
           'HASH',
           {
             'data' => [
                         'baz'
                       ],
             'label' => 'Foo'
           }
         ];
$VAR1 = [
           'TWO',
           'HASH',
           {
             'label' => 'Bar',
             'data' => [
                         'baz'
                       ]
           }
         ];
$VAR1 = [
           'THREE',
           'HASH',
           {
             'label' => 'Bar',
             'data' => 'test'
           }
         ];
$VAR1 = [
           'FOUR',
           '',
           'data',
           [
             'baz'
           ],
           'label',
           'Foo',
           'label',
           'Bar'
         ];



More information about the Pdx-pm-list mailing list