SPUG: The string name of a variable (or any identifier)

ced at carios2.ca.boeing.com ced at carios2.ca.boeing.com
Thu Jan 29 11:59:57 CST 2004


> Anyone ever wanted to do something like this? I do it all the time in
> Anyone ever wanted to do something like this? I do it all the time in
> debugging, but I can't put it in a loop like this

> my ($x, $y, $z) = (1..3);
> @stuff_to_debug = ($x, $y, $z);
> foreach (@stuff_to_debug) {
>    printf "%s %d\n", $_.printable_name, $_;
> }


Not quite as elegant as an array but did someone already 
suggest a hash...

my %stuff_to_debug;
@stuff_to_debug{'x'..'z'} = 1..3;
while ( my($key,$value) = each %stuff_to_debug ) {
    printf "%s %d\n", $key, $value;
}

--
Charles DeRykus



More information about the spug-list mailing list