Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Syntax error in using do-until loop: How can I fix it?

by BrowserUk (Pope)
on Jul 16, 2012 at 10:21 UTC ( #981997=note: print w/ replies, xml ) Need Help??

in reply to Syntax error in using do-until loop: How can I fix it?

If you formatted your code correctly, the reason becomes obvious.

You've added your until clause to the end of your foreach loop:

#!/usr/bin/perl-w ## To chop a sentence at intervals of 4-letter and to print results: use strict; my $sentence="BEAR CALF DEER FEAR GEAR HEAR"; ## To remove blank spaces: # Line 5 $sentence=~ s/\s//igs; print"\n Words are: \n"; do { my @four=$sentence=~ /[a-zA-Z]{4}/igs; # Line 9 foreach my $word(@four) { print"\n $word: "; my $length=length($word); print"\n Length of the word= $length\n\n"; my $output="Words .txt"; # Line 14 unless (open(RESULT,">$output")){ print"Cannot open file\"$output\".\n\n"; # Line 16 exit; } print RESULT"\n Words are: \n Word: $word; Length of the word= $length\n\n"; close(RESULT); # Line 21 } until ( my $word=~ /^.*$/); # Line 22 exit; }

In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Comment on Re: Syntax error in using do-until loop: How can I fix it?
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981997]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
As of 2014-07-12 18:58 GMT
Find Nodes?
    Voting Booth?

    When choosing user names for websites, I prefer to use:

    Results (240 votes), past polls