>-----Original Message----- >From: Chris Stinemetz [mailto:chrisstinem...@gmail.com] >Sent: Monday, February 20, 2012 13:51 >To: beginners@perl.org >Subject: Re: search and replace with an array > >Looks like I was able to figure it out with the below: > >But how do I remove all the blank lines? > >Output: > >cdmno=1 >rdnt_cdmno=1 > > > > > > > >cdmno=2 >rcsm=801 > > > > > > > >rcsm=801 > > > > > > > >rcsm=802 > >#!/usr/bin/perl >use warnings; >use strict; > >my $file = "nonKeys.txt"; >my $newFile = "cleanKeys.txt"; >my @keyFields = qw(rcsm cdmno); > >#open my $FH, '<', $file or die "ERROR opening $file: !"; >open my $FHOUT, '>', $newFile or die "ERROR opening $newFile: !"; > >while ( <DATA> ) { > chomp; > for my $i ( 0 .. $#keyFields ) { > $_ =~ s/$keyFields[$i]\d.*//; Make the print dependent upon NOT doing the change( you do not need to use $_ and =~ that is the default variable to use): If ( ! s/$keyFields[$i]\d.*// ) { # so if does not do the change, then you will print what is in $_ print "$_\n"; }
If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us > } >} >__DATA__ >cdmno=1 >rdnt_cdmno=1 >cdmno2=1 >cdmno3=1 >cdmno4=1 >cdmno5=1 >cdmno6=1 >cdmno7=1 >cdmno8=1 >cdmno=2 >rcsm=801 >rcsm2=801 >rcsm3=801 >rcsm4=801 >rcsm5=801 >rcsm6=801 >rcsm7=801 >rcsm8=801 >rcsm=801 >rcsm2=801 >rcsm3=801 >rcsm4=801 >rcsm5=801 >rcsm6=801 >rcsm7=801 >rcsm8=801 >rcsm=802 > >-- >To unsubscribe, e-mail: beginners-unsubscr...@perl.org >For additional commands, e-mail: beginners-h...@perl.org >http://learn.perl.org/ > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/