Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: regex pattern match

by AnomalousMonk (Abbot)
on Apr 01, 2013 at 23:00 UTC ( #1026548=note: print w/ replies, xml ) Need Help??


in reply to Re: regex pattern match
in thread regex pattern match

my ($first, $last ) = /(.+",)(.+)/; $last =~ s//"\n$first"/g;

I second hdb's reply in general.

Let me add that the
    $last =~ s//"\n$first"/g;
statement from the posted code quoted above is very unlikely to do what you want: it will match the  // null regex pattern globally and do a substitution against what is matched. If there has been a previous successful regex match (e.g., the match in the preceding line), the  // regex matches using the previously matched regex. (If there has been no previous successful regex match, the  // regex matches anything!) As it stands, this substitution seems to be a no-op. If it is part of some carefully thought out strategy, I advise you to abandon it immediately: it has 'maintenance nightmare' written all over it! (In the code example below,  \x22 stands in for an unbalanced  " (double-quote) character.)

>perl -wMstrict -le "$_ = qq{\"ABC\",\"DEF\",\"This is a test\",\"Hello\"}; ;; my ($first, $last ) = /(.+\x22,)(.+)/; print qq{'$last'}; ;; $last =~ s//\"\n$first\"/g; print qq{'$last'}; " '"Hello"' '"Hello"'


Comment on Re^2: regex pattern match
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (16)
As of 2014-10-23 14:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls