Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: same script, different results

by Athanasius (Archbishop)
on Oct 25, 2013 at 12:38 UTC ( [id://1059641]=note: print w/replies, xml ) Need Help??


in reply to same script, different results

Hello jb60606,

When I run your code on my 32-bit Vista system:

This is perl 5, version 18, subversion 1 (v5.18.1) built for MSWin32-x +86-multi-thread-64int

I get the same results as you. Looking through the code, nothing leaps out as a potential trigger for different behaviour on a different system. (Did you ask the interviewer for details of the system on which he ran your code?) So I can’t help you there, sorry. But the following points should be noted:

  • Commenting-out use warnings; is a red flag. For lines with fewer than 26 fields, $array[25] is undefined, raising a warning on the equality test. One way to avoid the warning is to test for definedness first, and short-circuit if the value is undefined:

    ... next if defined $sym8 && $symbol eq $sym8; ...
  • As Lennotoecom has pointed out, your results do not take account of symbol A in the data file. This is because the character class used in the call to split doesn’t include =. Note also that within a character class, the dot does not need to be escaped, and enclosing the space in double quotes merely adds the " character to the class. You should use: my @array = split /[. =]/, $line;.

  • If the files get bigger, the inefficiency of opening and closing and reopening the data file for each symbol in the symbol file will quickly become prohibitive. I would read the symbols into a hash an array first, then open the data file once and process it line by line, testing each symbol against the current line before moving on to the next.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: same script, different results
by jb60606 (Acolyte) on Oct 25, 2013 at 13:42 UTC
    Hi folks, thanks for your expertise and advice. To answer some of your questions, I hadn't originally planned on writing it this way as I thought something like a hash of arrays would have been more appropriate. The problem was that a HoA is kind of uncharted territory for me, as I am still relatively new to this this or any language. Additionally, I only had the remainder of the day to put a script together and send it back to the interviewer. The interview was yesterday. I had hoped to figure out what went wrong and package an explanation with the thank-you letter today but seeing that you've discovered additional unforgivable problems, I might be better off leaving it alone. Besides, apart from the 2nd script being a success, I pretty much bombed the rest of the interview after learning that this script failed and highly doubt they consider me a competitive candidate.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1059641]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-24 02:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found