Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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.

CountZero

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


Comment on Re: Regex copy and paste help
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (15)
As of 2014-07-10 16:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (213 votes), past polls