Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Pattern Matching in Cygwin Perl vs. Win32 Perl

by ikegami (Patriarch)
on Aug 26, 2008 at 23:01 UTC ( [id://707002]=note: print w/replies, xml ) Need Help??


in reply to Pattern Matching in Cygwin Perl vs. Win32 Perl

open WORDLIST, "< WORD.LST" || die "Cannot open WORD.LST: $!\n";

means

open WORDLIST, ("< WORD.LST" || die "Cannot open WORD.LST: $!\n");

which is the same as

open WORDLIST, "< WORD.LST";

(since "< WORD.LST" is true). Try

open WORDLIST, "< WORD.LST" or die "Cannot open WORD.LST: $!\n";

If that doesn't help, try printing out $word and $newWord using Data::Dumper and $Data::Dumper::Useqq = 1;. You might have line-ending issues.

Replies are listed 'Best First'.
Re^2: Pattern Matching in Cygwin Perl vs. Win32 Perl
by CharlesClarkson (Curate) on Aug 27, 2008 at 01:41 UTC

    Also, leave the newline ending off the end of the die() statement. It supressses line number information. According to perlfunc, die:

    If the last element of LIST does not end in a newline, the current script line number and input line number (if any) are also printed, and a newline is supplied.

    Here is my favorite file opener. I have used it for a couple of years and used to routinely catch a lot of wierd errors due to my typing skills (or lack there of).

    • It doesn't suppress line number info,
    • It uses the three argument style for open,
    • It uses one of those cool quote-like operators (qq{}),
    • It uses the lower precedence or operator to avoid extra parentheses
    • It uses a scalar ($fh) instead of a glob (FH) to hold the file handle and allows me to avoid local when passing file handles,
    • It quotes the file name in the error message in case something wonky is going on with white space (or I screwed up the file name), and
    • It looks good in my editor's syntax highlighter. :)
    open my $fh, '<', $filename or die qq{Cannot open "$filename": $!}; open my $fh, '>', $filename or die qq{Cannot open "$filename": $!}; open my $fh, '>>', $filename or die qq{Cannot open "$filename": $!};
    HTH,
    Charles

      I disagree completely with your first point. If you need to know on what line an I/O error occured, something is horribly wrong with your error handling. Users must not have to dig into a program to find and address the cause of errors under their control (as opposed to a programming error).

      I agree with the other changes, but I didn't want to venture far from the topic until the OP's problem became known. How I write it:

      open(my $fh_log, '>>', $qfn_log) or die(qq{Cannot open log file "$qfn_log": $!\n});

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-25 21:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found