Michael C. Davis wrote: > > I just ran across some unexpected results in passing arguments to > user-defined subroutines. Could someone who has been around Perl a while > longer check this and make sure I'm seeing this right? > > I've got some code that implements a constant as a subroutine call (to keep > the constant from being modified). When I use that subroutine in an > arithmetic expression, it is consuming everything to the right of it as its > argument list. It looks like one simply needs to be careful in the > following case: > > - user-defined subroutine, where > - subroutine does not validate incoming arguments > - subroutine has no prototype > - ... -or- prototype not defined at point of actual subroutine call (ie is > called relative to its own namespace and not by name imported into caller's > namespace) > - is called as plain old subroutine and not as method > > I have to say this is rocking my world -- because of the potential for such > code to die silently in a number of situations not hard to imagine -- but I > guess that someone who's been around Perl for a while would not be > surprised by this. > > Am I reading the situation correctly? Thanks! > > Example subroutine call that fails: > ---------------------------------- > print MyProject::CoreConstants::EarliestValidTimestampAsNumber+1, "\n"; # > fails -- the result does not have +1 added to it
Hi Michael. I haven't looked at this at all carefully, but my first guess would be be that you need to call the subroutine as if it was one: print MyProject::CoreConstants::EarliestValidTimestampAsNumber() + 1, "\n"; but, even better, how about use constant EARLIEST_VALID_TIMESTAMP => MyProject::CoreConstants::EarliestValidTimestampAsNumber(); print EARLIEST_VALID_TIMESTAMP + 1, "\n"; BTW, where does 'timegm' come from? HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>