Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
The newbie has questions... the wise old monks have answers... but all too often newbie can't communicate the question, and the wise old monks fall over each other trying to guess what the newbie might have meant -- perhaps what merlyn meant when he wrote "the only personality trait Perl programmers have in common is that they're all pathologically helpful" (Programming Perl, "Perl Culture"). Examples of this happen all the time -- see for instance the recent post at Regex doubt.

Well, pathological helpfulness (or xp greed :) ) has its bright side as a cultural feature, but enough is enough.

With this series of posts I want to help everyone save time, newbies and wise old owls alike, by providing templates for how to ask certain common types of questions. This is intended to be an alternative place to point newbies to, rather than the (also very helpful, but in a more general way) How (Not) To Ask A Question.

As a bonus feature, newbies learning this will also learn Test::More, a powerful tool every monk should incorporate into their life.

The first example will be short. My comments are in ~ . Here goes.

******************BEGIN QUESTION TEMPLATE************************

O Wise Monks, I am having a problem I hope you can help me with.

As you can see, in the following code, my zero test for the "multiplies_by_seven" function fails. ~the problem is isolated~

I tried googling on "perldoc shift" but no dice. Am I searching with the wrong search terms? ~the newbie tried to help himself first before going to the perlmonks~

What the heck am I doing wrong?

~The novice now posts his code using code tags: see Writeup Formatting Tips~

# use strict; #~the newbie has used the strictures~ use warnings; use Test::More qw(no_plan); my ($result, $expected); # ~convenient way to structure your input and expected output is to ~ # ~suck in the test data, which is everything after the __DATA_ line.~ while (<DATA>) { #~splits a string on spaces by default; see perldoc -f split~ my ($input, $expected) = split; my $output = multiply_by_seven($input); is($output, $expected, "testing $input"); } sub multiply_by_seven { my $number = shift or die "no number"; return $number*7; } #~convenient way to structure your input and expected output, #assuming that you can use whitespace as the delimiter. __DATA__ 1 7 2 14 3 21 0 0
I'm on Windows XP system using the standard ActiveState perl distribution. ~The novice mentions what system he is on.~

I got both standard and error output out of my test, into one output file, by running this with perl multiplyBySeven.pl > output.txt 2>&1 output.txt. ~Enables newbie to communicate his test result with a minimum of putzing around~

The output is:

ok 1 - testing 1 ok 2 - testing 2 ok 3 - testing 3 no number at multiplyBySeven.pl line 18, <DATA> line 4. 1..3 # Looks like your test died just after 3.

Any ideas? Thanks very much in advance, o wise monks :)

******************END QUESTION TEMPLATE************************

That's basically it. Why the 0 test fails is left as an exercise for the reader :)


Update: More tutorials in this series to come. See tphyahoo's homenode for tutorials under construction :)

In reply to How to Ask a Question (With Test::More) by tphyahoo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (5)
    As of 2020-02-21 16:56 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What numbers are you going to focus on primarily in 2020?










      Results (96 votes). Check out past polls.

      Notices?