Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^4: Parsing a file to print multiple times

by ExperimentsWithPerl (Acolyte)
on Sep 26, 2015 at 10:21 UTC ( [id://1143086]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Parsing a file to print multiple times
in thread Parsing a file to print multiple times

Thanks a lot Anonymous Monk.You rock!!!
This logic worked.Below is the final code :-

open (FILE, '<', 'sample.txt') or die "Could not open sample.txt: +$!"; open (FILE1, ">output1.txt") or die "Could not open sample.txt: $! +"; my @nums = <FILE>; my $start = "print from"; my $go = 0; my $sizeconf = scalar @nums; for my $num ( @nums ){ if ($num =~ /$start/) { $go = 1; } if($go){ print FILE1 "$num"; } my $end = "closing"; if ($num =~ /$end/ && $num !~ /$start/) { $go = 0; } }


The last point of "$num =~ /$end/ && $num !~ /$start/" because in my actual input file $start conatins the staring $end.

I will intergrate this logic with my tool and update you.

Replies are listed 'Best First'.
Re^5: Parsing a file to print multiple times
by ExperimentsWithPerl (Acolyte) on Sep 29, 2015 at 11:31 UTC

    Yes..this works fine when integrated.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-23 21:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found