Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Parsing file to pull out sections of text

by artist (Parson)
on Feb 03, 2009 at 20:46 UTC ( #741121=note: print w/replies, xml ) Need Help??


in reply to Parsing file to pull out sections of text

use strict; use warnings; my $flag = 0; my $start = 'd1'; my $end = 'd4'; my @array; while (<DATA>) { chomp; if(/$start/){ $flag = 1; @array = (); } elsif(/$end/) { $flag = 0; print "@array\n"; } else{ push @array, $_ if $flag; } }
--Artist

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://741121]
help
Chatterbox?
[james28909]: how can i write a while loop on one line (in a script) something like print "this\n" && print "that" && <DATA> && print the other\n" && next if /this matches/ while <DATA>?

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2018-05-20 18:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?