Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^2: regex pattern match

by AnomalousMonk (Chancellor)
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"'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026548]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2018-06-21 03:48 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.