in reply to Writing compact conditional regex's
This is not a direct answer, just some points you might want to know about.
if ($temp =~ /(.+?)(\d{1,2}x\d{1,2}|s\d{1,2}e\d{1,2})/ix) { $inventory{$1}=$2; }
if (($temp=~s/(\d{1,2}x\d{1,2})//i) or ($temp=~s/(s\d{1,2}e\d{1,2})//i) ) { $inventory{$_}=$1; }
If you didn't have named captures (such as before perl 5.10), you would have to write this in an uglier way:$ perl -we 'for (qw"14/3 03-14") { m"^(?:(?<m>\d\d)-(?<d>\d\d)|(?<d>\d +{1,2})/(?<m>\d{1,2}))$" or die; print "$_ => month=$+{m}, day=$+{d}.\ +n"; }' 14/3 => month=3, day=14. 03-14 => month=03, day=14.
which is prone to errors if you have to change the regex later so the captures are renumbered.perl -we 'for (qw"14/3 03-14") { m"^(?:(\d\d)-(\d\d)|(\d{1,2})/(\d{1,2 +}))$" or die; my $m = $1||$4; my $d = $2||$3; print "$_ => month=$m, +day=$d.\n"; }'
|
|---|