CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Using "use" doesn't import variables implicitly

 



Cupidvogel
Novice

May 6, 2012, 8:19 AM

Post #1 of 3 (1598 views)
Using "use" doesn't import variables implicitly Can't Post

Hi, I was under the impression that one difference between use and require is that the former enables one to use unqualified versions of the imported variables, while the latter requires fully qualified names. But look at my situation, I am running a code from C:\Perl\Codes under test.pl which contains this:


Code
BEGIN {unshift @INC, "C:/"}; 
use Cards::need;
print "$w";


I have added a folder named Cards in C:\\ directory, inside which there is the module called need.pm. It contains this code:


Code
package Cards::need; 
our @b;
$w = 5;
@b = (1,2,3);


However when I run the test.pl file, nothing gets printed until I edit the 3rd line to be a fully qualified name like print $Cards::need::w. So why is the implicit import not working?


wickedxter
User

May 6, 2012, 9:46 AM

Post #2 of 3 (1578 views)
Re: [Cupidvogel] Using "use" doesn't import variables implicitly [In reply to] Can't Post

If you want to access the variable ull need to export them using the exporter module. If u dont u wont have access unless u do


Code
Print $cards::need::w;



Cupidvogel
Novice

May 6, 2012, 10:16 AM

Post #3 of 3 (1563 views)
Re: [wickedxter] Using "use" doesn't import variables implicitly [In reply to] Can't Post

Thanks...

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives