Hi Sooraj,

welcome aboard.

On Friday 12 November 2010 17:36:54 Sooraj S wrote:
> Hi I am new to perl.
> 
> I am trying to access a variable which is declared in a package. I
> have kept both the files in the same directory. But still my code
> errors out as ""$my_val" requires explicit package name".
> 
> my_file.pl
> =======================
> #!/usr/bin/perl
> 
> use strict;

Add use warnings.

> use my_package;

Please start your packages with an uppercase letters, as package names that 
start with a lowercase letter are reserved for pragmas.

> 
> print "\nValue : $my_val\n";

You cannot access a lexical variable from a different module as "use" creates 
a scope for that. While you can make it a package-scope variables (using "use 
vars" or "our"), please consider providing an interface to your modules using 
procedures instead of variables.

> 
> 
> my_package.pl

This is likely my_package.pm.

> ======================
> package my_package;
> 

You forgot "use strict;" here and you again don't have "use warnings;". For 
more information see:

* http://perl-begin.org/tutorials/bad-elements/

* http://www.onyxneon.com/books/modern_perl/index.html

* http://perl-begin.org/books/advanced/#pbp

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/

<rindolf> She's a hot chick. But she smokes.
<go|dfish> She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to