Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; my $data = ''; my $input_file = "string.txt"; open (DATA,"$input_file") || eval { print "Can't open file $input_file: $@"; exit; }; my ($account,$value,$end_value); my @frags; my $c = 0; while (<DATA>) { $data = $_; print "\n 1 - ^^$data^^\n"; my $frag = substr $data, 0, 6; my $frag2 = substr $data, 61, 6; my $frag3 = substr $data, 122, 6; #print "\n 2 - $c ^^$frag^^$frag2^^$frag3^^\n\n"; push @frags, $frag, $frag2, $frag3; foreach my $fs (@frags) { $account = substr $data, 9, 8; # should find: ACCOUNTA - ACCOU +NTB - ACCOUNTA print "\n 1 - ^$account^\n"; if( $account eq 'ACCOUNTA') { $value = substr $data, 22, 7; print "\n 2 - *$value*\n"; if( $value eq 'XXXXXMA') { $end_value = substr $data, 45, 6; print "\n 3 - ^$end_value^\n"; }else { $end_value = substr $data, 167, 6; print "\n 4 - *$end_value*\n"; } } } print "\n $account - $value - $end_value\n"; #1START ACCOUNTA XXXXXMA 12345 XYZ111 #1START ACCOUNTA XXXXXNY 54321 XYZ131 } #DATA from string.txt: #1START ACCOUNTA XXXXXMA 12345 XYZ111 1START + ACCOUNTB XXXXXBR 12345 XYZ191 1START ACCOUNT +A XXXXXNY 54321 XYZ131
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing a long string
by BrowserUk (Patriarch) on Aug 16, 2013 at 19:08 UTC | |
by Anonymous Monk on Aug 16, 2013 at 19:16 UTC | |
by AnomalousMonk (Archbishop) on Aug 16, 2013 at 20:08 UTC | |
by BrowserUk (Patriarch) on Aug 16, 2013 at 20:05 UTC | |
|
Re: Parsing a long string
by toolic (Bishop) on Aug 16, 2013 at 18:17 UTC | |
by Anonymous Monk on Aug 16, 2013 at 19:12 UTC | |
|
Re: Parsing a long string [OT]: strange open
by AnomalousMonk (Archbishop) on Aug 16, 2013 at 20:54 UTC | |
|
Re: Parsing a long string
by atcroft (Abbot) on Aug 17, 2013 at 05:39 UTC |