Home > Archive > PERL Beginners > July 2007 > Printing a reference of an array
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Printing a reference of an array
|
|
| Bryan Harris 2007-07-25, 6:59 pm |
| Hi,
I'm trying to figure out how to print the following array. How do I
print this type of thing? Please let me know if I'm posting to the
wrong list.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Getopt::Long;
my $name;
GetOptions('name=s@{1,}' => \$name);
print $name;
When I run the program I get the following results.
../getopts.pl --name bryan stephen robert
ARRAY(0x81308f4)%
I've tried several different ways of printing it, but with no luck so
far. Sometimes I get the following type of message, when I use
different variables like \$name[1], or other variations.
Global symbol "@name" requires explicit package name at ./getopts.pl line 10.
Execution of ./getopts.pl aborted due to compilation errors.
--
Bryan
| |
| Mr. Shawn H. Corey 2007-07-25, 6:59 pm |
| Bryan Harris wrote:
> Hi,
>
> I'm trying to figure out how to print the following array. How do I
> print this type of thing? Please let me know if I'm posting to the
> wrong list.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use Data::Dumper;
> use Getopt::Long;
>
> my $name;
> GetOptions('name=s@{1,}' => \$name);
> print $name;
>
> When I run the program I get the following results.
>
> ./getopts.pl --name bryan stephen robert
> ARRAY(0x81308f4)%
>
> I've tried several different ways of printing it, but with no luck so
> far. Sometimes I get the following type of message, when I use
> different variables like \$name[1], or other variations.
>
> Global symbol "@name" requires explicit package name at ./getopts.pl
> line 10.
> Execution of ./getopts.pl aborted due to compilation errors.
>
You have to dereference the reference:
print @$name;
Or:
print @{ $name };
To access a member of the array, you use the arrow operator:
print "The first value is $name->[0]\n";
See `perldoc perlreftut` and `perldoc perlref` for more info.
--
Just my 0.00000002 million dollars worth,
Shawn
"For the things we have to learn before we can do them, we learn by doing them."
Aristotle
|
|
|
|
|