Found another example that doesnt store the entire file in a variable
but reads it line by line like this,
open ( my $input_fh, "<", $input_file );
open ( my $output_fh, ">", $output_file );
foreach my $line ( <$input_fh> )
{
##########
i have to use regex here to first see if this line start with a HDR -
+correct?
then if it does i would do a substring to delete the first 50 and wr
+ite the
rest to the output file
else
write the entire line to output
similarly check if it starts with EDR and substring again
##########
}
close ( $input_fh );
close ( $output_fh );
I didnt quiet get your suggestion on using the line number and eof. The file
will have numerous records that has headers and footers.
Am I on the right track with the above approach?
Storing in a variable vs reading line by line. Is one way better than the other?
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.