in reply to Array: inserting what isn't there
Produces:while(<DATA>) { # regex detects or doesn't detect number as $found in line m/magic_phrase:(\d+)/; next unless ( $found = $1 ); $max = ( $found >$max ? $found : $max ); $seen{$found}++; } sub isit { return exists $seen{$_[0]}; } # if you really need the output (or array) for ( 1..$max) { my $str = ( isit($_) ? "$_.found" : "$_.lost" ); print "$str\n"; push @array, $str; } print "\@array is @array\n"; __DATA__ magic_phrase:2 magic_phrase:5
1.lost 2.found 3.lost 4.lost 5.found @array is 1.lost 2.found 3.lost 4.lost 5.found
|
|---|