Hi Monks, I have a lot of questions that I can't seem to figure out. These questions are holding tonnes of weight on my shoulders, and I feel like if I understand these they will be lifted off of my shoulder! (: Here's my first question, I understand that with arrays, shift takes away the first value of an array at the start, unlike pop which does this at the end, and if no array is given then it uses the default @_, but I don't understand its use in subroutines? Here is the updated code:

my %h = ( decimalhex => sub{return sprintf("0x%x", shift)}, decimalbinary => sub{sprintf("%b", shift)}, hexdecimal => sub{return sprintf("%d", shift)}, ); my $var = <STDIN>; print $h{decimalhex}($var), "\n"; print $h{decimalbinary}($var), "\n"; print $h{hexdecimal}($var), "\n"; Basically, this script converts numbers into different formats(binary +and hex), when I take away shift: <code>___OUTPUT___ 5 0x0 0
When I keep shift
___OUTPUT___ 5 0x5 101
Why is that? What is shift doing that changes the output? When should I use the shift() function during subroutines? Another question, what's the point of return?
___OUTPUT___ 5 0x5 101
Without return it's the same thing?


In reply to My very confusing questions by ROP

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.