Hello Perl Monks:


I was wondering if there was a way to do this (you will get the idea when you see the code - if not, I'll explain below):


#!/usr/bin/perl -w use strict "vars" ; my $data ; my @splitter ; $data = "testval,1" ; @splitter = split( "," , $data ) ; my $$splitter[ 0 ] = $splitter[ 1 ] ;

I know you can do something like this with hashes, but I don't want to use hashes. Here's the gist of what I am trying to do with this code. I have data (defined here as $data, but will be in a file). It is comma-separated. The first value in this data is the actual variable name I want to define. The second value is the value I want to assign to it. Obviously, assigning the value is easy, but creating the variable is not so easy. The $$ makes sense in terms of real-time substitution, however it doesn't work. Perl is interpreting it to mean something other than a string declaration. The error message given is:


Can't declare scalar dereference in "my" at srtest line 7, near "$spli +tter[" syntax error at srtest line 7, near "$splitter[" srtest had compilation errors.

Any ideas of how to make this work?


Statue


In reply to Self-writing code revisited by Statue

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.