Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^2: header footer

by gupr1980 (Acolyte)
on Mar 04, 2014 at 22:22 UTC ( #1076986=note: print w/replies, xml ) Need Help??

in reply to Re: header footer
in thread header footer

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?

Replies are listed 'Best First'.
Re^3: header footer
by Eily (Monsignor) on Mar 04, 2014 at 23:01 UTC

    Yeah, I just missed the multiple records in the same file. Mea culpa

    Then you can do something like:

    %length = (HDR => 5, FTR => 10); while(<DATA>) { while(/(HDR|FTR)/) # find either HDR or FTR { substr($_, $-[1], $length{$1}) = ''; # $-[1] is the position of +the first capture groups (parenthesis) } print; } __DATA__ HDR--Hello this is a test FTR-------Should there be text here? HDR--Tw +o records on the same line FTR------- HDR--and here an incomplete footer FTR--

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1076986]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2023-01-29 02:07 GMT
Find Nodes?
    Voting Booth?

    No recent polls found