On 10-11-12 10:36 AM, 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;

use strict;
use warnings;

use my_package;

use My_Package;


print "\nValue : $my_val\n";

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



my_package.pl

My_Package.pm

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

package My_Package;


my $my_val = "Just a test";

our $my_val = "Just a test";


1;

Always have `use strict;` and `use wranings;`. By convention, all packages in Perl start with an uppercase letter. The variable you access has to be global, which is declare with "our".


--
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

--
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