If the content of one scalar variable is the name of another scalar variable, how can I use the first scalar variable to provide the name to the program?

Or, to say it another way:
if
$foo = meow;
$boo = foo;
then does $$boo = meow;?
or `${$boo}` or `${boo}`?

Here's a little more precise version of the question using the code I'm currently grappling with.

#!/usr/bin/perl -w use strict; ## usage information # $0 UPSNAME HOSTNAME DATAPOINT # where DATAPOINT can be any of # utility - the number VAC utility power is providing # loadpct - the percentage of the maximum load # battpct - percent of total battery charge available # runtime - approx. number of minutes of battery life my $lookfor = $ARGV[2]; my @upsinfo = (`/usr/local/bin/upsc $ARGV[0]\@$ARGV[1]`); my ($junk, $utility) = split /\s+/, $upsinfo[10]; my ($kunk, $loadpct) = split /\s+/, $upsinfo[14]; my ($lunk, $battpct) = split /\s+/, $upsinfo[21]; my ($munk, $runtime) = split /\s+/, $upsinfo[23]; if ($lookfor) { print $$lookfor; } else { print "utility is $utility\n"; print "loadpct is $loadpct\n"; print "battpct is $battpct\n"; print "runtime is $runtime\n"; };
Why do I get the error:
Can't use string ("loadpct") as a SCALAR ref while "strict refs" in use... line 20 ?

Now, Page 58 of the Camel book (v3) says that $bert and ${ some_expression() } are the same, where some_expression() 'returns a reference to variable $bert (or even the string, "bert")'

I know that references are a concept around which my grasp is not firm, perhaps I've got it all mistaken. Please someone show me how to understand this problem.

Apologies if this is covered somewhere but I have not found it, a link and an RTFM is a generous answer.

By the way, this $0 is what I'm cobbling together to use NUT the Network UPS Tools and MRTG to chart the usage and performance of my UPSes over time.

In reply to scalar dereferencing by jamgill

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.