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;

In reply to Re: Vowel search by Jim
in thread Vowel search by Noob@Perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.