You can't read lexical variables from an external file and see them in your file. With strict or without. That's one of the scope restrictions dictated by my.

Anyway, you can't escape when use strict is in effect, but you shouldn't do without. Consider two alternative solutions:

1: Create a module and export the variables you need from there. See perldoc perlmod and perldoc Exporter

2: Use OOP. A quick-and-dirty solution could be to create a bare bones class with some attributes you can pull out via class or object methods, but it's not that elegant :-). I'll write some untested crap below here, but you should really look for something better that fits your needs

package MyProgramConfiguration ; use strict ; use warnings ; # Take this as a starting point, # *NOT* as an example, *PLEASE*!!! my %config = ( color => 'yellow', beverage => 'chinotto', food => 'pizza', driver => 'Schumacher', ) ; my gimmeconf { # I don't care how you called me (class or object method) return %config ; }

And your prog could do:

use strict ; # don't leave it out use MyProgramConfiguration ; my %c = MyProgramConfiguration->gimmeconf() ;

In case I didn't say that, I'll say it again: don't take this as production code!!! Read it, understand how it works and create your solution from scratch. You have been warned. Also, you should read about lexical variables and how they work.

Ciao!
--bronto

# Another Perl edition of a song:
# The End, by The Beatles
END {
  $you->take($love) eq $you->made($love) ;
}


In reply to Re: Calling variables from external file, with strict by bronto
in thread Calling variables from external file, with strict by c

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.