Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Homework question list

by displeaser (Hermit)
on May 20, 2005 at 18:30 UTC ( #459086=perlquestion: print w/ replies, xml ) Need Help??
displeaser has asked for the wisdom of the Perl Monks concerning the following question:

Hello fellow belivers of the Perl faith,

is there a list/node anyones aware of which list's homework questions? (not solutions, just questions)

I think it would be valuable for both teachers and people who want to learn more about perl. Theres oft times I wanted to learn something but nothing inspired me so homework questions for a little bit of practice may help me (and others of course) learn better.

Sometimes the questions posed are a little too much like work so smaller learning tasks may be better suited.
I've asked in CB but got no response and also used supersearch. There are obvious homework questions within the vaults of the Monestary but has anyone collected them and put them in one place?

If not, I will try but wanted to check I'm not duplicating work done by a worthier Monk.

displeaser

Comment on Homework question list
Re: Homework question list
by mrborisguy (Hermit) on May 20, 2005 at 19:50 UTC

    I think this is a good idea, too! Maybe not even just homework questions, but little scripts to write to hone a monk's skills would be good. Anyway, take a look at Should PM have a Puzzles Corner?, there's been some discussion on that thread concerning something somewhat like this.

    -Bryan

Re: Homework question list
by dynamo (Chaplain) on May 20, 2005 at 22:17 UTC
    Any fairly simple task or solution might be considered a homework question. You're looking for an archive, and we have one: Categorized Questions and Answers. Look there for the simpler looking stuff.
Re: Homework question list
by planetscape (Canon) on May 20, 2005 at 22:49 UTC

    Do you have access to programming books that deal with other languages? Those should have exercises that you can implement in Perl.

    The Monks are very discerning; many times they recognize homework questions. Sometimes SoPW has homework questions unabashedly posted as such. Try Super Search on "homework."

    Or Super Search for "Perl Golf." If the questions are too difficult, take a look at the answers, and reverse-engineer them so you understand why they do what they do.

    If all else fails, create (and solve) your own small challenges. Tackle just a section of those questions that seem like work.

    Good luck,

    planetscape

Re: Homework question list
by Zaxo (Archbishop) on May 20, 2005 at 23:53 UTC

    TIMTOWDI provides a class of Perl questions which I favor: "Show N ways to do X in Perl. Describe their different properties."

    For instance,

    Show three ways to remove trailing newlines from the elements of a Perl array. Which would you prefer, and why?
    Seekers of Perl Wisdom provides numerous cases which could be turned into this kind of question, complete with answers.

    This tests knowledge of perl, rather than programming speed or CS-fu, which is good if that's what you mean to test.

    After Compline,
    Zaxo

Re: Homework question list
by TedPride (Priest) on May 21, 2005 at 07:26 UTC
    Just browse the boards every day and try to solve the more algorithmic-style questions without looking at the code people have posted. Then compare your code to theirs. A week or two of this will give you a fairly good grasp of Perl.

    By the way, the simplest way to remove trailing newlines from an array is:

    chomp for @arr;
    You could also use chop, substr, or s///, but chomp has the best combination of speed and flexibility for this task.
      Even better would be:
      chomp @arr;
      because when chomp is fed a list, it'll chomp each element.

      Arjen

Re: Homework question list
by cLive ;-) (Parson) on May 21, 2005 at 08:38 UTC

    Slightly OT, but I've been interviewing long distance recently, and I used the following 3 questions tasks (ffs). Bear in mind these are for web application development, so front end is important too.

    1. create a calculator using HTML/Javascript, that processes the entered equation through a Perl CGI script and displays the result. This tests JS usage and, the biggie, whether they untaint user input in the CGI before 'eval'ing. Also, use of CGI/Mason/Template Toolkit is examined (and mentioned in the original question).
    2. Compare two arrays and show the elements that exist in both (I actually screwed up in my live question, but the answers were still informative). This is a great question because it shows how someone thinks. Lower level devs use nested loops (I did, when this was thrown at me a few years ago). Smart people use hash slices. Really smart people use 'undef'd hash slices to save memory (or, rather, time - ty runrig).
    3. Search google for a particular search term and present the first ten results in a web page. Another good one to see how someone thinks. LWP is quick and dirty, the Google SOAP Perl API is elegant, yet non-intuitive if you haven't heard of it.

    Maybe we should start a quiz section where these sorts of questions can be dumped? I'm sure there are many more that push you to think laterally - or use aspects of Perl that involve some interesting thinking.

    cLive ;-)

      2. Compare two arrays and show the elements that exist in both (I actually screwed up in my live question, but the answers were still informative). This is a great question because it shows how someone thinks. Lower level devs use nested loops (I did, when this was thrown at me a few years ago). Smart people use hash slices. Really smart people use 'undef'd hash slices to save memory.
      Could you give an example of the "hash slice" method? Using hashes is a good way (something like my %temp; my @doubles = grep { ++$temp{$_} == 2 } @a1, @a2; works nicely), but I can't seem to figure out the "(undef'd) hash slice" method. Please enlighten me :-)

      Arjen

        Your example fails if @a1 or @a2 have a value more than once. For example, @a1 = (1, 2, 3, 2, 1) and @a2 = (4, 5, 6, 5, 4). Your grep would show 1, 2, 4, and 5 as elements existing in both arrays, when the right answer is obviously zero.

        I will also disagree with cLive ;-) that "really smart people" use the undef'd hash slices to save memory - if memory is a concern, sure. But in general, the difference is not going to be significant. Premature optimisation and all that. I've even found sometimes where using the standard "++$hash{$value}" turns out to be handy three months later when the number of times a value shows up becomes relevant. I didn't need to change nearly as much code because I wasn't "really smart" according to cLive's definition.

        Anyway, as always, TIMTOWTDI, so being able to use the undef'd hash slice is still a tool to keep handy:

        my %a1; undef @a1{@a1}; my @in_both = grep { exists $a1{$_} } @a2;
        Unfortunately, this has the side effect of showing duplicates if @a1 has a value, and @a2 has that value multiple times. Which, of course, may be what you want, but it's not explicit in the original requirement.
        my (%a1, %a2); undef @a1{@a1}; undef @a2{@a2}; my @in_both = grep { exists $a1{$_} } keys %a2;
        Oh, and I also recommend better variable names than what I'm using here. :-)

        Update: Added the italicised part in the last line.

        Interestingly, you made the same mistake an applicant made when doing the compare - as Tanktalus has pointed out :)

        By the way, Tanktalus, by "really smart people", I was referring to tilly here ;-)

        cLive ;-)

      Smart people use hash slices. Really smart people use 'undef'd hash slices to save memory.

      undef'd hash slices save time not memory.

      Update: Also, as pointed out to me in a previous post, only use this method if you don't care about the values of the hash, as the values do not necessarily get set to undef.

        I notice that in five years no one has filled in the details of the concise implementation.

        # given two arrays you want to compare for common elements, @a1 & @a2 +... my %common; undef @common{@a1}; delete @common{@a2}; my @common = keys %common; #for example: DB<1> @a1 = qw(a b c d e) DB<2> @a2 = qw(a c e ) DB<3> undef @common{@a1} DB<4> x \%common 0 HASH(0x8408418) 'a' => undef 'b' => undef 'c' => undef 'd' => undef 'e' => undef DB<5> delete @common{@a2} DB<6> x \%common 0 HASH(0x8408418) 'b' => undef 'd' => undef DB<7> print join " ", keys %common b d

        As Occam said: Entia non sunt multiplicanda praeter necessitatem.

      Those aren't questions.
Re: Homework question list
by ysth (Canon) on May 22, 2005 at 20:14 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://459086]
Approved by tye
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2014-08-02 04:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (54 votes), past polls