At 03:02 PM 7/11/02 -0500, rory oconnor wrote: >Thanks so much for your help Peter. I'm getting a grasp of this. > >However, I have been using a separate file containing subroutines shared >by a few scripts. They have worked previously because I was just >requiring it, and all my variables were global. I set up my config file >as a package (thanks to you), do I also need to set up my subroutines >file as a package?
No (long story: because subroutines are implicitly inserted into the symbol table). But doing so will give you a leg up on understanding more advanced programming should you get to it in the future. >If so, do I have to explicitly export all the possible return variables >in the whole subroutines package? I don't understand that. If the subroutines package defines variables as well as subroutines, then they have to be handled like the last example I gave. Here's an example of using the Exporter on subroutines as well: $ cat user #!/usr/bin/perl -wl use strict; use MyConfig; print "\$foo = $foo"; print "\@bar = @bar"; print "%baz = ", join(' ' => %baz); print "iterator = ", iterator for 1..5; $ cat MyConfig.pm package MyConfig; use strict; use Exporter; use vars qw(@ISA @EXPORT $foo @bar %baz); @ISA = qw(Exporter); @EXPORT = qw($foo @bar %baz iterator); $foo = "one"; @bar = qw(two three); %baz = (four => 4, five => 5); my $NEXTVAL = 100; sub iterator { return $NEXTVAL++ } 1; $ ./user $foo = one @bar = two three %baz = five 5 four 4 iterator = 100 iterator = 101 iterator = 102 iterator = 103 iterator = 104 >thanks again! > >Rory > >On Thu, 2002-07-11 at 13:59, Peter Scott wrote: > > At 01:19 PM 7/11/02 -0500, rory oconnor wrote: > > >Peter, > > > > > >Thanks so much for the help! Unfortunately I am not using 5.6. I'd > > >like to, but it's not up to me to do the upgrading! Which parts are > > >5.6-only, and how can I work around? > > > > Altered for 5.004... if your perl is older than that, it's time to come > > out of the fallout shelter... > > > > $ cat user > > #!/usr/bin/perl -wl > > use strict; > > use MyConfig; > > print "\$foo = $foo"; > > print "\@bar = @bar"; > > print "%baz = ", join(' ' => %baz); > > > > $ cat MyConfig.pm > > package MyConfig; > > use strict; > > use Exporter; > > use vars qw(@ISA @EXPORT $foo @bar %baz); > > @ISA = qw(Exporter); > > @EXPORT = qw($foo @bar %baz); > > > > $foo = "one"; > > @bar = qw(two three); > > %baz = (four => 4, five => 5); > > > > 1; > > > > $ ./user > > $foo = one > > @bar = two three > > %baz = five 5 four 4 > > > > -- > > Peter Scott > > Pacific Systems Design Technologies > > http://www.perldebugged.com/ > > > > -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]