Oh, great. Definition by example. And we get one whopping
complete example, the other examples just show strings,
but not what needs to be matched.
Please consider defining what you want. Usually, once you
give a good definition instead of a single example, it's
easy to write a regex. By just giving a example, you run
the risk you get 10 replies, all different. All will match
your example, and all will fail on the other 1000 matches
you need to perform. Some examples of regex that will match
your example:
/^(.{5})/
/(gedit)/
/(\w+)/
/([^-]+)/
/(.\w{3}.)/
That's the danger of describing your problem with only a
single example.
Abigail | [reply] [d/l] |
| [reply] |
$name = (split/-\d/,$string)[0];
Just never use it on anything that starts with -\d.
antirice The first rule of Perl club is - use Perl The ith rule of Perl club is - follow rule i - 1 for i > 1 | [reply] [d/l] |
Question:
Could it be that
($name) = split /-\d/,$string,2;
is more efficient regarding time and/or memory than your solution?
Just wonder because I thought that this will just split into two array elements, thus saving some memory (maybe) but at least some time. | [reply] [d/l] |
Benchmark: running mine, yours for at least 3 CPU seconds...
mine: 3 wallclock secs ( 3.03 usr + 0.00 sys = 3.03 CPU) @ 27
+8704.16/s (n=844822)
yours: 3 wallclock secs ( 3.13 usr + 0.00 sys = 3.13 CPU) @ 34
+5612.45/s (n=1082739)
Rate mine yours
mine 278704/s -- -19%
yours 345612/s 24% --
antirice The first rule of Perl club is - use Perl The ith rule of Perl club is - follow rule i - 1 for i > 1 | [reply] [d/l] |