Re: RFC: Self Assessment Perl
by Your Mother (Archbishop) on Sep 05, 2018 at 19:09 UTC
|
That’s a wonderful list that neatly condenses down many things that took me a couple of years to learn. One gotcha I might suggest, probably as an adjunct to something existing or perhaps as a part of “Passing arguments.”
moo@cow[49]~>perl -le 'print ( 1 + 2 ) / 2'
3
Oh, and command line switches would be extremely valuable. Say what you want about Perl v Python v Ruby v Go v Scala, et cetera, but Perl on the command line is a game changer for anyone willing to take it up.
| [reply] [d/l] |
|
> That’s a wonderful list that neatly condenses down many things that took me a couple of years to learn.
Thanks, I somehow wanted to nail down mental coordinates of the "Perl hyper space". But just dropping words wouldn't help because most people would just assume something and nod.
But asking a question puts them under stress and motivates them to rethink and gives an incentive to do some research.
And at least I can point to that list next time people "try to misunderstand" me in meetings... ;-D
> print ( 1 + 2 ) / 2
I could add this to "precedence"
> command line switches
Unfortunately it's a very stubborn windows context here at $job$, i.e. really working with a shell/cmd is out of scope for most of our team ...
I know the list is incomplete ...
( actually I was sure I also mentioned autovivification, but somehow this extended list got lost ) ...
| [reply] [d/l] |
Re: RFC: Self Assessment Perl -- special variables
by Discipulus (Canon) on Sep 05, 2018 at 21:02 UTC
|
Hello LanX
the list is nice, but I have some note.
I will add, at the end:
Then, at least for me, an example looks too much edge case, or due to familiarity with other languages (desease I'm immune to, but can be useful for others having other experience): $h = {%h} personally I never seen used this way and I'd stress the standard form to take reference as in \%h and ( UPDATE after a glass of beer I now see the sense of the question about anonymous datastructure and a reference).Here i'll ask also about \(a..z) syntax.
There is nothing about regexes:you can at least ask how to make regexes more readable.
Core modules are important to know: they would deserve a long section with many named, but at least you can ask:
> So, do you know Perl?
So and so, but I know where to read and where to ask!
L*
UPDATE
> Unfortunately it's a very stubborn windows context..
I know this, but you can tempt them: This happened 5000 seconds ago, ie? perl -e "print scalar localtime (time - 5000)" or with mass editing or with -lne
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
| [reply] [d/l] [select] |
|
$h = {%h} personally I never seen used this way and I'd stress the standard form to take reference as in \%h They do different things; as the {%h} will get you a reference to a shallow copy of the hash, not just a reference to the original.
>perl -e "my %h = (1,2); my $g = {%h}; $g->{1}=3; print $h{1} . ' vs '
+ . $g->{1};"
2 vs 3
I see you've spotted that in the update tho. | [reply] [d/l] |
|
> Special variables
Almost all special variables are very edge case. They can look them up, provided they understand perldoc.
I was concentrating on essential concepts which are misunderstood or ignored, like "flattening".
This is not meant to be a tutorial *, people should rather realize where the gaps in their knowledge are.
You can't explain things to people who don't really listen because they think they know it already.
> regex ... map/grep/sort
my colleagues are capable to write millions of LOC without any regex° or map/grep/sort
This should probably be on a secondary list, I didn't want to risk that they depreciate the fist list. (hope you know what I mean)
> $h = {%h} personally I never seen used this way and I'd stress the standard form to take reference as in \%h
Seems like someone misunderstood flattening.... ;-P
*) though it could link into a tutorial or training.
°) well they sometimes use "cargo cult" regexes, i.e. C&P without understanding.
update
That's very a good idea
- Core modules
Name some standard modules/pragmas you use and explain what for.
they are confronted with CORE, the concept of module installation and can interact with each other.
| [reply] |
Re: RFC: Self Assessment Perl
by Eily (Monsignor) on Sep 06, 2018 at 13:40 UTC
|
I also think this list is really nice, with its wide variety of aspects of perl tricks and specificities :). Indicating how critical each piece of knowledge is might be useful though? Mastering context isn't required but knowing the basics can help a lot. You can get quite good with perl without having to understand BEGIN or even the notion of compile/run time, so I was kind of surprised that this was the first question.
Where can I look this up?
Best question. Knowing what kind of information you can get out of the doc, like perlop (like operator precedence, but also all the stuff on the quote like operators), perlvar (like knowing that sometimes you change the behaviour of a function by changing a var, rather than with the parameters) should be high on the list of required knowledge.
Booleans:
There are more than four? Actually this made me realize that I didn't know the answer to that correctly, I thought that any string that "looks like a number" and is equal to 0 was false. But:
perl -E "say for grep { $_ } qw<0 00 0.0>"
00
0.0
This means that the four FALSE I can think of are "", 0, "0" and undef. I suppose the empty list might count? (Edit: actually there are two numbers that are false, int 0 and real 0.0, so I guess that's up to 6 false values?)
Also I'm not sure about the other question, is this about how perl tests truth internally, or are you expecting an answer like !!(FalseOrWrong)? | [reply] [d/l] [select] |
|
> Indicating how critical each piece of knowledge is might be useful though?
as I said I didn't prioritize, and things are too interconnected.
like {%h} is not only a ref to an anonymous hash but the %h is flattened inside the { LIST } operation.
> You can get quite good with perl without having to understand BEGIN or even the notion of compile/run time, so I was kind of surprised that this was the first question.
My colleagues have to understand modules, for that to understand they need compile-time and namespaces
(I'm sick of all the requires into main:: in our code...)
Variable declaration happens at compile-time, die'ing at run-time should be avoided , ... and so on.
> Where can I look this up? ... Best question.
yes but they also need a mental map of essential key words.
A condensed Perlglossary would be nice, probably more explicit and with less Larry injokes.
> Actually this made me realize that I didn't know the answer to that correctly
Mission accomplished! :)
| [reply] [d/l] [select] |
|
I think you don't need to understand BEGIN to understand modules at a certain level. I think a useful lie is that use is just like require+->import(), and to postpone the discussion of BEGIN.
You can always gloss over that by saying that use must appear at the top of any code.
| [reply] [d/l] [select] |
|
|
| [reply] |
|
Re: RFC: Self Assessment Perl
by davido (Cardinal) on Sep 06, 2018 at 17:03 UTC
|
Definedness: Explain the difference between false and undefined. Show how to test for each.
Hashes: Show how to test for the existence of a hash key.
Autovivification: Show how to fetch the value in $foo->{'bar'}->{'baz'} without causing $foo->{'bar'} to spring into existence if it didn't exist to begin with.
Sorting: Show how to sort "foo123", "bar123", "baz345", "baz123" numerically first, alphabetically second.
List manipulation: Show how to find how many times the number 5 exists in map {int(rand(6)+1)} 1..20.
| [reply] [d/l] [select] |
|
Nice :)
Interview questions?
| [reply] |
Re: RFC: Self Assessment Perl
by eyepopslikeamosquito (Archbishop) on Sep 07, 2018 at 07:33 UTC
|
See On Interviewing and Interview Questions for how I have gone about interviewing over the years.
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.
References Added Later
| [reply] [d/l] [select] |
Re: RFC: Self Assessment Perl
by zentara (Archbishop) on Sep 06, 2018 at 11:52 UTC
|
This would also be a great Perl Job Interview question set.
As far as self-assesment goes, I would fail unless it was an open-book or with-laptop test. :-)
| [reply] |
|
> This would also be a great Perl Job Interview question set.
Unfortunately, I don't want people to learn answers by heart.
I once had an Skype interview with "teleprompter" interviewers
who had no idea what they where reading and what to expect ...
> I would fail unless it was an open-book or with-laptop test. :-)
The idea is to give orientation and an incentive to open a book...
update
But from a certain perspective you are right. I'm somehow interviewing my colleagues ...
| [reply] |
|
Yes teacher..........I see your point completely. :-) How's that for politeness?
| [reply] |
|
|
|