You can use the following regex to get the patch number
 
chomp( $ch ); # remove the newline character
my ($pnum) = substr( $ch, 5 ); #grab everything after the pach_
Then you can say
if( $given_patchid > $pnum ) { #compare numerically
  ...
}
 
To sort the patches you can say
 
@patches = <F1>; #read the entire file into an array
chomp @patches; #remove all of the newlines
sort { substr( $a, 5 ) < substr( $b, 5 ) } @patches; #sort the lines by the values after the pach_
 
I'm not sure what result you want to store in a file, but if it is the patches then you can say
open F2, ">file.out" or die "Could not open file.out: $!\n"; #open a file for writing
print F2 join( @patches, "\n" ); #add a newline to the end of each line and write it to file.
 
----- Original Message -----
Sent: Tuesday, November 12, 2002 4:00 AM
Subject: a simple pattern matching quesn

i have a file(say f1) containing patch names
pach_2377
pach_2676
pach_3897
I want to check if there are(is)  patch _id(s)  which r greater than given patch_id
(say  :  pach_2579)
 pls tell me how to do that in perl
i.e.
 while (<f1>)
{
 $ch = $_;
 if ($given_patchid  gt $ch )    ###### pls tell me how to exactly do it
<  do some action>
}
###  should i extract last digits - then to extract them ?
 
u can also write me how to sort & store the result in a file
____________________________________________________
  IncrediMail - Email has finally evolved - Click Here

Reply via email to