on Mon, Jul 02, 2001 at 01:20:05PM -0700, David Freeman scribbled:
(/-l\s*([^-]+)/) && do { my $orig_chain = $1; my $chain = join(',', map {$_ if (!/^$/);} split(/ /, $1));
$chain =~ s/(?<![^,])0(?![^,])/*/g; s/$orig_chain/$chain /g;
};
the first line is a classic example of why its write only code, WTF does the (/-l\s*([^-]+)/) mean?
First line is valid in sed, if you change it to /-l *([^-]{1,})/.
If you ommit the lhs, perl uses $_. So (/-l\s*([^-]+)/) is effectively ($_ =~ /-l\s*([^-]+)/) which, if it matches, evaluates and returns true. Since && requires both sides to be true, then only if it matches is the do {} executed. Yes, it could all be rewritten as: if ($_ =~ /-l\s*([^-]+)/) { ... } but i prefer the other way.
/-l\s*([^-]+)/: 0) Match -l followed by zero or more space characters. 1) Add everything between ( and ) to the pattern buffer $1 where [^-]+ is one or more non dash character.
Arguably one of the neatest parts of perl is it's inherent regexes although if you don't know perlre(1) well it can be confusing.
This code basically converts the string "-m -l 0 blah b0df 0 blah 0 -t" to "-m -l *,blah,b0df,*,blah,* -t" (this is for getting mixmaster remailer chains 2.9beta23 to work with mutt..)