supriyoch_2008 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Perl Monks,
I am a beginner in perl script writing. I have written a small script word.pl (given below) using a do-until loop to chop a sentence in 4-letter words. But it is not showing the results. The line number 22 shows a syntax error for ");". I have not been able to correct the error. I have written line number 22 to search the sentence fron beginning to the end for every 4-letter word. May I expect suggestions from perl monks regarding the error? The script goes like:
#!/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; }
I have got the following results in cmd screen:
Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\xxxxxxx\Desktop>word.pl syntax error at C:\Users\xxxxxx\Desktop\word.pl line 22, near ");" Execution of C:\Users\xxxxxxxx\Desktop\word.pl aborted due to compilat +ion errors.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Syntax error in using do-until loop: How can I fix it?
by BrowserUk (Patriarch) on Jul 16, 2012 at 10:21 UTC | |
Re: Syntax error in using do-until loop: How can I fix it?
by aitap (Curate) on Jul 16, 2012 at 10:22 UTC | |
Re: Syntax error in using do-until loop: How can I fix it?
by grumbert (Scribe) on Jul 16, 2012 at 10:24 UTC | |
Re: Syntax error in using do-until loop: How can I fix it?
by jwkrahn (Abbot) on Jul 16, 2012 at 18:18 UTC | |
Re: Syntax error in using do-until loop: How can I fix it?
by BillKSmith (Monsignor) on Jul 16, 2012 at 19:00 UTC | |
Re: Syntax error in using do-until loop: How can I fix it?
by pvaldes (Chaplain) on Jul 16, 2012 at 23:25 UTC |
Back to
Seekers of Perl Wisdom