Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Regular Expression - delimiter/spaces problem

by toolic (Bishop)
on Feb 14, 2014 at 17:43 UTC ( [id://1074983]=note: print w/replies, xml ) Need Help??


in reply to Regular Expression - delimiter/spaces problem

Are you sure the application doesn't output fixed-width data? If it did, then you could use unpack. Otherwise, maybe you can use \d instead of \w if some of your columns always output numbers.

UPDATE: This seems to work. Probably no uglier than a regex:

use warnings; use strict; while (<DATA>) { chomp; my @cols = split; my @a1 = splice @cols, 0, 3; my @a2 = splice @cols, -7, 7; my $pool = join ' ', @cols; print join(';', @a1, $pool, @a2), "\n"; } __DATA__ PID POLS U(%) POOL_NAME Seq# Num LDEV# H(%) VCAP(%) TYPE PM 003 POLN 0 Bad name with spaces 13453 2 61443 80 - OPEN N 002 POLN 52 DemoSolutions 54068 7 61454 80 - OPEN N

Replies are listed 'Best First'.
Re^2: Regular Expression - delimiter/spaces problem
by CountZero (Bishop) on Feb 14, 2014 at 21:01 UTC
    Your solution works with the examples, but the specification has for the second field: "1-n characters with 0-n spaces". You solution will break when the second field includes a space.

    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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-23 07:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found