in reply to Re^2: Search string within an predefined array
in thread Search string within an predefined array
@d{@defstream} = (1) x @defstream;This is a way to initialize the %d hash variable. Each element of the @defstream array is used as a hash key, and all values of the hash will equal 1. @d{@defstream} is a hash slice (see Subscripts). Also see Multiplicative Operators for an explanation of "x". It is equivalent to the more verbose:
foreach my $dfs (@defstream) { $d{$dfs} = 1; }
if ($d{$dfs})The "if" tests if the expression in the parentheses, which is a hash subscript, is true. I think moritz probably meant to use:
This will test whether the %d hash contains a key whose name is given by the value of the $stream variable. As hbm points out, it may be more appropriate to use exists.if ($d{$stream}) {
|
---|