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:
When I keep shiftmy %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
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?___OUTPUT___ 5 0x5 101
In reply to My very confusing questions by ROP
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |