in reply to Crazy constant question...
Used a HoA to allow for multiple constants having the same value.#!/usr/bin/perl use strict; use warnings; use constant { FOO => 1, BAR => 2, BAZ => 1 }; my %val_to_name; { no strict 'refs'; foreach my $con (keys(%constant::declared)) { push @{$val_to_name{$con->()}}, $con; } } my $thing = FOO; print "$thing defined by: " . join(" and ", @{$val_to_name{$thing}})." +\n";
|
---|