Hello, Hoping you can help me here.

I'm trying to write a perl script however am I lots of difficulty with a particular sub routine which is essentially grepping a log files, depending on which exist. I'm starting to test with just two log files, but there will be about 8 to select from in the end so hence the usage of subs.

Anyway, I' attempting to check if a 12 Log exists, if it does then assign that scalar to be used later in the loop as the array:

sub GetDecUser { if (-e $LOGFILE12) { $LFILE = \@arr12; # if the 12 log exist, use it } else { $LFILE = "\@arr10"; # $LFILE = @arr10; # Tried this and this just seems to loop throu +gh the whole log } print "$LFILE\n"; # this prints @arr10, so the scalar is getting po +pulated for $dec ("$LFILE") # Use what ever log was found in the above if s +tatement #for $dec (@arr10) # this works fine, but its not using the assignm +ent! { if ($dec =~ /declared users/) # match this { print "TESTING we found it: $dec\n"; # Nothing outputted + when I try this. } } }
Many Thanks (yes I know I can do this easily in shell, but am trying to learn some perl)

In reply to Assign scalar to array by topteam

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.