in reply to 'use strict;' between libraries

Most of your problem here is caused by having subroutines that are only called for their side effects on global variables. A better approach would probably be to use subroutines which return values.

#!/usr/bin/perl # pie.pl use strict; my $pie; require "b.pl"; $pie = &getpied; print "The pie says : $pie\n";

and

#!/usr/bin/perl # b.pl use strict; sub getpied { return "eat me"; } 1;

An even better approch would be to look into turning b.pl into a real module.

Update: Oops. Just saw the part where you said

Using return is not an option, as I have a whole lot of variables that has to be available in about 8 different scripts.

(thanks to Skeeve for pointing it out)

In that case, you really need to turn b.pl into a module and use Exporter.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re: Re: 'use strict;' between libraries
by Skeeve (Parson) on Jul 16, 2003 at 12:42 UTC
    Just to let you know why --. He explicitly didn't want to return the value

    > Using return is not an option, as...

    But I have to aggree that it's a better approach to try to use return values or at least give the subroutine a reference to the variable that should be changed.

      Update: This was excessively rude and brutal on my part. Although probably factually accurate, I should have found a more polite way to say this than the method I chose. I'm sure the OP is a good guy whose code does what it's intended to do, whatever issues it might have from a purist's point of view.

      His full statement was:

      Using return is not an option, as I have a whole lot of variables that has to be available in about 8 different scripts.

      He might just as well say:

      I don't want to return variables because I want to write crappy code - I just want to put use strict at the top of the files so it doesn't look like crap, or because it looks cool, or because "everyone says I should".

      He is building a demonic cluster-f***, which will torment him and all who follow.

      And I'm not trying to be mean, but this is not the way to do a project. There is a reason you break things into pieces, but if you're going to use global variables everywhere, <sarcasm>better to have it all in 1 file 10000 lines long, where at least you find all the references to your globals.</sarcasm>.

      --Bob Niederman, http://bob-n.com
        Yes, it was extremely rude ;-)

        But who cares if one read this on your homepage. That's just your overall attitude.

        you're right of course ... best thing to do would be to screen out all novices so that you wouldn't be bothered by beginners like us ... who do we think we are tapping into a site like this anyway ... been working through perl for 3 weeks now but apart from this "post" I don't reckon I'll be brave enough to ask any questions for a few years ... fyi, that issue that was raised resolved issues of understanding that I had ... without your puerile rant.