Re: General Perl/Web questions



Yeah, what that would pretty much mean is that you will make a file
called, say, CommonFuncts.pm and then in each Perl script say

use CommonFuncts;

Alternatively, you can make a common_functs.pl file, where each one of
the above actions is performed in a subroutine (the file should only
have subroutines, and should not do anything outside of them (except
like use strict;)) and then, from within each file, you could do
something like

BEGIN
{
do ('common_functs.pl');
die if $@;
}


The BEGIN just makes the block be loaded at the beginning of
execution, the do() function loads files and eval()s them (except
since all we have are subroutines, nothing is actually performed, you
just now have all of the new subroutines to work with) and the 'die if
$@' exits if there were syntax errors in the common_functs.pl file and
it prints them.

Either of the two ways work, I just prefer do();

Cheers!

--
Leonid Grinberg
lgrinberg@xxxxxxxxx
http://www.lgrinberg.org
.



Relevant Pages

  • Re: Faster way to execute contents of a perl script?
    ... I have second perl script that contains calls to these ... >>execute the ... > There is no need to repeatedly 'do' the second file containing ... After this has been done once, the subroutines may be ...
    (comp.lang.perl.misc)
  • Re: Faster way to execute contents of a perl script?
    ... I have second perl script that contains calls to these ... > execute the ... There is no need to repeatedly 'do' the second file containing ... After this has been done once, the subroutines may be ...
    (comp.lang.perl.misc)
  • Re: Requiring perl scripts
    ... Bigus wrote: ... > it just make the subroutines available or will it attempt to run all the ... Perl script that also functions as a Perl4-style library by checking ... Migrate the common subroutines to a Perl5-style module and use it in ...
    (comp.lang.perl.misc)