hi

i'm trying to solve this problem elegantly, so any suggestions are welcomed.

use strict; use warnings; my $array; if (ref $array eq 'ARRAY' && ref $array->[0] eq 'HASH' # checking if t +he contents of array ref is a hash ref ){ do something }
so the thing is that my $array can be an array of strings, or array references or hash references. and i need to check if it is a set of strings , or arrays or hashes and if those variables (strings or hashes or arrays) are initialized or not

because some times those variables could be declared but not initialized ! (and then i get warnings :) - don't like them very much)

so far i've been doing it like this but now it seams to me that this way is a little bit ... (can't find the right word).

thanx

rb

update:

ok there is an input file from which i read some lines each line has an indicator to tell the program if it should create an array for storing that data or hash or just plain scalar. and then it imports that data into that array or hash or.. but some lines have just an indicator to create a special type of variable but since there is no data to be imported then that variable stays empty.

then after the load process is finished program starts to check what type of data is in array (array ref, scalar or hash ref). and based on what type of data it is, it does something with that data and if the variable is empty ->[] it does something else ( + reports a warning), so it is important for some variables to be declared but empty. hope this clarifies things

Updata 2:

"all of the array elements are of the same kind" - yes , they have to be


In reply to how to check contents of my array ref by baxy77bax

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.