in reply to Assign scalar to array

Your code would be easier to read if you used consistent indentation - honest! It will also help you if you always use strict; and use warnings;
The use of quotes is part of your problem. The \ is an operator, and \ has no effect inside double quotes. Update: that's rubbish, of course it has an effect, what was I thinking?

Here is my version, with some variables added to make it work:
use strict; use warnings; sub GetDecUser { my $LFILE; my $LOGFILE12 = $0; my @arr12 = ('The','quick','brown','declared users'); my @arr10 = qw(The quick brown fox); if (-e $LOGFILE12) { $LFILE = \@arr12; # if the 12 log exists, use it } else { $LFILE = \@arr10; } print "$LFILE\n"; for my $dec (@$LFILE) { if ($dec =~ /declared users/) # match this { print "TESTING we found it: $dec\n"; } } } GetDecUser();

Replies are listed 'Best First'.
Re^2: Assign scalar to array
by ikegami (Patriarch) on May 18, 2010 at 16:30 UTC

    The \ is an operator, and \ has no effect inside double quotes.

    That's not true. It most definitely had an effect (escaped the "@" to prevent interpolation). Just not the desired one.

      Dear Monks,

      This is working great now! Many thanks for your patience and assistance