Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Datastructure

Reply
Thread Tools

Datastructure

 
 
Bioperler
Guest
Posts: n/a
 
      11-15-2007
HI!

Actually I'm about to code a tool, that's able to track users of a
website (using cookies). However, I've got a problem with the sorting of
the data. I need a data structure like this:

%hash(array(array)) "hash of an array of an array"

So for testing purposes I generated a small dataset, which looks like this:


%HoAoA = (
hash1 => [
( [ "first", "second" ],
[ "third" , "fourth" ],
[ "fifth" , "sixth" ]
)
],
hash2 => [
( [ "9th", "10th" ],
[ "11th" , "12th" ]
)
]

);

So while it was no problem to acces all data fields using nested loops,
I was not able to append data to these arrays listed above. Array's push
doesn't seem to work for this.

Example of what I want to do:
push($HoAoA{hash1}[2], "seventh");


Any suggestions?
 
Reply With Quote
 
 
 
 
Peter Makholm
Guest
Posts: n/a
 
      11-15-2007
Bioperler <(E-Mail Removed)> writes:

> %HoAoA = (
> hash1 => [
> ( [ "first", "second" ],
> [ "third" , "fourth" ],
> [ "fifth" , "sixth" ]
> )
> ],


You don't need the inner ()'s

> hash2 => [
> ( [ "9th", "10th" ],
> [ "11th" , "12th" ]
> )
> ]
>
> );
>


> Example of what I want to do:
> push($HoAoA{hash1}[2], "seventh");


The first argument to push should be an actual array and not just an
reference. So you have to dereference it:

push @{ $HoAoA{hash1}[2] }, "seventh";

//Makholm
 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      11-15-2007
Bioperler wrote:
>
> Actually I'm about to code a tool, that's able to track users of a
> website (using cookies). However, I've got a problem with the sorting of
> the data. I need a data structure like this:
>
> %hash(array(array)) "hash of an array of an array"
>
> So for testing purposes I generated a small dataset, which looks like this:
>
> %HoAoA = (
> hash1 => [
> ( [ "first", "second" ],
> [ "third" , "fourth" ],
> [ "fifth" , "sixth" ]
> )
> ],
> hash2 => [
> ( [ "9th", "10th" ],
> [ "11th" , "12th" ]
> )
> ]
>
> );
>
> So while it was no problem to acces all data fields using nested loops,
> I was not able to append data to these arrays listed above. Array's push
> doesn't seem to work for this.
>
> Example of what I want to do:
> push($HoAoA{hash1}[2], "seventh");
>
> Any suggestions?


You have to dereference the array (push only modifies arrays):

push @{ $HoAoA{ hash1 }[ 2 ] }, 'seventh';



John
--
use Perl;
program
fulfillment
 
Reply With Quote
 
Bioperler
Guest
Posts: n/a
 
      11-15-2007
Peter Makholm wrote:
> Bioperler <(E-Mail Removed)> writes:
>
>> %HoAoA = (
>> hash1 => [
>> ( [ "first", "second" ],
>> [ "third" , "fourth" ],
>> [ "fifth" , "sixth" ]
>> )
>> ],

>
> You don't need the inner ()'s

Yes, you're right. But actually the structure is a bit more complex - I
just shorted it a little bit to ease it.

>
>> hash2 => [
>> ( [ "9th", "10th" ],
>> [ "11th" , "12th" ]
>> )
>> ]
>>
>> );
>>

>
>> Example of what I want to do:
>> push($HoAoA{hash1}[2], "seventh");

>
> The first argument to push should be an actual array and not just an
> reference. So you have to dereference it:
>
> push @{ $HoAoA{hash1}[2] }, "seventh";

Thanks! This works. Seems as I have to read a little bit about that
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      11-16-2007
Bioperler <(E-Mail Removed)> wrote:
> Peter Makholm wrote:



>> push @{ $HoAoA{hash1}[2] }, "seventh";

> Thanks! This works. Seems as I have to read a little bit about that



You can do that with:

perldoc perlreftut


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
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
What datastructure to use to store nodes/locations I've visited 6tc1@qlink.queensu.ca Java 3 06-23-2005 02:28 AM
Index-based datastructure Sharp Java 1 03-14-2005 11:56 AM
Set DataStructure Anony! Java 2 08-13-2004 02:32 AM
Datastructure and Algorithms Prateek Basu C Programming 4 01-24-2004 10:37 AM
Datastructure design Santosh C Programming 6 11-20-2003 07:26 AM



Advertisments