topteam has asked for the wisdom of the Perl Monks concerning the following question:
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:
Many Thanks (yes I know I can do this easily in shell, but am trying to learn some perl)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. } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Assign scalar to array
by cdarke (Prior) on May 18, 2010 at 15:26 UTC | |
by ikegami (Patriarch) on May 18, 2010 at 16:30 UTC | |
by topteam (Initiate) on May 18, 2010 at 16:49 UTC | |
|
Re: Assign scalar to array
by ikegami (Patriarch) on May 18, 2010 at 15:04 UTC | |
by topteam (Initiate) on May 18, 2010 at 15:31 UTC | |
by ikegami (Patriarch) on May 18, 2010 at 16:24 UTC | |
|
Re: Assign scalar to array
by jwkrahn (Abbot) on May 18, 2010 at 17:02 UTC |