Re: Printing and Formatting data from hash (or array)



Mike wrote:
Mike wrote:

[...]
I've been tinkering with printing the
values from hashes, but it seems like there is a lot of duplicated
data, for instance, I found the example of this to print all the values
I have in a hash, but it seems like it is a single array within the
hash repeating (not printing multiple items in hash):

Correct. A hash has unique keys.

However, when I copy all the hash data to an array, and print the
array, it doesn't show all the duplicated data.
Post a short example of how you're doing that.

Possibly, you want to have a hash of arrays?

push( @{ $report{ $key } }, 'some value' );
push( @{ $report{ $key } }, 'another value' );

For many examples of data structures, see: perldoc perldsc

Ok, I think I've figured it out, this is what I'm doing (two tabs,
instead of one, yes, I know), is their a cleaner way to do this?:

my $n = 0;
while ($temphash[$n]) {

Is this an array or a hash?? Review the differences and name your variables accordingly.

print $temphash[$n];
$n++;
print "\t\t";
print $temphash[$n];
print "\n";
$n++;
}

If that actually prints the values you want. You may put the print on one line:

print "$tmphash[$n++]\t\t$temphash[$n++]\n";
.



Relevant Pages

  • Duck Typed Concepts for Ruby (was Re: A use case for an ordered hash)
    ... An Sequencable mixin can be defined that implements all sorts of operations such as append, concat, splice, sort, etc. ... extending an instance of Array with Sorted if the array is known to be sorted. ... Now returning to the thread at hand we can see that the difference between the associative array and hash hierarchies is that the hash hierarchy depends upon Hashable keys. ...
    (comp.lang.ruby)
  • Re: Suggestions for double-hashing scheme
    ... >> The items that are being moved are the items in the hash table itself, ... >> which are of fixed size (they are in an array, ... > typedef struct { ... One "uchar" aka 'unsigned char' is plenty to hold a probe ...
    (comp.programming)
  • [SUMMARY] Index and Query (#54)
    ... This was a fun quiz for me because I really don't know anything about indexing ... We see in initializethat the index is just a Hash. ... an Array of symbolic document names where the word can be found ). ...
    (comp.lang.ruby)
  • Re: Comment on how to uniquely track your objects in C# / hash table / get hash code
    ... Array, correct? ... This is largely irrelevant to the issue of performance, since hash ... where both insertions and lookups happen frequently, ... about fast lookups for balanced red/black binary trees. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: problem with hash & sort array
    ... Then I put the hash into an array with the sort ... The twist is I have to identify the duplicate ... a real data structure, and in the next place I make the exact opposite ...
    (comp.lang.perl.misc)