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

Re: I need a "non-trivial" bug for my script!

by almut (Canon)
on Feb 26, 2009 at 22:09 UTC ( [id://746685]=note: print w/replies, xml ) Need Help??


in reply to I need a "non-trivial" bug for my script!

As you're doing regex matching, you could construct something around this feature:

From perlop:

m/PATTERN/cgimosx

(...)
If the PATTERN evaluates to the empty string, the last successfully matched regular expression is used instead.

I've seen rather experienced programmers having been bitten by this...

  • Comment on Re: I need a "non-trivial" bug for my script!

Replies are listed 'Best First'.
Re^2: I need a "non-trivial" bug for my script!
by Fletch (Bishop) on Feb 26, 2009 at 22:13 UTC

    Another good regex-related one is blindly assuming a match succeeded and geting "stale" results from the last one which was successful sitting in $1 and friends.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Hah, I hated that one! Out of curiosity, what is the best method of fixing it? Undefining $1 before the regex (not sure if that is possible), testing to see if the regex is successful, or something else?

      And you didn't even know bears could type.

        Do the match in list context, and don't use $\d+ at all

        if (@kitties = $string =~ /pattern (with) captures/) { paw_at @kitties; }
        Obviously you can use my($cats, $kittens) in place of @kitties there.

        The other option is check that the match succeeded first

        if ($string =~ /pattern (with) captures/) { paw_at $1; }
        but $1 is ugly... unpacking into either an array or bundle of scalars will get you less maintenence-programmer hate.

        @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-23 15:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found