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"'
In reply to Re^2: regex pattern match
by AnomalousMonk
in thread regex pattern match
by reaper9187
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |