I had applied for a job and for the 'technical' phone screen interview, I was given two scripting tasks - one of which was the following:
################## #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

In reply to same script, different results by jb60606

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.