in reply to Parsing a Variable Format String
my @items = split /\s+/, $buf; if (scalar(@items) == 13) { # process (ii) } else { # process (i) or (iii) }
This assumes that the number of token in a line determines the line type.
Update: try this:
use strict; use warnings; while (<DATA>) { my @items = split /\s+/, $_; if (scalar(@items) == 13) { my (@new) = ($items[4] =~ /(PV)(.*)/); my (@new2) = ($items[8] =~ /(RL)(.*)/); splice @items, 4, 1, @new; splice @items, 9, 1, @new2; } print "@items\n"; # now @items always contains same number of to +kens # process items... } __DATA__ SS 21 PL 2#3 PV 51.3 CL #110 +0 RL 126' SA 106 DS 93 SS 21 PL 2#3 PVa51.3 CT^ 110 +0 RL126, SA 106 DS 93 SS 21 PL 2#3 PV 51.3 CL #110 +0 RL 126' SA 106 DS 93
prints:
SS 21 PL 2#3 PV 51.3 CL #110 +0 RL 126' SA 106 DS 93 SS 21 PL 2#3 PV a51.3 CT^ 110 +0 RL 126, SA 106 DS 93 SS 21 PL 2#3 PV 51.3 CL #110 +0 RL 126' SA 106 DS 93
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Parsing a Variable Format String
by ozboomer (Friar) on Jul 10, 2008 at 02:40 UTC | |
by jethro (Monsignor) on Jul 10, 2008 at 03:04 UTC | |
by ysth (Canon) on Jul 10, 2008 at 03:45 UTC |