in reply to Re^2: Combining hashes of hahses?
in thread Combining hashes of hahses?
$x ||= something; is commonly used to give $x a value if it hasn't one already (more correctly, if the current value is false). In the case cited it is to pick up the first non-zero length of a dna string. There is an implicit assumption that all dna strings are the same length.
Note that Perl returns the value of which ever true value it finds when evaluating || (not simply a true or false value) so $x gets the value 'something' regardless of what the nature of 'something' is if $x is false to start with. In particular, this trick can be used to set a scalar to a default string if the scalar hasn't been set already:
my $error; ... $error ||= 'No error found';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Combining hashes of hahses?
by convenientstore (Pilgrim) on Nov 07, 2007 at 22:20 UTC |