Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Regex copy and paste help

by CountZero (Bishop)
on Sep 01, 2012 at 13:17 UTC ( #991154=note: print w/replies, xml ) Need Help??

in reply to Regex copy and paste help

I would do it this way:
use Modern::Perl; while (<DATA>) { my @record = split; if ($record[1]=~s/-$//) { while (<DATA>) { my ($continuation) = split; $record[1] .= $continuation; last unless $record[1]=~s/-$//; } } say join ' ', @record; } __DATA__ A00002 \\a00002\c$ 2 WinNT NTFS Yes 73,626MB 42.5 A00003 / 1 Linux86 EXT3 No 38,289MB 29.8 A00004 A00004 \Sys- 1 WinNT VSS Yes 0 KB 0.0 temState\- NULL\Syst- em A00005 /xyz 4 Linux86 EXT2 No 12,345MB 30
And yes, you get a few "Use of uninitialized value $record1" warnings because of the anomalous third record which has only one filed "A00004" in it. You can safely ignore these warnings or add another test to drop such record if you do not need it.


A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991154]
LanX is reminded that public sarcasm is causing rpoblems nowadays ... ehm ...
[Your Mother]: Americans love massacres as long as it's brown and red people. Ooops. That was supposed to be a state secret. There goes my Q clearance.
[Your Mother]: It would hillarious to learn the Flat Earth movement was started by misunderstood sarcasm.
[Corion]: Your Mother: Aah - Server Side Events maybe, which mostly sends events from the server as they come up?
[Your Mother]: Sounds right.
[Corion]: Your Mother: I think that that is basically the origin story. Flat earth started as trolling, but then the real believers drove out the trolls
LanX is pretty brown in summer
[Your Mother]: Though a bad match for the OP in question here. :P
[Corion]: Your Mother: Yeah

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (17)
As of 2018-03-19 13:37 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.