Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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; }

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
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?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2015-11-30 16:10 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (777 votes), past polls