Hi Monks

I have a csv file and i need to parse those data as well as write into separate file with type filter

input_parse_and_output("Bill"); input_parse_and_output("Bond"); input_parse_and_output("Note"); # Subroutine has two arguments 1.Input file name 2. Output file direct +ory 3. Output file name all of these are scalar sub input_parse_and_output{ foreach my $input_data_each_line(@input_data_in_array){ chomp($input_data_each_line); # if the current line not contatin cusip then program will move to ne +xt line next unless $input_data_each_line=~ /cusip/; next unless $input_data_each_line=~ /"securityType":"$_[0]"/; if(defined $input_data_each_line){ foreach my $output_header_names_temp(@output_header_names){ chomp($output_header_names_temp); if(defined $output_header_names_temp){ # regex to replace the double quotes to blank string #input_data_each_line=~ s/"//g; $input_data_each_line=~ /$output_header_names_temp:([\w\d\-\$\%\:\!\ +@\&\*\.]+)/; if(defined $1){ my $temp=$1; if($temp=~ /\:/){ # regex for get exact first ten charavtetr it can be digit or hyph +en $temp=~ /^([\d\-]{10})/; print OUTPUT_FILE_WRITE "$1\t"; } else { print OUTPUT_FILE_WRITE "$1\t"; } } else { print OUTPUT_FILE_WRITE "NULL\t"; } } } print OUTPUT_FILE_WRITE "\n"; } } }

In this above code @input_data_in_array contain 100 lines so the subroutine call itself by 3 times for sorting by order "Bill","Bond","Note"

The given input file data sample as below

912828Q86 Note 1-Year 2016-05-25 2016-05-27 2018-0 +4-30 100.003850 NULL 912796HD4 Bill 4-Week 2016-01-26 2016-01-28 2016-0 +2-25 99.977056 NULL 912810RS9 Bond 30-Year 2016-05-12 2016-05-16 2046-0 +5-15 97.619462 2.500000 912810RQ3 Bond 29-Year 2016-04-14 2016-04-15 2046-0 +2-15 98.011430 2.500000 912796HD4 Bill 4-Week 2016-01-26 2016-01-28 2016-0 +2-25 99.977056 NULL 912828N71 Note 9-Year 2016-05-19 2016-05-31 2026-0 +1-15 103.533587 0.625000

In this program the array of content is read 3 times so it taken more time to complete , I need it to done with in 1 time reading and filter by "Bill","Bond","Note"

Expected output

912796HD4 Bill 4-Week 2016-01-26 2016-01-28 2016-0 +2-25 99.977056 NULL 912796HD4 Bill 4-Week 2016-01-26 2016-01-28 2016-0 +2-25 99.977056 NULL 912810RS9 Bond 30-Year 2016-05-12 2016-05-16 2046-0 +5-15 97.619462 2.500000 912810RQ3 Bond 29-Year 2016-04-14 2016-04-15 2046-0 +2-15 98.011430 2.500000 912828Q86 Note 1-Year 2016-05-25 2016-05-27 2018-0 +4-30 100.003850 NULL 912828N71 Note 9-Year 2016-05-19 2016-05-31 2026-0 +1-15 103.533587 0.625000

Your Suggestion is mostly appreciated...


In reply to File content sorting based on type by perlmad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.