in reply to = for lists and hashes?

Is there anything that keeps you from saying
%myHash = ( key1 => 'common Value1', key2 => 'common Value2' ) unless keys %myHash;
? Since you're eval'ing the file anyways, there's nothing to keep you from using any perl construct you want, is there?

You could even hit it key by key, doing

$myHash{key1} ||= 'common Value1'; $myHash{key2} ||= 'common Value2';

--
Mike

Replies are listed 'Best First'.
Re: Re: = for lists and hashes?
by hossman (Prior) on Mar 20, 2002 at 21:29 UTC
    just for completeness: you can also say...
    @myArray = ('common Value1', 'common Value2', ) unless scalar @myArray;

    NOTE: This type of solution breaks down if the user sets @myArray (or %myHash) to an empty array in their conf file (but your existing system of setting scalars breaks down the same way if they have $foo = 0; in their conf file)

      and this will work great for arrays!

      Right now, I can't think of a reason we'd be creating empty arrays... yet ;)

      Thanks!

       

      -justin simoni
      !skazat!

Re: Re: = for lists and hashes?
by skazat (Chaplain) on Mar 20, 2002 at 22:57 UTC

    This will work great for hashes:

    unless keys %myHash;

    I'd hate to hit it key by key, since I have hashes that are almost 100 keys long :)

    uggh.

    Thanks

     

    -justin simoni
    !skazat!