On Nov 7, Tim Yohn said:

>Is there an easy way to have variables in the value of a hash that are
>not populated until the value of the hash is used... for example:

You could use my DynScalar module (found on CPAN):

  use DynScalar;

  my $domain;
  my %hash = (
    offline => dynamic { "$domain is offline" },
    busy => dynamic { "sorry, $domain is too busy" },
    # ...
  );

  for $domain (qw( foo.com bar.net )) { print $hash{busy} }

Or, cheat a bit:

  my %hash = (
    offline => "%s is offline",
    busy => "sorry, %s is too busy",
  );

  for my $domain (qw( foo.com bar.net )) {
    printf $hash{busy}, $domain;
  }

OOH!  Cheating using printf format strings!  You like?  I like.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]




















-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to