On 12-04-27 03:06 AM, Zapp wrote: > 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";
`my` produces lexical variables which means they are scoped to the file. These variable will not be accessible outside the file. Tey something like: use vars qw( $abc $ddd ); $abc = 'abc'; $ddd = 'ddd'; > > and in my.pl : > #!/usr/bin/perl -w > use strict; > use vars qw( $abc $ddd ); > do './my_env.pl' or die '$!\n"; > print $abc $ddd; # and nothing happen print $abc, $ddd, "\n"; > > why? anybody knows? Thanks! > If you want to create a configuration file: $ cat MyConfig.pm #! use strict; use warnings; use base qw( Exporter ); our @EXPORT = qw( %MyConfig ); our @EXPORT_OK = qw( ); our %EXPORT_TAGS = ( all => [ @EXPORT, @EXPORT_OK ], ); our %MyConfig = ( abc => 'abc', ddd => 'ddd', ); 1; __END__ $ cat myscript.pl #!/usr/bin/env perl use 5.014; use strict; use warnings; use Data::Dumper; # Make Data::Dumper pretty $Data::Dumper::Sortkeys = 1; $Data::Dumper::Indent = 1; # Set maximum depth for Data::Dumper, zero means unlimited local $Data::Dumper::Maxdepth = 0; our %MyConfig; use MyConfig; print Dumper \%MyConfig; __END__ $ -- Just my 0.00000002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. [updated for today's programmers] "Show me your code and conceal your interfaces, and I shall continue to be mystified. Show me your interfaces, and I won't usually need your code; it'll be obvious." -- Fred Brooks Don't be clever; being great is good enough. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/