Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: How to club different lines of program into one

by ww (Archbishop)
on May 25, 2009 at 17:34 UTC ( [id://766078]=note: print w/replies, xml ) Need Help??


in reply to Re: How to club different lines of program into one
in thread How to club different lines of program into one

...and the lack of testing shows.

syntax error at 766040.pl line 7, near "close"

You're missing a terminal semicolon at the end of line 6.

where file.txt is:

001: january 002: february 003: egypt 004: moon 005: saturday

The presence or absence of the line numbers reflects laziness and slow downloads but makes no difference here.

Suggestion: Use 3-arg opens and test each one (...|| die "Can't open $file: $!\n";.

Also, IMO, McDarren's response below strikes an appropriate chord. If the list of "wanted" words is in file.txt, then testing for their presence merely burns cycles and inconveniences electrons to no purpose whatsoever.

Hence, one might infer that OP failed to specify the issue adequately and that leads to another question: Is the intent to find the "wanted" words *anywhere* within the text or is it to test the text, line-by-line, and report per-line. One might guess from OP's wording that it's the former < update for clarity (in which case, slurping the file is fine [size issues aside] but would NOT be a good approach in the latter case ). but In /update> any case, leaving the reader guessing doesn't always get the best answer.

But, all that said, a question (perhaps ignorant) for akho: why scalar <$file>; for this application?

Replies are listed 'Best First'.
Re^3: How to club different lines of program into one
by akho (Hermit) on May 25, 2009 at 19:40 UTC
    I was writing this on a machine without Perl, thus the syntax error and no testing; I also tried to be extra safe with context in the do. That scalar is not necessary.

    Sorry for the confusion, if there was any.

    As for the OP's intent: it is hard to understand it. But the title question was "How to club different lines of program into one", so I tried to do the same thing the OP's code is doing, but in less lines.

    And I don't have an excuse for not testing my open except that I usually use autodie.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2026-02-17 08:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.