I'm exporting some functions into a seperate module and I'm getting some awkward behavior. I spent a lot of time boiling it down to figure out what was happening. For a long time, I kept thinking I wasn't passing scalars back and forth correctly :(

I boiled it down to an example in these two modules (they don't reflect the actual code). For sake of argument, they're just entitled module1 and module2:

use strict; use lib ('./'); require 'module2.pl'; Alice->mTest2 ("Some stuff", "and something else"); 1;
the other module contains:
use strict; package Alice; sub mTest2 { my ($junk, $and) = @_; print "$junk=$junk\n\$and=$and"; }

Naturally, I would expect it to print out
Some stuff
and something else.

Instead I get:

Alice
Some stuff

Ok, after doing some searching and a bit of experimentation, I can see where a person would want to know the context the function is called. I fried my brain and all I can come up with is a shift on the @_ to look for the object name. If it matches, then proceed to get the rest of the array. If it doesn't match, then assume it's a variable I want to keep and proceed accordingly. But this seems really sloppy when all I really care about is the variables I want to deal with, not the package name.

I guess what I'm asking is, can someone clarify if this is some sort of error on my part, or is this perfect behavior (which I assume it is)? I tried to flip through the Camel to see if this is mentioned, but I can't find it :(
Gah! I need coffee...

----
Thanks for your patience.

Prove your knowledge @ HLPD


In reply to Unexpected value in incoming variable. by SavannahLion

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.