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. } } }
In reply to Assign scalar to array by topteam
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |