in reply to Re^2: Segregate data based on Page number and account combination
in thread Segregation with 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

Replies are listed 'Best First'.
Re^4: Segregate data based on Page number and account combination
by Johndow (Novice) on Nov 17, 2018 at 01:29 UTC
    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:  <%-{-{-{-<