3 ms·
($hour, $min, $sec) = $someTimeString =~ /(\d\d):(\d\d):(\d\d)/; if ($hour >= 12) { if ($min == 42) { doSomething(); } } Where
by marai2 3y ago
($hour, $min, $sec) = $someTimeString =~ /(\d\d):(\d\d):(\d\d)/;
if ($hour >= 12) {
if ($min == 42) {
doSomething();
}
}
Whereas in Python, Ruby even though it's only a tiny extra step, but that symantic distance in one's head when parsing out and naming the parts of a regex on the same is a convenience that when you get used to it, you really miss it.
m = /(\d\d):(\d\d):(\d\d)/.match( someTimeString )
hour = m[0]
min = m[1]
sec = m[2]
if hour >= ...
- riffraff 3y agobut ruby, python etc.. can just extract the list too, it's just an extra method call on the same object (perhaps there could be destructuring too in modern ruby/python) hour, min, sec = /(\d\d):(\d\d):(\d\d)/.match('10:11:12').captures or hour, min, sec = re.compile(r'(\d\d):(\d\d):(\d\d)').match('10:11:12').groups() ruby & python will explode if there is no match rather than fail silently but I'm not convinced the difference is huge.