in reply to Re: Regular Expression
in thread Regular Expression

Thanks for the information Zaxo. The first example cuts down a lot of code I had plan to use. I can't really use the second example because I need this to work on both windows and unix, though eventually it will be unix only. However the words are still missing when the search is started. Here is the code...
use strict; use warnings; my @matches = (); open (DICT, "dictionary.txt") or die "Dictionary.txt: $!\n"; while (my $words = <DICT>) { chomp $words; push @matches, $words . " 1" if $words =~ /a$/; push @matches, $words . " 2" if $words =~ /.*[i].*[i].*[i].*[i].*[ +i].*/gi; push @matches, $words . " 3" if $words =~ /[^aeiou]/gi; my $reverse = reverse($words); push @matches, $words . " 4" if $words eq $reverse; } close (DICT); foreach (@matches) { print $_; }

Replies are listed 'Best First'.
Re: Re: Re: Regular Expression
by graff (Chancellor) on May 19, 2003 at 01:43 UTC
    Regarding this issue:

    I need this to work on both windows and unix

    The safest way to remove line terminations across platforms is:

    s/[\r\n]+//;
    For that matter, you could probably just do s/\s+//g; based on the assumption that the only white space to be found in your dictionary file is the line breaks.
Re: Re: Re: Regular Expression
by hangmanto (Monk) on May 19, 2003 at 00:17 UTC
    You might want to check to see if the words are there inside of the while loop. A simple print statement like
    print "----$words-----\n";
    inserted after the chomp statement may detect the problem.