in reply to Re^4: Recomendations For Learning perl?
in thread Recomendations For Learning perl?
Sure, here you go:
Things to maybe note:use strict; use warnings; use Algorithm::Diff qw/ LCS_length /; ( my $name = $ARGV[0] ) && length $ARGV[0] > 2 or die "Usage: `$0 <nam +e>` (min. 3 letters)"; open my $fh, '<', '/usr/share/dict/words' or die $!; my $found = 0; while ( <$fh> ) { next unless LCS_length( [ split //, $name ], [ split // ] ) == len +gth $name; $found++; print "$found $_"; } __END__
while ( <$fh> ) { ... }
, omitting the second argument to split, and Perl knows to Do The Right Thing. More self-documenting usage would be:while ( <$fh> ) { # each line is loaded into $_ in turn my @characters = split //; }
while ( my $line = <$fh> ) { # each line now in $line my @characters = split //, $line; }
Hope this helps! have fun ....
edit: fixed missing parens
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Recomendations For Learning perl?
by adamZ88 (Beadle) on Dec 08, 2016 at 04:26 UTC | |
by Laurent_R (Canon) on Dec 08, 2016 at 08:33 UTC | |
by 1nickt (Canon) on Dec 08, 2016 at 16:03 UTC | |
by adamZ88 (Beadle) on Dec 08, 2016 at 20:18 UTC | |
by Discipulus (Canon) on Dec 08, 2016 at 21:38 UTC | |
by adamZ88 (Beadle) on Dec 08, 2016 at 22:09 UTC | |
by 1nickt (Canon) on Dec 08, 2016 at 21:10 UTC | |
by adamZ88 (Beadle) on Dec 08, 2016 at 21:21 UTC | |
|