Thai Heng has asked for the wisdom of the Perl Monks concerning the following question:
I run as#!/bin/perl use v5.14.2; use strict; use Carp; package main; main(); sub main { show_call_information(); } sub show_call_information { my ($package, $file, $line,$func) = caller(0); say "Called $func from $package in $file:$line"; } say "---------use Carp------------------"; say add_numbers(1,2,3); sub add_numbers { croak 'Expected two numbers, received:' . @_ unless @_ == 2; my ($one, $two) = @_; return $one + $two; }
get the following output:perl chapter5_2.pl
Called main::show_call_information from main in chapter5_2.pl:13 ---------use Carp------------------ Expected two numbers, received:3 at chapter5_2.pl line 28. main::add_numbers(1, 2, 3) called at chapter5_2.pl line 24
I can't know why the main() function is called automatically? What's the mechanism?
How can I get result from formal document such as perldoc?
Thanks!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: why main() call automatically?
by kcott (Archbishop) on Jan 17, 2014 at 01:58 UTC | |
Re: why main() call automatically?
by Anonymous Monk on Jan 16, 2014 at 23:56 UTC | |
Re: why main() call automatically?
by bulk88 (Priest) on Jan 17, 2014 at 05:13 UTC | |
by chromatic (Archbishop) on Jan 17, 2014 at 18:14 UTC | |
by Anonymous Monk on Jan 21, 2014 at 04:17 UTC | |
Re: why main() call automatically?
by Thai Heng (Beadle) on Jan 21, 2014 at 00:34 UTC |