HI, I'm looking for some advice of how to do this?
I need to match some "variable" pattenrs so
I define a $match variable and use it in the patterr below.
However it didn't match anything for the sample data.
If I change the match critia to hardcode
next unless /\s+BCV\s+N/Grp/; it works
if I
next unless /\s+BCV\s+N\/Grp/; it didn't work
so my question are
1. what is the proper way to use \ within regex?
2. can I use $match within regex , sun as / $match ../, should I quote
' or "" for $match ?
3. can I use ${match} to make it more readiable?
Thanks.
Jason
===== code segment ===
my $sid = $ARGV[0];
my $type = $ARGV[1];
my @devices = find_avaiable_devices ();
sub find_available_devices {
my @finds = ();
my $match = ( $type eq 'bcv' ) ? 'BCV' : 'RAID-5' ;
open (AVAIL, "$symdev list -sid $sid -noport -$type |" ) or die
"cannot open $!\n";
while ( <AVAIL> ) {
next unless /Not Visible.*\d\d[A-D]:[A-D][0-3]\s+${match}\s+N\/Grp/;
my ($device , $type, $size) = ( split )[0,5,8];
push @finds , $device if defined $device ;
}
return @finds;
__END__
# Sample output from ""$symdev list -sid $sid -noport -$type" below
__DATA__
05F3 Not Visible ???:? 16A:CF RAID-5 N/Grp'd RW
9492
05F4 Not Visible ???:? 01A:DF RAID-5 N/Grp'd RW
9492
05F5 Not Visible ???:? 16A:D10 RAID-5 N/Grp'd RW
9492
05F6 Not Visible ???:? 01A:C10 RAID-5 N/Grp'd RW
9492
05F7 Not Visible ???:? 16A:CF RAID-5 N/Grp'd RW
9492
05FA Not Visible ???:? 16A:D0 BCV N/Asst'd RW
9492
05FB Not Visible ???:? 16D:C0 BCV N/Asst'd RW
9492
05FC Not Visible ???:? 01A:C0 BCV N/Asst'd RW
9492
05FD Not Visible ???:? 16B:C0 BCV N/Asst'd RW
9492