Hi harangzsolt33,

Just to mention a few more small things in addition to Corion's excellent post.

print "\nL=".((AA) + BB) ."\n";

An alternate way to tell Perl that the call to AA should take no arguments (instead of taking the return value of the call to BB) is (AA() + BB()).

# sub DDD { # 4+4; # 5+(previous lines' result); # return previous line's result; # }

In the first case, no, you'd need to write 5 + (4+4); or my $v = 4+4; 5+$v;.

In the second case, from perlsub: "If no return is found and if the last statement is an expression, its value is returned." So all you need to write is sub foo { my $v = 4+4; 5+$v; } and foo will return 5+$v.

perlsub also goes on to explain why your sub Y doesn't return the value of $i: "If the last statement is a loop control structure like a foreach or a while, the returned value is unspecified." It's easily achievable though: sub Y { my $i=0; $i while($i++<10); $i }

And some more info on version strings: Version Strings

Hope this helps,
-- Hauke D


In reply to Re: Trying to understand Perl :-) by haukex
in thread Trying to understand Perl :-) by harangzsolt33

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.