in reply to Re: Segregate data based on Page number and account combination
in thread Segregation with Perl

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

Replies are listed 'Best First'.
Re^3: Segregate data based on Page number and account combination
by poj (Abbot) on Nov 15, 2018 at 08:08 UTC

    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
        I have modified the data in the question for better clarity

        In other words, you have moved the goalposts. Given the current poll we can see that the first answer applies: the spec was broken. Who knows if it is even correct now?

        See the section headed It is uncool to update a node in a way that renders replies confusing or meaningless in the FAQ How do I change/delete my post? for what you should have done.

        Once you've fixed that, consider a careful read through How to ask better questions using Test::More and sample data. If you can provide an SSCCE then maybe further help will be forthcoming.

        ... I am unable to reach to a concrete solution.

        poj seems to have given a very concrete solution here. In what specific way or ways does this solution not meet your needs? Just saying "it doesn't work" is not helpful or encouraging to any monk who is inclined to help you.


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