Hi zapp,

Please my comments below:

2012/4/27 Zapp <zapp.pref...@gmail.com>

> when I use bash, I can write a file ( a.sh ) like :
> abc='abc'
> ddd='aaa'
> ...
> then I can load it in other file:
> source a.sh
> echo $abc $ddd # it always work!
>
> but in perl , how can I do like that ?
>
> I write a file ( my_env.pl ) like:
> #!/usr/bin/perl -w
> my $abc='abc';
> my $ddd="ddd";
>
> and in my.pl :
> #!/usr/bin/perl -w
> use strict;
>
> do './my_env.pl' or die '$!\n";
> print $abc $ddd; # and nothing happen
>
> why? anybody knows? Thanks!
>
> --
>

   You can achieve your aim like this [ofcourse one of several ways]:
  first script: my_env.pl
   #!/usr/bin/perl
  use warnings;
  use strict;

our $abc='abc';
our $ddd="ddd";
__END__
  second script [a module script to show another way]: My_env.pm
package My_env;
use strict;
use Exporter;

our @ISA=qw(Exporter);
our @EXPORT=qw($abc $ddd);

our $abc='abc';
our $ddd="ddd";
__END__

script to call them both: my.pl
#!/usr/bin/perl
use warnings;
use strict;
require "my_env.pl";
use My_env;

  our $abc;
  print $abc;  ## from my_env.pl script
  print $ddd;  ## from module My_env
__END__

I hope this helps

Reply via email to