Hello there Monks!
I have this long string over 1000000 chars, to try to explain what I am trying to do I have a sample code that I am parsing to get some values from it, I just can’t get it to work to print the values I am looking for. If someone would have the patience to look at this code and let me know what could be done better to make it print the right information from the inner IFs it will be very appreciated:
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
Thanks for looking!