Hi, Experts,
At first, please take a look at my code. Please also note that the ONLY difference between RED and BLUE is that @pattern1 has TWO members while @pattern2 has only ONE. Everything else is just the same!!
And here is the output:
My question: Why does the codes in RED NOT produce the SAME results? How to fix it?
Thank you! This one is driving me nuts.
At first, please take a look at my code. Please also note that the ONLY difference between RED and BLUE is that @pattern1 has TWO members while @pattern2 has only ONE. Everything else is just the same!!
Code:
#! /usr/bin/perl
use File::Find::Rule;
my $dir = '/sbin';
[COLOR=red]
# Block 1 in RED
my $rule1 = File::Find::Rule->new;
$rule1->file;
my @pattern1 = ("*power*", "*Power*");
my (@files1);
foreach my $p1 (@pattern1) {
$rule1->name($p1);
@files1 = $rule1->in($dir);
}
print "Block 1: \$#files1 = $#files1\n";
if($#files1 > -1) {
foreach my $f1 (@files1) {
print "$f1\n";
}
}[/color]
[COLOR=blue]
# Block 2 in BLUE
my $rule2 = File::Find::Rule->new;
$rule2->file;
my @pattern2 = ("*power*");
my (@files2);
foreach my $p2 (@pattern2) {
$rule2->name($p2);
@files2 = $rule2->in($dir);
}
print "Block 2: \$#files2 = $#files2\n";
if($#files2 > -1) {
foreach my $f2 (@files2) {
print "$f2\n";
}
}[/color]
Code:
% test.pl
[COLOR=red]Block 1: $#files1 = -1[/color]
[COLOR=blue]Block 2: $#files2 = 5
/sbin/powermig
/sbin/poweroff
/sbin/quick_poweroff
/sbin/powerd
/sbin/powerprotect
/sbin/powermt[/color]
My question: Why does the codes in RED NOT produce the SAME results? How to fix it?
Thank you! This one is driving me nuts.