Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
As part of our continuing crusade against sanity, we of #perlhelp (EFnet) have created a modest perl quiz to test for all the skills required to make the maintainance programmer voluntarily leap into the gaping chasm of madness. We hope it will reinforce everyone's appreciation of our favorite language, by itself and as a tool towards this noble goal.   ;-)

Only those who know and truly understand the answers to all these questions can call themselves [insert awesome title here].

For all exercises: no fork/exec/system/qx/open, no cmdline options, no user input, no modules, no tie, no bless, no %SIG. Make sure you don't depend on random factors, such as exact values of addresses. All solutions should be executable from the cmdline using perl -e For extra points, try to make them work under strict (warning: for one exercise no strict solution is known (yet))
UPDATE Thanks to mauke, strict solutions are now known for all exercises! :-)
Exercise 1: Create an array @x such that changing $x[0] also sets $x[1] to the same value Exercise 2: Given a pre-declared function "foo", write a code snippet that invokes it in an infinite loop; in 10 chars Exercise 3a: Create $foo such that \$foo->[1] == \$foo->{1} Exercise 3b: Create $foo such that \$foo->[1] == \$foo->(1) You must use different solutions for the two Exercise 4: Dump core in 6 chars Exercise 5: Create a static variable lexically scoped to a sub, and no wider than that. It's ok if it blows up under recursion Exercise 6: Create $x, $y such that $x eq $y && $$x ne $$y Exercise 7: Create $foo such that fileno($foo) && !*$foo Exercise 8: Create $foo such that ($foo^=0)++ eq $foo++ Exercise 9a: Create $foo such that eval(q[$$foo]) != eval(q[0+$$foo]) Exercise 9b: Create $foo such that eval(q[$$foo =~ / /]) && !$$foo Exercise 10: Make $x::y::x::y::y::x::y::x::x::y::y::y::y::x::y::y true in 26 chars of code Exercise 11: Make <STDOUT> eq <+STDOUT> in 25 chars Bonus Exercise: The code snippet 'sub foo{} goto +foo' produces an error: "Can't find label SCALAR(0x31c70c)" (the address may vary) Where does that ref come from? What does it point to?

Please black-box solutions/spoilers so people can safely read discussion without seeing all the answers. (for example use: <table bgcolor="#00000000"><tr><td><font color="#00000000">Text goes here</font></table>)

UPDATE: clarification of exercise 5: "static variable" means a variable whose value is retained across multiple invocations of the sub (like static vars in C), and being "scoped to a sub and no wider" means that the standard solution { my $x; sub { ... } } doesn't qualify, because $x is one block wider than the sub. (it is static though)
UPDATE: minor reformatting to make everything fit in 70 columns
UPDATE: they're designed for 5.8, though most probably have solutions on older versions too.

UPDATE: Strict solutions are now available for all exercises.

UPDATE: (21-7-2004) How's your Perl? (II)

This waste of time is sponsored by:
#perlhelp - Where people with no life teach people with no clue.

In reply to How's your Perl? by xmath

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2023-10-03 20:57 GMT
Find Nodes?
    Voting Booth?

    No recent polls found