Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > strange hash syntax

Reply
Thread Tools

strange hash syntax

 
 
Torch
Guest
Posts: n/a
 
      11-14-2003
I encountered a hash syntax I have never seen before, can somebody
help me understanding it.

$somehash{$somekey} = [ @somearray];

When I do print"$somehash{$somekey}" I get some strange number
ARRAY(0x20038114)as an output.
What does this mean????
I can;t find anything in my book and I do not nkow how to start
looking for it on the net...
Thx for any help!

Torch
 
Reply With Quote
 
 
 
 
Andreas Kahari
Guest
Posts: n/a
 
      11-14-2003
In article <> , Torch wrote:
> I encountered a hash syntax I have never seen before, can somebody
> help me understanding it.
>
> $somehash{$somekey} = [ @somearray];



This stores an array reference at the given location of the
hash. The %somehash now contains an array reference at the key
$somekey. You can index it like this:

# Third element of the stored array:
my $e = $somehash{$somekey}[2];

Or loop over it:

foreach my $e (@{ $somehash{$somekey} }) {
# Make use of array element $e here
}


Read the perldata manual.


--
Andreas Kähäri
 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      11-14-2003
(Torch) writes:

> $somehash{$somekey} = [ @somearray];


> What does this mean????
> I can;t find anything in my book


Others have addressed your immediate problem but if your book doesn't
explain [...] it sounds like it is probably a Perl4 book. There's a
lot of stuff in Perl5 that's not in Perl4 and there's a lot of stuff
that you had to do in Perl4 to work around its shortcommings that's
now considered very poor style in Perl5.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
Reply With Quote
 
Dave Oswald
Guest
Posts: n/a
 
      11-15-2003

"Torch" <> wrote

> I encountered a hash syntax I have never seen before, can somebody
> help me understanding it.
>
> $somehash{$somekey} = [ @somearray];
>
> When I do print"$somehash{$somekey}" I get some strange number
> ARRAY(0x20038114)as an output.
> What does this mean????
> I can;t find anything in my book and I do not nkow how to start
> looking for it on the net...


You're looking at the creation of an anonymous array, whos referent will be
a hash element.

If your book doesn't discuss references and anonymous arrays, you'd better
get a different book, or read 'perlref' from the Perl POD.


 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      11-23-2003
Darek N <> wrote:

>> # Third element of the stored array:
>> my $e = $somehash{$somekey}[2]; ## need to derefernce !!

>
> This is not quite right



Yes it is.


> because of the dereferencing action:
> my $e = $somehash{$somekey}->[2];



perldoc perlref

One more thing here. The arrow is optional _between_
brackets subscripts...


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
[ANN] SqlStatement 1.0.0 - hide the syntax of SQL behind familiarruby syntax Ken Bloom Ruby 3 10-09-2006 06:46 PM
Syntax highligth with textile: Syntax+RedCloth ? gabriele renzi Ruby 2 12-31-2005 02:44 AM
Question About Strange 'C' Code Syntax ( Well strange to me anyway ) Harvey Twyman C Programming 8 10-25-2003 05:54 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57