Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Global Variable

by lamp (Chaplain)
on Sep 22, 2008 at 14:39 UTC ( [id://713031]=note: print w/replies, xml ) Need Help??


in reply to Global Variable

The following is the sample code for achieving the above mentioned scenario using require method.
file1.pl
#!/usr/bin/perl -w use strict; use warnings; our $error; $error = 10; print "before $error \n"; require 'file2.pl'; # you can use 'do' also print "after $error \n";
file2.pl
#!/usr/bin/perl -w use strict; our $error = 20;
output
before 10 after 20

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://713031]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-09-12 02:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (15 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.