Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

RE: Using PerlMonks code

by reptile (Monk)
on Jul 11, 2000 at 00:45 UTC ( #21869=note: print w/ replies, xml ) Need Help??


in reply to Using PerlMonks code

Pretty good, although (and I haven't tested this or anything, so I could be wrong) I believe the last regex could pose a problem at times...

s/(<a href="[^"]+">(\d+)<\/a>)/[$2]/g;

What if the person wrote something like $array[$foo]? Since it only matches when there's a number in the regex, it won't work in this instance. Perhaps something like this:

s/(a href="[^"]+">(\$\w+|\d+)/[$2]/g;

Which would accept all digits or any word preceeded by a $. Of course it still doesn't predict all possibilities, like using a hash value or another array, or taking an array slice, etc. but that particular would tend to crop up pretty commonly I imagine.

All in all, a nice, useful script. Thanks for posting it.

local $_ = "0A72656B636148206C72655020726568746F6E41207473754A"; while(s/..$//) { print chr(hex($&)) }


Comment on RE: Using PerlMonks code
Select or Download Code
RE: RE: Using PerlMonks code
by Ovid (Cardinal) on Jul 11, 2000 at 01:21 UTC
    That's a nice point. I threw this code together rather quickly, so I didn't think of all possibilities. That last regex could definitely use some beefing up and I think you've given it a good start. Thanks for the feedback!

    Just a quick (untested) stab:

    s/<a href="[^"]+">([^<]+)<\/a>/[$1]/g;
    This is pretty generic and I would only use it in this context because there is an assumption that the data will be more or less valid. I think it would catch most cases. Also, I dropped a set of parentheses. I have no frickin' idea why I had them in the first place.

    Cheers,
    Ovid

    Update: I've now tested this regex modification and it appears to work fine. I also realized a potential bug in the code that would be rare, but difficult to circumvent: if someone names a sub "amp" (or another HTML character code name) and tries to call the sub with '&amp;', this code will cheefully convert that to '&' and the resulting code will not function properly.

    Update #2: buzzcutbuddha pointed out that the "Bug" I mentioned wasn't behaving quite the way I posted. It will only occur if someone names a subroutine "amp" and then posts the code without code tags. Highly unlikely, but a possibility.

      in response to your update, wouldn't you actually get
      &amp;amp;
      in ASCII/escaped HTML if someone named a subroutine amp?

      To check for the above use
      /\&(amp;)($1)/
      and you would catch it. Just a quick thought. :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-12-22 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls