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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.