Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > substitution with computed replacements

Reply
Thread Tools

substitution with computed replacements

 
 
fred
Guest
Posts: n/a
 
      08-03-2009
I took this from Minimal perl by Tim Maher.

s/\d+ /$& * 1.6/ge

I am trying to add numbers instead of converting miles to KM.

input
2 3 4 1
3 4 6

output
2 3 4 1 = 10
2 4 6 = 12

1. What would the replacement part be ?
2. What should the seach part be if we have ten numbers instead of
four?

Thanks
 
Reply With Quote
 
 
 
 
kappa
Guest
Posts: n/a
 
      08-09-2009
On 3 Aug., 16:57, fred <(E-Mail Removed)> wrote:
> I took this from Minimal perl by Tim Maher.
>
> s/\d+ /$& * 1.6/ge
>
> I am trying to add numbers instead of converting miles to KM.
>
> input
> 2 3 4 1
> 3 4 6
>
> output
> 2 3 4 1 = 10
> 2 4 6 = 12
>
> 1. What would the replacement part be ?
> 2. What should the seach part be if we have ten numbers instead of
> four?
>
> Thanks


If you want to practice regexp stuff:

kappa@kappa:~$ head -2 /etc/hosts | perl -lne 'use List::Util "sum";
@a = /(\d+)/g; print "@a = ",sum @a'
127 0 0 1 = 128
127 0 1 1 = 129
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DVD Rental Licenses: Perpetual plus cheap replacements? Dee V. Dee DVD Video 3 03-26-2005 07:53 PM
Sony InfoLithium Battery Replacements Mike Schudel Digital Photography 2 07-22-2004 12:52 AM
Replacements For Single-Disk Failures In Box-Sets? Confessor DVD Video 12 07-09-2004 05:12 PM
Replacements for BP-511 for Canon cameras Rick Langston Digital Photography 12 03-07-2004 04:03 PM
Possible to get replacements for lost discs? SoHillsGuy DVD Video 1 08-17-2003 11:59 PM



Advertisments