I started programming perl again as the codebase at Overseas Family School has java and perl. Which draws me back to usability in perl, and so now I'm updating some of my old habits to kindler, gentler methods of code delivery to your brain.
Regular expressions can become illegible in a hurry, I used to deal with this by breaking the regexps into smaller regexps and hiding them indented below the relevant line:
$re = qr/^($ip) ($host) ($msg)$/ if ( $ip = qr/\d+\.\d+\.\d+\.\d+/, $host = qr/[\_\.\-\w]+/, $msg = qr/.*/ ); '4.2.2.2 my_host printer (lp1) is on fire!!!' =~ $re and return $3,$2,$1;Since Modern::Perl means using strict, the above won't fly anymore, and so I use the following which accomplishes the same indent-hiding, however we've now vertically separated the variable declaration for $re from the value as we understand it on the screen :
my $re = eval { my $ip = qr/\d+\.\d+\.\d+\.\d+/; my $host = qr/[\_\.\-\w]+/; my $msg = qr/.*/; return qr/^($ip) ($host) ($msg)$/; }; '4.2.2.2 my_host printer (lp1) is on fire!!!' =~ $re and return $3,$2,$1;
I'm not psyched. Any ideas for improvement?