in reply to Passing a $Scaler into a while loop...

chinamox: FWIW, it can be a little tough to help without seeing your data.

Try something like this:

while( my $line = <DATA> ){ ... } ... __DATA__ sample input data

Having said that, you've got a trailing }, so that's an issue.

open (WORDS, 'data.txt') or die "Can't open employees2.txt: $!\n"; my @cols = qw('data.txt');

I'm not sure what you're doing there - your error message ought to reflect the name of the file it's having trouble with. And your @cuts @cols array contains one element, a piece of text 'data.txt'. I don't think that's what you want. Also, your regexes are matching against $_, when you want them to match against $cut, the next element of @words.

Finally, I've reformatted your code, made it compile, and looped through the words of each line (which you weren't doing), and left the "meat" of your "algorithm" in place. Though that could be cleaned up, too.

#!/usr/local/bin/perl use strict; use warnings; while (my $line = <DATA>) { chomp $line; for my $cut( split /\s+/, $line ){ next if $cut !~ /a/; next if $cut !~ /e/; next if $cut !~ /i/; next if $cut !~ /o/; next if $cut !~ /u/; print "$cut\n"; } } __DATA__ sample line with words input more words thiswordhaseveryvoul so it should print butthisdoesnt nor do these

Output:

$ perl chinamox.pl thiswordhaseveryvoul

HTH



--chargrill
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

Replies are listed 'Best First'.
Re^2: Passing a $Scaler into a while loop...
by chinamox (Scribe) on Oct 09, 2006 at 04:47 UTC

    Wow! Thanks for the excellent reply. I will clean up my code and use the __DATA__ from now on when I post.

      Using __DATA__ instead of external files is a really good start. For a few other related posting tricks take a look at I know what I mean. Why don't you?.


      DWIM is Perl's answer to Gödel