Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.

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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found