Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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

by Lawliet (Curate)
on Feb 27, 2009 at 00:28 UTC ( #746715=note: print w/replies, xml ) Need Help??

in reply to Re^2: I need a "non-trivial" bug for my script!
in thread I need a "non-trivial" bug for my script!

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.

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

Replies are listed 'Best First'.
Re^4: I need a "non-trivial" bug for my script!
by f00li5h (Chaplain) on Feb 27, 2009 at 00:36 UTC

    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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://746715]
[Corion]: A good morning!
[Discipulus]: good morning Corion!
[Corion]: I spent parts of yesterday digging into Filter::Simple to make it not change the line numbers of unfiltered code, but I think I need regex help (which will come in a SoPW I guess). I tried @lines = /((?:"...."|[^" \n]+)\n)/gs, but that matched on...
[Corion]: ... foo "\0\0\0\n" bar\n by matching the first \n instead of matching the four-bytes-in- double-quotes part
[Corion]: ... and I still don't understand why ;)
[Corion]: This is because Filter::Simple does some string-trickery, replacing all string literals with "quoted packed numbers"

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2017-01-23 08:02 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (191 votes). Check out past polls.