On Thu, Sep 8, 2011 at 11:58 AM, Marc <sono...@fannullone.us> wrote: > I'm trying to capitalize 3 and 4 letter words that contain > only vowels or consonants, but not both. The code I've come > up with is not working correctly. Given the string > 'The Kcl Group', it should return 'The KCL Group' but it is > also capitalizing the word 'THE'. What am I doing wrong? *snip* > my @words = split(/ /, $string); > my @new_words; > foreach my $word (@words) { > if ((length $word >= 3 and length $word <= 4) and ($word !~ > m/[aeiouy]+/gi or $word !~ m/[bcdfghjklmnpqrstvwxz]+/gi)) { > $word = uc($word); > } > push @new_words, $word; > } > $string = "@new_words";
Hmmm, couldn't you just use a s/// operator for this? #!/usr/bin/perl while(my $original = <DATA>) { chomp $original; (my $modified = $original) =~ s/\b([aeiouy]{3,4}|[bcdfghjklmnpqrstvwxz]{3,4})\b/uc($1)/egi; print "$original -> $modified\n"; } __DATA__ The Kcl Group Off The Menu Output: The Kcl Group -> The KCL Group Off The Menu -> Off The Menu -- Brandon McCaig <http://www.bamccaig.com/> <bamcc...@gmail.com> V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl. Castopulence Software <http://www.castopulence.org/> <bamcc...@castopulence.org> -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/