Hi people,
trying to gather information from several logfiles at once, outputting relevant (to me) information to the screen. This mean I have to have an unspecified number of files open for reading at the same time. Unspecified because the config file can contain any number of files to be 'tailed' along with what regexps to match to each file.
I'v tried using a hash like %monitored_files containing data like this:
use strict;
my %monitored_files;
%monitored_files = (
"messages" => "/var/log/messages"
);
my $key;
foreach $key (keys (%monitored_files)) {
open ($key, $monitored_files{$key}) or die " ! Could not open $key
+: $!";
print(" * $key opened\n");
}
Now, I know I can't do this when using strict, but, how else? I want to use strict, but is there no way of constructing the filehandle on the fly so I can predict what the filehandle will be called when using it later? Am I making sense at all?
Since I probably am thinking the wrong way about this problem, would someone please point me the right way?
Thanks!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.