in reply to Re: gathering of some elements of a list
in thread gathering of some elements of a list


Dear ikegami
I would like that my outfile looks like :
0601|3|NORM|2|ALLO|XLF753|U|0045|0050| 0603|5|NORM|2|ALLO|ADR2CG||0430|0438| 0604|6|NORM|2|ALLO|AF681VC|i U|0500|0510| 0605|7|NORM|2|ALLO|AF651PQ|i|0515|0523| 0606|8|NORM|2|ALLO|AF713BR|i|0445|0453| 0607|9|NORM|2|ALLO|AFR100M|i|0520|0533| 0609|11|NORM|2|ALLO|GJT775|i E|2300|2315| 0610|12|NORM|2|ALLO|AF661WN|i|0450|0500|0500

So that there is a unique column for i, E, and U and if two both appear on the same line, that they are in the same column.

Replies are listed 'Best First'.
Re^3: gathering of some elements of a list
by ikegami (Patriarch) on Jul 30, 2007 at 15:12 UTC

    Here's a solution that creates the output you've added to the OP using the updated input data. (When making changes to a post, especially if replies relied on the original unchanged data, specify the changes you made by adding "Update:".)

    while (<DATA>) { my @parts = unpack('A5 A7 A5 A3 A5 A9 A8 A5 A*', $_); for ($parts[6]) { s/\s+/ /g; s/^\s//; } print(join(';', @parts), "\n"); }

    or

    while (<DATA>) { my @parts = unpack('A5 A7 A5 A3 A5 A9 A2 A4 A2 A5 A*', $_); my $flags = join ' ', grep length, @parts[6..8]; splice(@parts, 6, 3, $flags); print(join(';', @parts), "\n"); }

    The second version is basically the same as FunkyMonk's, but I do the substitution after extracting the fields.