dirtdog has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, I've got a working snippet of code that will take parameters and stuff them into a hash to be used later in the program to only keep the highest ranked value only (0 is top ranked) if it exists.
hierarchy.pl POPE PATRIARCH ARCHBISHOP CARDINAL#!/usr/bin/env perl use strict; my @hierarchy; my %hierarchy; my $order =0; while ($#ARGV >= 0) { push @hierarchy,shift; } for (@hierarchy) { $hierarchy{$_} = $order; $order++; } while( my( $key, $value ) = each %hierarchy ){ print "$key: $value\n"; }
The code appears to work, but I thought there might be a better way to do it so thought I'd check with the Monks.
Much appreciated!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HASH Hierarchy
by hippo (Archbishop) on Feb 16, 2018 at 15:49 UTC | |
by dirtdog (Monk) on Feb 16, 2018 at 16:10 UTC | |
|
Re: HASH Hierarchy
by Eily (Monsignor) on Feb 16, 2018 at 16:22 UTC | |
|
Re: HASH Hierarchy
by thanos1983 (Parson) on Feb 16, 2018 at 15:57 UTC |