DespacitoPerl has asked for the wisdom of the Perl Monks concerning the following question:
Hi, currently i am developing a script for the input file, the contents are like this:
abcd1234 1002 abcd1235 9920 abcd1236 8272 abf123 262 abf124 8172 ach37 888 ach38 990but in the waiver file, the contents are like this:
abc* 250 ac* 750in the waiver file, the *sign is the input, so my perl script must able to read this symbol, and come out with grepping the remaining all characters behind if the strings before is matched. So, whatever inside the waiver file, the output should be change to value in waiver file
abcd1234 250 abcd1235 250 abcd1236 250 abf123 262 abf124 8172 ach37 750 ach38 750Anyone has any ideas? Since the symbol * is in the input file, not as always in perl script which the computer itself can understand, so how i can write the script to get the results? I am still new to perl
Update:
Hi, currently i am developing a script for the input file, the contents are like this:
func c4_2060/bump 250.00 2000.00 -1750.00 ( +VIOLATED) func c4_2061/bump 250.00 2000.00 -1750.00 ( +VIOLATED) func c4_2062/bump 250.00 2000.00 -1750.00 ( +VIOLATED) func c4_2063/bump 250.00 2000.00 -1750.00 ( +VIOLATED) func c4_2064/bump 250.00 2000.00 -1750.00 ( +VIOLATED) func c4_2065/bump 250.00 2000.00 -1750.00 ( +VIOLATED) and so on..
but in the waiver file, the contents are like this:
c4_2*/bump,250.00,2000.00,"Justification","Waived,by","Waived,Date","A +pproved,by","Approved,date" c4_2070/bump,250.00,2500.00,"Justification","Waived,by","Waived,Date", +"Approved,by","Approved,date"
in the waiver file, the *sign is the input, so my perl script must able to read this symbol, and come out with grepping the remaining all characters behind if the strings before is matched. So, whatever inside the waiver file, the output should be change to value in waiver file
func c4emib_2060/bump 250.00 2000.00 -17 +50.00 (WAIVED) func c4emib_2061/bump 250.00 2000.00 -17 +50.00 (WAIVED) func c4emib_2062/bump 250.00 2000.00 -17 +50.00 (WAIVED) func c4emib_2063/bump 250.00 2000.00 -17 +50.00 (WAIVED) func c4emib_2064/bump 250.00 2000.00 -17 +50.00 (WAIVED) func c4emib_2065/bump 250.00 2000.00 -17 +50.00 (WAIVED) func c4emib_2066/bump 175.00 2000.00 -18 +25.00 (WAIVED) func c4emib_2067/bump 250.00 2000.00 -17 +50.00 (WAIVED) func c4emib_2068/bump 250.00 2000.00 -17 +50.00 (WAIVED) func c4emib_2069/bump 250.00 2000.00 -17 +50.00 (WAIVED) func c4emib_2070/bump 250.00 2000.00 -17 +50.00 (WAIVED) func c4emib_2071/bump 250.00 2000.00 -17 +50.00 (WAIVED) func c4emib_2072/bump 250.00 2000.00 -17 +50.00 (VIOLATED) func c4emib_2073/bump 250.00 2000.00 -17 +50.00 (VIOLATED) func c4emib_2074/bump 250.00 2000.00 -17 +50.00 (VIOLATED) func c4emib_2075/bump 250.00 2000.00 -17 +50.00 (VIOLATED)
my code is like this
#! /tools/perl/5.8.8/linux/bin/perl use strict; use warnings; use Data::Dumper; # Source script my $report = $ARGV[1] ; my $waiver = $ARGV[3] ; my $result = $ARGV[5] ; # Set up a hash to receive the information my %identifier = (); # Read the violations file into the hash open my $filter, '<', $waiver or die; while (my $vline = <$filter>) { next unless $vline =~ /\S/; #skip blank lines my ($pins2, $threshold2, $newthreshold2) = split /,/, $vline; #$pins2 =~ s/\*/.*/g; $identifier{$pins2}{'threshold2'} = $threshold2; $identifier{$pins2}{'newthreshold2'} = $newthreshold2; } print Dumper \%identifier; # Read input file line by line and compare 2 files open my $input, '<', $report or die; open my $output, ">", $result or die; while (my $wline = <$input>){ my ($scenario, $pins1, $threshold1, $newthreshold1, $diff, $status +) = split /\s+/, $wline; # overwrite values if match if (exists $identifier{$pins1}) { if ( ($threshold1 == $identifier{$pins1}{'threshold2'}) && ($newth +reshold1 <= $identifier{$pins1}{'newthreshold2'}) ) { $status = '(WAIVED)'; } } printf $output "%-44s %-24s %-8s %-8s %-8s %-10 +s\n", $scenario, $pins1, $threshold1, $newthreshold1, + $diff, $status; } close $filter; close $input; close $output;
Anyone has any ideas? Since the symbol * is in the input file, not as always in perl script which the computer itself can understand, so how i can write the script to get the results? I am still new to perl
2017-07-26 Athanasius restored original content
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Grep asterisk sign in input file
by choroba (Cardinal) on Jul 25, 2017 at 06:50 UTC | |
by Athanasius (Archbishop) on Jul 25, 2017 at 07:18 UTC | |
|
Wildcard in a hash
by DespacitoPerl (Acolyte) on Jul 27, 2017 at 02:51 UTC | |
by shmem (Chancellor) on Jul 27, 2017 at 06:49 UTC | |
by tybalt89 (Monsignor) on Jul 27, 2017 at 15:09 UTC | |
by poj (Abbot) on Jul 27, 2017 at 06:14 UTC | |
by DespacitoPerl (Acolyte) on Jul 27, 2017 at 07:00 UTC | |
by Anonymous Monk on Jul 27, 2017 at 02:56 UTC | |
by DespacitoPerl (Acolyte) on Jul 27, 2017 at 03:21 UTC | |
by Anonymous Monk on Jul 27, 2017 at 03:51 UTC | |
by DespacitoPerl (Acolyte) on Jul 27, 2017 at 04:57 UTC | |
| |
by Anonymous Monk on Jul 27, 2017 at 14:19 UTC | |
by choroba (Cardinal) on Jul 27, 2017 at 14:39 UTC | |
by DespacitoPerl (Acolyte) on Aug 15, 2017 at 08:10 UTC | |
by shmem (Chancellor) on Aug 15, 2017 at 09:19 UTC | |
by DespacitoPerl (Acolyte) on Aug 16, 2017 at 02:25 UTC | |
|