I know that the question specifically speaks of βfunctionsβ, but I get this post high in search when I search for βperl includeβ, and often times (for example, now) I want to include variables (in a simple way, without thinking about modules) . And so I hope that my example will be published here (see Also: Perl require and variables ; in short: use require and make sure that both the "includeser" and "includesee" files declare the variable as our ):
$ perl --version This is perl, v5.10.1 (*) built for i686-linux-gnu-thread-multi ... $ cat inc.pl use warnings; use strict; our $xxx = "Testing"; 1; $ cat testA.pl use warnings; use strict; require "inc.pl"; our $xxx; print "1-$xxx-\n"; print "Done\n"; $ perl testA.pl 1-Testing- Done $ cat testB.pl use warnings; use strict; our $xxx; print "1-$xxx-\n"; $xxx="Z"; print "2-$xxx-\n"; require "inc.pl"; print "3-$xxx-\n"; print "Done\n"; $ perl testB.pl Use of uninitialized value $xxx in concatenation (.) or string at testB.pl line 5. 1-- 2-Z- 3-Testing- Done
sdaau Jan 20 '13 at 11:33 2013-01-20 11:33
source share