[ale] perl bogosity

Chris Fowler cfowler at outpostsentinel.com
Tue May 24 18:33:16 EDT 2016


It could be anything in Perl's mind I guess. :) 

[ 1, 2 ] is basically the same as { '1' => '2' } from our view. Net::LDAP developers may have just decided to stick with array references so that they did not have to deal with hash vs array. You could just cast it to either. 

I thought that maybe using the array and casting to hash would preserve ordering, but the order is still random. 

my $hash = { 
'1' => 'One', 
'2' => 'Two' 
}; 

print "Hash:\n"; 
foreach my $ref (keys %{$hash}) { 
print "$ref\n"; 
} 

my $array = [ '1' => 'One', '2' => 'Two' ]; 

print "Array:\n"; 
foreach my $ref (@{$array}) { 
print "$ref\n"; 
} 

my %hasher = @{$array}; 

print "Array:\n"; 
foreach (keys %hasher) { 
print "$ref\n"; 
} 

> From: "Todor Fassl" <fassl.tod at gmail.com>
> To: "Chris Fowler" <cfowler at outpostsentinel.com>, "Atlanta Linux Enthusiasts"
> <ale at ale.org>
> Sent: Tuesday, May 24, 2016 5:21:05 PM
> Subject: Re: [ale] perl bogosity

> Are you sure about that?

> $ perl -e 'print ref({ "key" => "value" }) . "\n";'
> HASH
> $ perl -e 'print ref([ "key" => "value" ]) . "\n";'
> ARRAY

> Using the Data::Dumper module, it looks like [ 'key' => 'value' ]
> creates an anonymous reference to an array with 2 elements.

> On 05/24/2016 03:10 PM, Chris Fowler wrote:
> > [ 'key' => 'value' ] is an associative array like that.


> --
> Todd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20160524/cf0973ae/attachment.html>


More information about the Ale mailing list