perl - Combination of while, array, and regex -


the loop fails. wrong array?

i regex return b when parses first string, , m when parses second string.

how such regex constructed?

#!/usr/bin/perl  use warnings; use strict;  $a = "0.0 b/s"; $b = "12.0 mib/s";  while (defined (my $s = shift ("$a", "$b"))) {      $unit = $1 if ($a =~ m/.*([kmgt])i?b\/s$/);     print "$unit\n"; } 

you need substitution:

for ($a, $b) {   if (m!((?:[kmgt]i)?b)/s$!) {     $unit = $1;      $unit =~ s/(.).*/$1/;     print "$unit\n" if $unit;   }    } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -