Jin Zhisong wrote:
> 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
>   
This line gives me a syntax error (Bareword found where operator expected)
> if I 
>
>   next  unless /\s+BCV\s+N\/Grp/;  it didn't work
>   
This regular expression matches one or more spaces, "BCV", one or more
spaces and "N/Grp" (i.e., " BCV N/Grp")
>  
>
> so my question are
>
> 1.  what is the proper way to use \ within regex? 
>   
You use '\' when you want to match literally some character that
otheways would be interpreted as an operator ('+', '*', etc.) or end of
regex (like '/' in the example above). Just to be sure, escape with '\'
any non alphanumeric you want to match literally.
> 2.  can I use $match within regex , sun as / $match ../, should I quote
> ' or "" for $match ?
>   
You can use $match alone or ${match} (safer).
> 3.  can I use ${match} to make it more readiable? 
>   
Yes, it's better.
>  
>
> 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
>
>  
>
>
>   


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to