Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about file formating

Status
Not open for further replies.

user2base

Technical User
Oct 16, 2002
29
0
0
GB
I have a file that looks like this:
blabla
!
!
!
bla bla
!
bla
blablabla
!
!

etc...

How to remove all the ! in a series but one so that the result looks like:

blabla
!
bla bla
!
bla
blablabla
!
 
whats you data output when you make the file?
 
You can set a 'seen' flag if a line contains a '!' and then skip any other lines after that which contain a '!'.
A simple example:
Code:
my $seen = 0;

while (<DATA>) {

    next if $seen and /^!$/;
    $seen = /^!$/ ? 1 : 0;
    print;
}
jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top