the second argument that needs to be passed. Is this just the length of the name?

No, there's only one argument expected. That line of code is the program's error checking. It does two things, but acts on the same variable both times.

( my $name = $ARGV[0] ) && length $ARGV[0] > 2 or die "Usage: `$0 <nam +e>` (min. 3 letters)";
What's happening here is we are evaluating the truth of an expression without using an explicit if statement.
my $name = $ARGV[0]
will evaluate to false if the first argument passed in is empty (i.e. non-existent) because then the value of $name will be false (so `0` would fail also)[1]. If that happens, the or die ... kicks in. But if it evaluates to true, then
&& length $ARGV[0] > 2
is evaluated for truth, so at this point we know we have some kind of value in the arg passed in, and now we check that it's at least three characters long. If the second part of the evaluation fails, the whole thing fails (because of the &&), and again we go to or die ....

Finally, in our error message emitted upon dying, we use $0, the global variable that holds the name of the currently executing script, and explain what the problem was.

Amazing how much useful stuff you can do with one line of Perl, isn't it?

[1] So in Perl you can evaluate truth very concisely:

while ( 1 ) { # runs forever ... } if ( 0 ) { # won't run ... } sub foo { return 'something'; # or maybe not } if ( foo() ) { # only runs if foo() returns something ... }

Hope this helps.

edit: added missing parens


The way forward always starts with a minimal test.

In reply to Re^7: Recomendations For Learning perl? by 1nickt
in thread Recomendations For Learning perl? by adamZ88

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, details, 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, summary, 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.