in reply to Re: Increaing a field size for a record
in thread Increaing a field size for a record
There's no magic that would allow expand field in place.
What? No magic? But this is Perl — of course there’s magic!
#! perl use strict; use warnings; use Tie::File; my $filename = 'data.txt'; tie my @lines, 'Tie::File', $filename or die "Cannot tie file '$filen +ame' to array: $!"; for (my $i = 0; $i < @lines; ++$i) { my @fields = split ' ', $lines[$i]; $fields[1] .= ' ' x (50 - length $fields[1]); $lines[$i] = join(' ', @fields); } untie @lines;
Test file “data.txt” before running the script:
DSE 1232123456 ABCDEF96DS0 20100722 20120827KJHLK LKEDX 058305574 IAC +8 S73 WERTYU DSE 987 ABCDEF96DS0 20100722 20120827KJHLK LKEDX 058305574 IAC 8 S73 W +ERTYU DSE 12321234567890 ABCDEF96DS0 20100722 20120827KJHLK LKEDX 058305574 +IAC 8 S73 WERTYU
and after:
DSE 1232123456 ABCDEF96DS0 201 +00722 20120827KJHLK LKEDX 058305574 IAC 8 S73 WERTYU DSE 987 ABCDEF96DS0 201 +00722 20120827KJHLK LKEDX 058305574 IAC 8 S73 WERTYU DSE 12321234567890 ABCDEF96DS0 201 +00722 20120827KJHLK LKEDX 058305574 IAC 8 S73 WERTYU
;-)
Athanasius <°(((>< contra mundum
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Increasing a field size for a record
by zwon (Abbot) on Oct 16, 2012 at 15:38 UTC | |
Re^3: Increasing a field size for a record
by McA (Priest) on Oct 16, 2012 at 13:31 UTC | |
by sundialsvc4 (Abbot) on Oct 16, 2012 at 13:44 UTC | |
by Athanasius (Archbishop) on Oct 16, 2012 at 13:39 UTC | |
Re^3: Increasing a field size for a record
by Thomas Kennll (Acolyte) on Oct 16, 2012 at 17:59 UTC | |
by Athanasius (Archbishop) on Oct 17, 2012 at 05:35 UTC | |
by Thomas Kennll (Acolyte) on Oct 22, 2012 at 07:51 UTC |
In Section
Seekers of Perl Wisdom