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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Well, I don't want to write your assignment answer for you, so I'll give you some different code to ponder a while that may help answer some of your questions.

use strict; use warnings; main (); # Only to ensure no global variables are used - look ma, no v +ariables sub main { my ($dogName, $color) = getDogData (); print "The $color dog's name is $dogName\n"; ($dogName, $color) = getDogData (3); print "The $color dog's name is $dogName\n"; } sub getDogData { my ($select) = @_; my @names = qw(woof k9 fred max); my @colors = qw(spotted white black brown); $select = rand (@names) if ! defined $select; return $names[$select], $colors[$select]; }

Prints:

The black dog's name is fred The brown dog's name is max

Please note that using strictures is not something you do when you have time, it is something you do to save time! Strictures tell you you have done something wrong early and can save huge amounts of time that would otherwise be spent poking around in the dark after black beetles with your eyes closed.

Update: In a follow up question weglarz asked 'What does the "qw" in "my @names = qw(woof k9 fred max);" do?'. See Quote-Like Operators in perlop for a description of Perl's various quote operators like qw.

True laziness is hard work

In reply to Re^3: prob w/ gatekeeper subroutine by GrandFather
in thread prob w/ gatekeeper subroutine by weglarz

Title:
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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-16 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found