4 ms·
But I don't want functions such as start_with() or startWith()! I'd much rather use regexes, which are more powerful and more expressive, than a mish-mash of te
by wazoox 5y ago
But I don't want functions such as start_with() or startWith()! I'd much rather use regexes, which are more powerful and more expressive, than a mish-mash of tests like
if ( (myvar.startsWith('hello') and myvar.endsWith('world')) or ((myvar.startsWith('Hello') and myvar.endsWith('World'))) {...}
I much prefer
if ( $myvar =~ /^[H|h]ello.*[W|w]orld$/ ) { }
Perl doesn't have these functions because it has better, more powerful tools. It's akin to saying that Python lacks line numbers as GW-BASIC did...
- tyingq 5y agoThey are more powerful and expressive, but are also less efficient and significantly slower for simple things like starts/ends_with(). Benchmark index("abc","ab")==0 vs "abc" =~ /^ab/
- deleted 5y ago[deleted]
- wazoox 5y agoThis is a canonical case of premature optimisation. I have performance problems with the database backend, the network, disk access, but too slow a regex is a completely non-existing problem in real-life for me. Or else I wouldn't be using Perl/PHP/Python/Ruby but C/C++/Rust/Java etc.
- tyingq 5y agoMaybe. Batch processing huge text files is pretty common in Perl.