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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Okay, so we've got;

%defaults = map {(/(.*?)=(.*)/)} @ARGV;
Which is cute. Except it fails under some conditions. Let's say you want to give the variable 'foo' the value of 'moo shoo= coo'. I'd assume it would be written 'foo=moo shoo\= coo'. Except your example doesn't allow for this.

So I tried a little, and this is what I got;

I was working from the param line as a single scalar variable for simplicity, and my first efforts seemed moderately successful;

$line = 'foo=moo sho=clue\ woo\=moo'; @pairs = split(/(?<!\\)\s/, $line);


However, this system has the problem of only checking whether the previous character is a backslash - it doesn't allow for backslashed backslahes. The expression would need to understand that '\\=' signified a backslash and then a non-escape literal. But it couldn't just check for two slashes and cancel, for it should accept '\\\=' as a a backslashed backslash and a backslashed equals symbol. It would, effectively, need to look behind for an even number of slashes, and only slash on that.

I had;
@pairs = split(/(?<!(\\\\+))\s/, $line); Which seemed perfect. Except we're not allowed variable length lookbehind, because it's not been implemented yet. Which was very annoying to find out. So, we could match the proceeding backslashes normally, but strap them back on. But that would be horrible. I have tried further routes, but found nothing. *sigh*

tlhf
xxx

In reply to Doesn't seem complete by tlhf
in thread Regular expression double grouping negation headache by JayBonci

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-18 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found