grinder has asked for the wisdom of the Perl Monks concerning the following question:
I have run into an odd corner of Perl behaviour I don't understand. I've simplified it down to the following snippet:
#! /usr/local/bin/perl -w use strict; sub one {1} sub two {2} sub three { one + two } print three, "\n"; # outputs 1 sub really_three { one() + two } print really_three, "\n"; # outputs 3
I don't understand why one + two returns 1 instead of 3. I have to force context with parens. This occurs on 5.005_03 and 5.8.6, the opposite ends of the spectrum of perl that interests me.
Is this a facet of some more useful behaviour that I haven't noticed before? Could someone please enlighten me as to what is going on?
- another intruder with the mooring in the heart of the Perl
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Puzzled by constant subs
by Anonymous Monk on Mar 09, 2005 at 11:22 UTC | |
|
Re: Puzzled by constant subs
by brian_d_foy (Abbot) on Mar 09, 2005 at 14:57 UTC | |
by grinder (Bishop) on Mar 09, 2005 at 15:24 UTC | |
|
Re: Puzzled by constant subs
by theorbtwo (Prior) on Mar 12, 2005 at 11:26 UTC |