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
Post a Comment