in reply to Not able to execute perl sub routine

welcome to the monastery sachin raj aryan!

if &sub is looking old style to many monks (not me, and is quite good if you do not use prototypes at all and if if you are aware that ⊂ will call &sub(@_); behind the scenes), what is looking very weird is the ancient require "file.pl"; style.

Code to be required and it's contained subs must go in modules and modules must be used via use

A simple module is more flexible than a required file, is easier to be tested.

Perl Modules are described in perlmod

PS: many simple module implementations can profit of the Exporter one to pull subroutines into the namespace.

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Not able to execute perl sub routine
by Laurent_R (Canon) on Dec 03, 2016 at 22:12 UTC
    if &sub is looking old style to many monks (not me, and is quite good if you do not use prototypes at all and if if you are aware that ⊂ will call &sub(@_); behind the scenes)
    I disagree, it is not "quite good". Or I would at least phrase it the other way around: It is really bad unless you really know what you're doing and really need that feature. Otherwise, simply don't use that obsolete syntax.

    For the rest, I agree that it is usually better to use a module with use rather than require.