in reply to trouble understanding code, and shift() w.o args
my %nu_hash=(); #why is this an empty hash? (is he storing patterns +in a hash?)
It is an empty hash because my creates a new empty variable. Some people feel that assigning an empty list to an already empty variable is a good practice.
my $sstr =""; #why is this an empty string?
Actually, this variable is declared in the wrong scope. It should be:
for ( my $i = 0; $slen >= $i + $pl; $i++ ) { my $sstr = substr( $str, $i, $pl ); $nu_hash{ $sstr }++; }
Which would also be better written as:
for my $i ( 0 .. $slen - $pl ) { my $sstr = substr( $str, $i, $pl ); $nu_hash{ $sstr }++; }
|
|---|