in reply to Segregation with Perl

It's good that you've provided an example input data file, but I don't understand what you would want to see in the two output files to be produced from this input. I also don't understand what the process of "page validation" is. Can you please supply more info?

BTW: The example data seems rather messy. E.g., there is no "Beginning Value" for the account number 222-222222 "Educational" "Account Type/Name": what, if any, value should appear in the output for the beginning value? Perhaps also see How do I post a question effectively? and I know what I mean. Why don't you?


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: Segregate data based on Page number and account combination
by Johndow (Novice) on Nov 14, 2018 at 22:42 UTC
    Thanks for your reply below are the two expected output files. The page validation should work for a Account Number as for example in Output 2 for account number 222-222222 there are three pages of statements which collectively needs to be printed and since Output 1 has only 1 page for a unique account so only that data is printed.I have corrected the data as well please have a look now. Thanks for your help
    Output 1:
    Page 1 of 1 Page 1 of 1 Account Unique_Number Description GENERAL 111-111111 This is the first line I am learning perl
    output 2:
    Page 1 of 3 Account Unique_Number Description PERSONAL 222-222222 This is the first line I am learning perl Page 2 of 3 Account Unique_Number Description Educational 222-222222 This is the second line I am learning perl Page 3 of 3 Account Unique Number Description Educational 222-222222 This is the third line I am learning perl
    Expected Output in File 1:
    Page 1 of 1 Account Unique_Number Description GENERAL 111-111111 This is the first line I am learning perl
    Expected Output in File 2:
    Page 1 of 3 Account Unique_Number Description PERSONAL 222-222222 This is the first line I am learning perl Page 2 of 3 Account Unique_Number Description Educational 222-222222 This is the second line I am learning perl Page 3 of 3 Account Unique Number Description Educational 222-222222 This is the third line I am learning perl

      Open a new file at each Page 1 line.

      #!/usr/bin/perl use strict; my $fileno = 0; my $fh; while (<DATA>){ if (/^ *Page 1/){ close $fh if $fileno; ++$fileno; print "Opening file $fileno\n"; open $fh,'>',"$fileno.txt" or die "Could not open $fileno.txt"; } print $fh $_; } close $fh; __DATA__ Page 1 of 1 Account Account_Number Beginning_Value GENERAL 111-111111 $88,0853.95 Page 1 of 3 Account Account_Number Beginning Value PERSONAL 222-222222 $88,0853.95 Page 2 of 3 Account Account_Number Beginning Value Educational 222-222222 Page 3 of 3 Account Account Number Beginning Value Educational 222-222222
      poj
        Thanks for your inputs monks, but still I am unable to reach to a concrete solution. I have modified the data in the question for better clarity and urgently seek your wisdom here. This is giving me tough time, please share your thoughts on this. Thanks