HELP: putting an @array into an %array??? 
Author Message
 HELP: putting an @array into an %array???

Hello,

i am writing a perl script for my benchmarking, creating the system call that
will be issued, using the perl timing facility to mesure elapsed tim ad making
averages....

now there's where my problem occurs, each type of problem is computed with
different timings, producing a variable sized array, this array was then
supposed to be stored in another one.....

i tryed the following code:
my %finalResults;
for(my $i=$startSize; $i < $stopSize; $i+= $sizeStep)
{
  ...

  for(my $n=$startTime; $n < $stopTime; $n+= $timeStep)
  {
    ....
    for(my $z=0; $z<$averageSteps; $z++)
    {
        ...
    }#for(my $z=0; $z<$averageSteps; $z++)

  }#for(my $n=$startTime; $i < $maxTimeIters; $i+= $sizeTime))

Quote:
}#for($i=0; $i < $m; $i++)

open(FILE,">".$simulator.$name.$type."log") || die("couldnt open result file");
foreach $line (keys(%finalresult))
{
  print FILE $line." ";


  print FILE "\n";
Quote:
}# foreach $line (keys(%finalresult))

close FILE;

but this doesn't work..... what's stored is the number of elements of the
subarray, and not the array....
So somewhere i am mangling again the different ways of sight.... what would be
the correct way?

--
ciao bboett
==============================================================

http://www.*-*-*.com/ ~bboett http://www.*-*-*.com/ ~bboett
===============================================================
the total amount of intelligence on earth is constant.
human population is growing....



Wed, 18 Jun 1902 08:00:00 GMT  
 HELP: putting an @array into an %array???

Quote:

> i am writing a perl script for my benchmarking, creating the system
call that
> will be issued, using the perl timing facility to mesure elapsed tim
ad making
> averages....

use the module provided for this purpose.
use Benchmark;

read perldoc  Benchmark
--

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 HELP: putting an @array into an %array???

Quote:
>i tryed the following code:

[ snip code ]

   That code is better than nothing for soliciting help, but not
   as good as it could have been.

   It could have been code that actually runs.

   It could have been code that illustrates your problem without
   a bunch of domain-specific stuff that we don't really need
   to figure out.

   You could have given us just:

------------------------
#!/usr/bin/perl -w
use strict;

my %finalResults;

while (<DATA>) {


Quote:
}

foreach (sort keys %finalResults ) {
   print "$_: $finalResults{$_}\n";

Quote:
}

__DATA__
a b c d e
f g h i j
k l m
n o p q r s t u
------------------------

   And explained your problem:

I expected this output:

1: a b c d e
2: f g h i j
3: k l m
4: n o p q r s t u

instead I got this output:

1: 5
2: 5
3: 3
4: 8

   The easier you make it to help you, the better your chances of
   getting help...

Quote:
>but this doesn't work..... what's stored is the number of elements of the
>subarray, and not the array....

   Because that is what you told perl to do.

   If you want something else, then you need to tell it something else :-)

Quote:
>So somewhere i am mangling again the different ways of sight.... what would be
>the correct way?

   Use a "hash of lists" (HoL) data structure.

   It is called that even though it is NOT a hash of lists!

   It is a hash of array references.

   Sometimes you can think of it as a hash of lists, but sometimes
   you can't (or shouldn't anyway).

   You can check out the perlref.pod and perldsc.pod (Data Structures
   Cookbook) man pages to find out about how to make nested data
   structures in perl.

------------------------
#!/usr/bin/perl -w
use strict;

my %finalResults;   #  HoL

while (<DATA>) {


Quote:
}

foreach (sort keys %finalResults ) {

   #          ^^                 ^      de-reference it

Quote:
}

__DATA__
a b c d e
f g h i j
k l m
n o p q r s t u
------------------------

--
    Tad McClellan                          SGML Consulting

    Fort Worth, Texas



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. putting arrays in arrays!?!?

2. Putting/accessing an object from an array - help!

3. help putting each page of report in to its own array

4. Help Putting data from an file that Perl reads into a JavaScript array

5. Need Help with putting Hashes in a two-dimensional array

6. URGENT: Hash in Hash, Array in Array, Array in Hash, Hash in Array

7. Help with Embedding and Arrays of Arrays?

8. Help with Embedding and Arrays of Arrays?

9. Variable length array of arrays into tree structure - help

10. help with arrays of arrays

11. Help with Arrays of Arrays

12. help w split and array of array plse

 

 
Powered by phpBB® Forum Software