Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Have you netted a Perl Monk or Perl Pretender in 5 minutes or less?

by benrwebb (Scribe)
on Sep 14, 2005 at 19:29 UTC ( #491982=note: print w/replies, xml ) Need Help??


in reply to Have you netted a Perl Monk or Perl Pretender in 5 minutes or less?

There are three lines of code I always ask people to gauge their Perl skills. I write them down on a white board and ask what they do.

my $c = 1 unless $c;
to see if they understand Perlish shorthand and
my $foo = @bar; my ($phoo) = @bar;

I ask them the difference, and what would actually be assigned to $foo and $phoo. This tells me if they understand the concept of "context". I also ask about the "my" and what it actually means. This, IMHO, covers most of what makes Perl different from other languages, and seems to weed out the pretenders.

update
Ok, I screwed this up. my first line of code doesn't acutually work. I pulled something out of context that works in my mind but not in practice. That should have been this: $c = 1 unless $c; putting the 'my' on there would actually re-declare the variable and set it to undef if it resolved to 'true'. Of course, with this line of code the variable must be pre-declared (I use this when testing web params - the variable defaults to undef if it wasn't filled in by the user, so I get code like $name = 'unknown' unless $name)

Replies are listed 'Best First'.
Re^2: Have you netted a Perl Monk or Perl Pretender in 5 minutes or less?
by Anonymous Monk on Sep 14, 2005 at 20:12 UTC
    Okay, I'm curious, why is that useful and/or not a trick question?
    $c = 2; print "Before: c=$c\n"; my $c = 1 unless $c; print "After: c=$c\n";
    That prints out...
    Before: c=2 After: c=
    ...on my machine (perl5.8.6).
      That prints out:
      Global symbol "$c" requires explicit package name at programname.pl li +ne 5. Global symbol "$c" requires explicit package name at programname.pl li +ne 6. Global symbol "$c" requires explicit package name at programname.pl li +ne 7. Execution of programname.pl aborted due to compilation errors.
      Oh... you didn't use strict :)

      "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
        Um. This is really a serious question. Is there something useful that example accomplishes, or is it just trying to point out a Perl anonomly (some might call it broken behavior)?
        #!/usr/bin/perl -w use strict; our $c = 2; print "Before: c=$c\n"; my $c = 1 unless $c; print "After: c=$c\n";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2020-01-23 16:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?