in reply to trouble acessing array result from GetOptions

Umm, using too much vertical white space? Not saying what you expected to see? Printing a reference rather than dereferencing it?

If the latter is the problem then try this version (note the @$value in the print):

use strict; use warnings; use Getopt::Long; my $key; my $value; my %options; GetOptions (\%options, 'names:s@', 'address:s@'); while (($key, $value) = each %options) { print "$key = @$value\n"; }

Prints:

names = Manny

Or using -names Manny -names Meany -names Minnie on the command line it prints names = Manny Meany Minnie.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: trouble acessing array result from GetOptions
by dark314 (Sexton) on Jul 21, 2006 at 04:23 UTC
    I had figured it out but couldnt delete this post, but thanks for your input!!

      One tip that may help you in similar situations in the future. Whenever you find yourself printing a stringified reference when you expected something else, it's helpful to use Data::Dumper;, and to dump the variable in question into Dumper to see what you get. For example, if you added print Dumper \%options; to your script, you would get a good look at the data structure, and that could help you figure out how to find within it the data you're trying to retrieve.

      Data::Dumper is a great "I wonder what this structure looks like" tool.


      Dave

      Don't delete the post. Others may benefit from your question. Add an Update at the end if you figure it out or the nature of the problem changes, but don't remove or edit the original material in a way that invalidates answers.


      DWIM is Perl's answer to Gödel