in reply to Search for a BLOCK of text and selectively replace
That will at least answer your first question.#!/bin/perl -w use strict; open (DATA, "text.txt") || die "Can't access test\n"; #each element in the array is a single line my @data = <DATA>; close(DATA); #vars to manipulate the data my $line=""; my @description = (""); my $found = "false"; #while it is not the end of the file while($line = shift @data){ chomp $line; if($line =~ "DESCRIPTION"){ $line = shift @data; chomp $line; while(!($line =~ "END")){ if(!($line =~ ";")){ push @description, $line; } $line = shift(@data); chomp $line; } print "[",@description, "]\n"; #if there's going to be more descriptions in the same file #then we can clear the array and keep going through the #file until we run out of lines. Otherwise @description #will continue to accumulate strings #@description = (""); } } if($found eq "false"){ #then we didn't find a description #add it here }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re(2): Search for a BLOCK of text and selectively replace
by dmmiller2k (Chaplain) on Mar 22, 2002 at 07:07 UTC | |
|
Re: Re: Search for a BLOCK of text and selectively replace
by Rhodium (Scribe) on Mar 22, 2002 at 14:30 UTC |