Re: Printing and Formatting data from hash (or array)
- From: "J. Gleixner" <glex_no-spam@xxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 30 Oct 2006 12:02:55 -0600
Mike wrote:
Mike wrote:
[...]
I've been tinkering with printing thevalues 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.
Post a short example of how you're doing that.However, when I copy all the hash data to an array, and print the
array, it doesn't show all the duplicated data.
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";
.
- Prev by Date: Re: Interesting behaviour with lexical variable
- Next by Date: How to get a full trace of a prog's execution?
- Previous by thread: Interesting behaviour with lexical variable
- Next by thread: How to get a full trace of a prog's execution?
- Index(es):
Relevant Pages
|