Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: using require as c like #include?

by flounder99 (Friar)
on Jan 20, 2004 at 13:16 UTC ( [id://322577]=note: print w/replies, xml ) Need Help??


in reply to using require as c like #include?

First, there is an error in your example. You are creating $HoH but are dumping %HoH.

Besides that what is happening is that the code brought in by require is in it's own scope. So the variables declared with my go a way when you leave that scope. This is what our is for. If you are using an older (pre 5.6) version of perl you can use vars

$ cat HoH.pl use strict; use Data::Dumper; our $HoH; require 'hash'; print Dumper($HoH);
or
use strict; use Data::Dumper; use vars qw/ $HoH /; require 'hash'; print Dumper($HoH);
Either way you will just have to drop the my in hash (or also declare it our if you are using the first example.)

--

flounder

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-03-29 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found