in reply to Vowel search

Consider the implicit suggestions in this refactoring of your Perl script.

#!/usr/local/bin/perl use strict; use warnings; use autodie qw( open close ); @ARGV == 1 or die "Usage: perl $0 file\n"; my $file = shift; open my $fh, '<:encoding(UTF-8)', $file; my @lines = <$fh>; close $fh; for my $line (@lines) { print $line if $line =~ m/[aeiou][aeiou]/i; } exit 0;

Since your script is using regular expression pattern matching, it's important that it knows the correct character encoding of the text in the input text file. I've assumed it's in the UTF-8 character encoding form of the Unicode coded character set. If it's in some other character encoding (e.g., Windows-1252), then you need to modify the second argument of open.

I'm creating a script that reads the file lines into an array and then searches and print the words that have 2 consecutive vowels in them

Neither your script nor my refactoring of it are doing exactly this. They're both printing whole lines on which there are two consecutive vowels anywhere on the line. The following script parses each line into words (where "words" are contiguous strings of non-whitespace characters) and then prints each word that has two consecutive vowels in it (where "vowels" are the Latin letters A/a, E/e, I/i, O/o and U/u).

#!/usr/local/bin/perl use strict; use warnings; use open qw( :encoding(UTF-8) :std ); @ARGV or die "Usage: perl $0 file ...\n"; while (my $line = <ARGV>) { chomp $line; my @words = split ' ', $line; for my $word (@words) { print "$word\n" if $word =~ m/[aeiou][aeiou]/i; } } exit 0;

Replies are listed 'Best First'.
Re^2: Vowel search
by Noob@Perl (Novice) on Jun 11, 2014 at 22:20 UTC
    This hit the nail in the head. Just tweaked it a little and managed to print the words from the file. I really appreciate your help Jim. I don't know why i'm having such a hard time with Perl...Iv'e read and read and it just flies through my brain!
      I don't know why i'm having such a hard time with Perl...Iv'e read and read and it just flies through my brain!

      It sounds like you're doing wrong what I do wrong:  Read too much and code too little. It's my worst bad habit. This is precisely why I tried to help you a bit by refactoring your code. Study each of the changes I made very carefully, asking yourself "Why did he do that?" for each one. I promise you you'll learn several helpful lessons.

      Are you using a good programmer's text editor with Perl syntax highlighting? If not, do. One of the obvious problems you're having is with trivial syntax errors (i.e., typos). A good Perl text editor will help you avoid these.

        I am using notepad++ as I use this to create web pages using html and css. since it had Perl editing i didn't want to download something else at the time.