Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: RFC: Self Assessment Perl

by eyepopslikeamosquito (Chancellor)
on Sep 07, 2018 at 07:33 UTC ( #1221906=note: print w/replies, xml ) Need Help??


in reply to RFC: Self Assessment Perl

See On Interviewing and Interview Questions for how I used to go about interviewing.

Further to that, I've dug out some old Perl interview questions I used to assess candidates who said they "knew" Perl (to keep them honest). That is, these questions are not difficult for a Perl expert.

  • What is the CPAN?
  • What does use strict; mean?
  • What is the difference between $x eq $y and $x == $y?
  • What is the definition of "false" in Perl?
  • Generally, when should you use 'foreach' versus 'map' versus 'grep'?
  • What is the difference between use File::Find and use File::Find () and require File::Find?
  • What is the difference between 'my', 'local' and 'our'?
  • In a regex, how do you do non-capturing parens?
  • In a regex, what's the difference between "greedy" and "non greedy"?
  • What is a regex assertion? Which ones have you used?

Given a list of numbers, namely:

my @oldlist = ( 4, 7, 8 );
write some code to add 42 to every item in this list, producing a new list. For this example data, newlist should contain the values: ( 46, 49, 50 ). Sample answer:

my @oldlist = ( 4, 7, 8 ); my @newlist = map($_ + 42, @oldlist);

Given a string containing a space-separated list of names:

my $names = "freddy fred bill jock kevin andrew kevin kevin jock";
write some code to produce a frequency table of names, sorted descending by frequency, then ascending by name. For this data, the output should be:
kevin : 3 jock : 2 andrew : 1 bill : 1 fred : 1 freddy : 1

Sample answer:

my $names = "freddy fred bill jock kevin andrew kevin kevin jock"; my %freq; for my $name (split ' ', $names) { ++$freq{$name}; } for my $k (sort { $freq{$b} <=> $freq{$a} || $a cmp $b } keys %fre +q) { printf "%-10s: %d\n", $k, $freq{$k}; }

Given an input text file and an output file as follows:

my $infile = 'in.tmp'; my $outfile = 'out.tmp';
write some code to read infile and change all occurrences of 'Peking' to 'Beijing', leaving infile unchanged and writing the changed text to a new file outfile. Sample answer:

my $infile = 'in.tmp'; my $outfile = 'out.tmp'; open(my $fhin, '<', $infile) or die "error: open '$infile': $!"; open(my $fhout, '>', $outfile) or die "error: open '$outfile': $!" +; while (my $line = <$fhin>) { $line =~ s/\bPeking\b/Beijing/g; print $fhout $line; } close($fhin); close($fhout);
If they use s/Peking/Beijing/g contrast with s/\bPeking\b/Beijing/g and ask which they prefer.

Updated: Added \b assertions to s/Peking/Beijing/ and extra questions around regex assertions. Thanks haukex.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2019-04-21 18:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I am most likely to install a new module from CPAN if:
















    Results (111 votes). Check out past polls.

    Notices?