Question

I have a Perl script which has the following line in it:

print $_->{label} || $_->{irq}, "=", $_->{count}, "; " for @irqs;

Where @irqs is some kind of collection (I am not a Perl programmer) that is pushed to elsewhere in the program.

I have another collection which is a hash, where the key is equal to either the value of $_->{label}or $_->{irq} from the collection @irqs.

Instead of printing $_->{count} in the above statement, I would like to print $_->{count} - X where X is the value from the hash.

I am sure that I can do this by iterating through @irqs by hand and pushing either $_->{label}or $_->{irq} onto a new collection with the calculated value, but, is there a better way to do it?

As I said, I'm not a Perl programmer, so I just wanted to make sure I was going down the correct path before starting out...

Was it helpful?

Solution

You don't need to copy/store any additional data to do this.

foreach my $irq (@irqs) {
    my $key = $irq->{label} || $irq->{irq};
    print $key, "=", $irq->{count} - $myhash{$key}, "; ";
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top