in reply to Re: how to modify foreach
in thread how to modify foreach
Hello Hippo and many thanks for your help. here is what i have done : replace
##merge data after filtering sub singlefile { my ( $file,$out) = @_; #open file open(FILE, $file) or die ("error occured while opening file"); #create list from file my @save = <FILE>; close(FILE); #empty table rows which do not meet criteria foreach (@save){ $_ = "" unless ($_ =~ m/"ENABLED","OLTP",/ && $_ =~m/^GREP/ ); $_ = "" if ($_ =~m/SYSMAN/|| m/SYS/); chomp $_; } #open output file, add data, close open(FILE, ">>OLTP.txt") or die ("error occured while opening file + OLTP.txt"); foreach (@save){ print FILE $_."\n" if ($_); } close(FILE); }
by
##merge data after filtering sub singlefile { my ( $file,$out) = @_; #open file open(FILE, $file) or die ("error occured while opening file"); #create list from file my @save = <FILE>; close(FILE); #empty table rows which do not meet criteria my $keep = ''; foreach (@save){ $_ = "" unless ($_ =~ m/"ENABLED","OLTP",/ && $_ =~m/^GREP +/ ); $_ = "" if ($_ =~m/SYSMAN/|| m/SYS/); if ($_) { $keep = $_; last; } } open(FILE, ">>OLTP.txt") or die ("error occured while opening +file OLTP.txt"); print FILE $keep if $keep; close(FILE); }
and the result is that i got only a file with only the header "User script,Serveur Name,Instance Name,Date of script,Serveur Name2,Instance.... and nothing else. if you want to give me a mail, i can send you some data to check. thank again OliverR
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: how to modify foreach
by poj (Abbot) on Jun 08, 2018 at 11:35 UTC | |
by Anonymous Monk on Jun 08, 2018 at 12:40 UTC | |
|
Re^3: how to modify foreach
by hippo (Archbishop) on Jun 08, 2018 at 09:34 UTC | |
by OliverR (Initiate) on Jun 08, 2018 at 09:58 UTC | |
by hippo (Archbishop) on Jun 08, 2018 at 11:00 UTC |