Thank you LanX and GrandFather for your response.

this is a very puzzling request, because how do you write code for variables which may or may not exist?

These are fields that will/won't be sent from front end. My code for each of these fields is in separate if(@arr_0), if($scal_1) blocks. So if any of these variables don't exist, the related code will not execute.

Why? What is the bigger goal?

The reasons I am trying to find if this is possible is:

1) If this is possible, I'll create variables only for those fields that were selected by user. (And so will have non empty values)

2) This will also prevent need for any immediate code changes at back end when fields are added or removed from the front end. If a field is removed from front end, the variable will not be created for it and related code block for that field will not execute. When fields is added at least the variable will be created for new field. I can make use of that. I'll still have to write code specific to that field.

Do you know that a hash value can be anything, including a reference to another (nested) hash or a reference to an array?

Thank you for suggesting this. I know about it but will be thinking in that direction now. Will try to see if I can make use of this somehow.


In reply to Re^2: How to create variables for each hash key that has a value. by Perl300
in thread How to create variables for each hash key that has a value. by Perl300

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.