in reply to regular expressions
Here's one way you could grab out the words. I didn't use grep(), I just did a comparison of each word against the regex directly. I also changed your open() statement to coincide with the recommended way to write them, and used ranges in the regex just so you're aware they are available. Note the 'i' after the regex; that's to make the regex case-insensitive.
#!/usr/bin/perl use strict; use warnings; open my $fh, '<', "input.txt" or die "Can't open the file: $!"; my @words; for my $line (<$fh>){ chomp $line; for my $word (split(/\s+/, $line)){ if ($word =~ /[b-df-hj-np-tv-z]{4}/i){ push @words, $word; } } } print "$_\n" for @words;
-stevieb
|
|---|