Dear monks,
Im struggling with references. Tye's
References quick reference is a great for information about dereferencing, and chapter 8 of programming perl has a lot about references. Even with this information however I have still come across a problem.
The following code is part of an object orientated package, hence the self reference (otherwise I could
understand manage it) and is trying
to use Getopt::Long
sub readoptions {
my $self = shift;
# usually I would create a hash %hash = ( foo => \$bar );
# and reference %hash. unless i'm mistaken this creates
# an anoymous hash and stores it in $self->{CONFHASH}
$self->{CONFHASH} = { foo => \$self->{BAR} };
# first argument to GetOptions woudl usually be \%hash
GetOptions( $self->{CONFHASH}, 'foo|f' ) or die "option not found";
}
Yes, this is completely wrong. The result is trying to be something where I can do $self->{BAR} to find an option. Would a fellow monk care to enlighten me?
Update: oops, i stated $self->{CONFHASH}->{foo} when I meant $self->{BAR}, although both ways are good
TIA
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.