Hello! I'm quite new at Perl and trying to build a config file written in perl and then pull it into a main file to setup variables. I've read the tutorials but still fail to grasp the concept. What am I doing wrong and how should I do it? I've been at it for 1.5 day now. Code is shortened since the config file is rather large but the concept is the same.

#!/usr/bin/perl -w use strict; use warnings; my $MATCH_FILE="/path/to/patterns.pl"; my @LOGE; # this is an array that should be "configured" by the patter +n.pl my $return; unless ($return = do $MATCH_FILE) { warn "couldn't parse $MATCH_FILE: $@" if $@; warn "couldn't do $MATCH_FILE: $!" unless defined $retu +rn; warn "couldn't run $MATCH_FILE" unless $return; } print $return; # this prints 2 printLogPatterns(@LOGE);

In this file I want to set the @LOGE file to a variable set in the patterns.pl file.

#pattern.pl use strict; use warnings; my $astring = "This is an example string"; # not accessed @LOGE = ( { HASH => "a hash"},{ HASH => "Another one"} ); # this is wh +at I want to be "exported" sub asub{ print "a sub"; }# is this also possible to "export"?

I'd like to use a pulled in perl config file since it would be good to configure the application quite fast and the possibilities looked very promising. Any help is appreciated


In reply to Making use of a config file written in Perl by noodleish

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.