Perl-Sensitive Sunglasses | |
PerlMonks |
Re^3: iterating hash keys?by kcott (Archbishop) |
on Sep 28, 2013 at 06:29 UTC ( [id://1056105]=note: print w/replies, xml ) | Need Help?? |
"Well, comparing to what I had, your code is faster than the speed of light!" That's a good start. :-) "Is there a simple way for the s// to also include names with hyphens in the middle?" The short answer is: yes. The longer answer depends on details. I found a reference you made to input data with hyphens in "Re^8: using hashes"; however, you provided no indication of the output you wanted (except that 20-10,25 was the wrong output when bana-na,banana was the input). The following is based on the code I provided earlier. Given these input files:
If you want output like this:
Change
to
If you want output like this:
Change
to
and
to
If you want something different to these, and are unable to work it out for yourself, provide details as outlined in the "How do I post a question effectively?" guidelines. It would also be useful to advise what version of Perl you're using: I wrote those changes for v5.8; a more efficient version could have been written for a later version. As a hint for doing this yourself, see (?<=pattern) \K under Look-Around Assertions in "perlre: Extended Patterns" — \K was introduced in v5.10.0 (see "perl5100delta: Regular expressions" for this, and other, regex enhancements). -- Ken
In Section
Seekers of Perl Wisdom
|
|