jb60606 has asked for the wisdom of the Perl Monks concerning the following question:
################## #TASK DESCRIPTION# ##################
Write a Perl script to find out which symbols in FILE_A are not contained in fileB for groupA and exchanges B and C.
################## #FILE_A (sym.txt)# ##################
A AA ABC ADF BFD EFF ZFF ZZD
################### #FILE_B (data.txt)# ###################
exchangeA_groupA.gateway_risk=A 10 10 AA 10 10 ABC 10 10 ADF 10 10 EFF + 10 10 MMM 10 10 NDB 10 10 RFD 10 10 ZFF 10 10 exchangeA_groupB.gateway_risk=A 10 10 AA 10 10 ABC 10 10 EFF 10 10 MMM + 10 10 NDB 10 10 RFD 10 10 ZFF 10 10 exchangeA_groupC.gateway_risk=A 10 10 AA 10 10 ABC 10 10 EFF 10 10 MMM + 10 10 NDB 10 10 RFD 10 10 ZFF 10 10 exchangeB_groupA.gateway_risk=A 10 10 AA 10 10 ABC 10 10 EFF 10 10 MMM + 10 10 NDB 10 10 RFD 10 10 ZFF 10 10 exchangeB_groupB.gateway_risk=A 10 10 AA 10 10 ABC 10 10 EFF 10 10 MMM + 10 10 NDB 10 10 RFD 10 10 ZFF 10 10 exchangeB_groupC.gateway_risk=A 10 10 AA 10 10 ABC 10 10 EFF 10 10 MMM + 10 10 NDB 10 10 RFD 10 10 ZFF 10 10 exchangeC_groupA.gateway_risk=A 10 10 AA 10 10 ABC 10 10 EFF 10 10 MMM + 10 10 NDB 10 10 RFD 10 10 ZFF 10 10 ZZD 10 10 exchangeC_groupB.gateway_risk=A 10 10 AA 10 10 ABC 10 10 EFF 10 10 MMM + 10 10 NDB 10 10 RFD 10 10 ZFF 10 10 exchangeC_groupC.gateway_risk=A 10 10 AA 10 10 ABC 10 10 EFF 10 10 MMM + 10 10 NDB 10 10 RFD 10 10 ZFF 10 10 exchangeD_groupA.gateway_risk=A 10 10 AA 10 10 ABC 10 10 EFF 10 10 MMM + 10 10 RFD 10 10 ZFF 10 10 exchangeD_groupB.gateway_risk=A 10 10 AA 10 10 ABC 10 10 EFF 10 10 MMM + 10 10 NDB 10 10 RFD 10 10 ZFF 10 10 exchangeD_groupC.gateway_risk=A 10 10 AA 10 10 ABC 10 10 EFF 10 10 MMM + 10 10 NDB 10 10 RFD 10 10 ZFF 10 10
########### #MY SCRIPT# ###########
#use warnings; use strict; #use feature qw(switch say); my $symbols = "sym.txt"; my $data = "data.txt"; open (SYM, $symbols) or die ("$symbols not found"); while (my $symbol = <SYM>) { my $lineNum = 0; chomp $symbol; open (DATA, $data) or die ("$data not found"); while (my $line=<DATA>) { $lineNum++; chomp $line; my @array = split ( /[\." "]/, $line ); my $sym1 = $array[4]; my $sym2 = $array[7]; my $sym3 = $array[10]; my $sym4 = $array[13]; my $sym5 = $array[16]; my $sym6 = $array[19]; my $sym7 = $array[22]; my $sym8 = $array[25]; if (( $array[0] =~ m/^exchangeB_groupA$/ ) || ( $array[0] =~ m +/^exchangeC_groupA$/ )) { if ($symbol eq $sym1) { next; } elsif ($symbol eq $sym2) { next; } elsif ($symbol eq $sym3) { next; } elsif ($symbol eq $sym5) { next; } elsif ($symbol eq $sym5) { next; } elsif ($symbol eq $sym6) { next; } elsif ($symbol eq $sym7) { next; } elsif ($symbol eq $sym8) { next; } else { print "$symbol\t$array[0](ln$lineNum)\tnot found\n" } } } }
############ #MY RESULTS# ############
A exchangeB_groupA(ln4) not found A exchangeC_groupA(ln7) not found ADF exchangeB_groupA(ln4) not found ADF exchangeC_groupA(ln7) not found BFD exchangeB_groupA(ln4) not found BFD exchangeC_groupA(ln7) not found ZZD exchangeB_groupA(ln4) not found
If you manually sift through the data, you'll see that the results I get are correct. However, when he ran my script, he said that he received ALL symbols back (meaning - every symbol in FILE_A were reported missing).
I was not near a computer with Perl on it and could not troubleshoot the issue 'live' during the interview. Upon being near a computer again, I began to troubleshoot the issue and I get the same (correct)results in Macintosh/FreeBSD (where it was written) as I do in Ubuntu Linux (ubuntu 3.11.0-12-generic). The only way that I could make the script fail and achieve the same results as he was by altering each of the $sym[x] declarations in my script, to match up with the wrong $array[element].
I know that my script may not be the most efficient way to perform the task, but I thought that the code was inteligible and "fool-proof". I packaged the script I sent to him with the same symbol file and data file that I used, so that we could mimic running the script in virtually the same environment and there would be no formatting issues.
Sorry for the long setup, but with all of that being said, can you think of any reason why this script wouldn't work and why it would give the results that he received?
Thanks
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: same script, different results
by Athanasius (Archbishop) on Oct 25, 2013 at 12:38 UTC | |
by jb60606 (Acolyte) on Oct 25, 2013 at 13:42 UTC | |
Re: same script, different results
by Lennotoecom (Pilgrim) on Oct 25, 2013 at 11:57 UTC | |
by jb60606 (Acolyte) on Oct 25, 2013 at 12:25 UTC | |
Re: same script, different results
by Dallaylaen (Chaplain) on Oct 25, 2013 at 15:07 UTC | |
Re: same script, different results
by Lennotoecom (Pilgrim) on Oct 25, 2013 at 12:33 UTC |