conversion of loop in perl

Hello Sir,

How can i convert below two loop lines in perl

 for BLOCK in /sys/block/myblock[a-z]* 
 for BLOCK in /dev/myblock[a-z]* 

How i can write them in perl like

 foreach( </sys/block/myblock[a-z]*/queue/nr_requests> ) 

You could use the glob operator, however while character classes are available specifying multiple occurrences isn't available so you'd have to perform the character class check within the loop.

for my $block (glob 'sys/block/myblock*'){
  if ($block=~(^/sys/block/myblock[a-z]*$)){
    ...
  }
}

Below code is also fine, please confirm.

for my $block (glob '/dev/myblock*'){
if ($block=~(^/dev/myblock[a-z]*$)){
...
}
}

Yes, the same pattern applies

Please confirm below code is fine.


for my $block (glob '/dev/myblock*'){
  if ($block=~(^/dev/myblock[a-z]*$)){
system("blockdev --setra 16384 $_");

  }
}

Install perl and try it yourself.

If you're unable to do so, this looks less like practical questions and more like homework.