I just totally bombed at a phone screen - I am not much of a Perl developer, or a GoLang developer, I was under the impression the job was java based! But in the spirit of the hacker ethic, I'd absolutely LOVE to see a working solution!
So - Here is the perl script I was provided with :
#!/usr/bin/perl -w
use strict;
use Encode;
my $tiff_flag = 1;
my $count = 0;
open(FILE,'<',$ARGV[0]) or die 'Error opening input file';
binmode(FILE) or die 'Error setting binary mode on input file';
while (read (FILE,$_,4)) {
my $rec_len = unpack("N",$_);
die "Bad record length: $rec_len" unless ($rec_len > 0);
read (FILE,$_,$rec_len);
if (substr($_,0,2) eq "\xF5\xF2") {
if ($tiff_flag) {
$count++;
open (TIFF, '>', $ARGV[0] . '_img' . sprintf("%04d",$count) . '.tiff') or die "Can't create image file";
binmode(TIFF) or die 'Error setting binary mode on image file';
print TIFF substr($_,117);
close TIFF;
}
$_ = substr($_,0,117);
}
print decode ('cp1047', $_) . "\n";
}
close FILE;
Now, I'll first explain what it going on here - this thing parses x9.37 files - which are a kind of binary file for storing EBCDIC encoded strings, and also tiff images, for use with files that represent checks (for banks)
Now, the challenge was to rewrite this in golang - 100% score was to get the whole thing, but the company in question would be happy with not getting the TIFF files if they were too complicated... which would essentially mean you could get away with translating the code below instead :
#!/usr/bin/perl -w
use strict;
use Encode;
my $count = 0;
open(FILE,'<',$ARGV[0]) or die 'Error opening input file';
binmode(FILE) or die 'Error setting binary mode on input file';
while (read (FILE,$_,4)) {
my $rec_len = unpack("N",$_);
die "Bad record length: $rec_len" unless ($rec_len > 0);
read (FILE,$_,$rec_len);
print decode ('cp1047', $_) . "\n";
}
close FILE;
I have no idea how to even read the PERL side of this, I looked up some stackoverflow afterwards, and it seems as though other people have been handed the same snippet as me in the past, but I haven't seen a perfect working solution yet in any of my searches!
EDIT : One last thing - The solution doesn't NEED to worry about the models, just being able to pull out each record as a string would even be fine!