I've searched high and low, and I still cannot get this to work. Any suggestions are welcome! TIA

#!/usr/local/bin/perl use strict; use warnings; no strict "subs"; no strict "refs"; my $line = 'fields: name addr zip state city'; my $var_city; print "$line\n"; $line =~ s/[-)(]//g; my @columnNames = split(/\s+/, substr($line,9)); print @columnNames; print "\n\n"; my $acount = 0; foreach my $name (@columnNames) { $acount++; print "name is: $name\n"; ${var_."$name"} = $acount; #print "nname is: ${"$name"}\n" } print "this should display 5: $var_city\n";

Here is the output:

fields: name addr zip state city nameaddrzipstatecity name is: name name is: addr name is: zip name is: state name is: city Use of uninitialized value $var_city in concatenation (.) or string at + G:\Projects\WebLogReporting\VarValAsVarName.pl line 28. this should display 5:

In reply to Using Variable Value as Variable Name by umama

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.