Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: string functions

by Samy_rio (Vicar)
on Oct 25, 2006 at 09:32 UTC ( [id://580520]=note: print w/replies, xml ) Need Help??


in reply to string functions

Hi valavanp, Try like this,

use strict; use warnings; my $str = "2A2B2C"; my %p = (A => 1.5, B => 2.5, C => 3.5); my @arr = split/(?=\d+)/, $str; my $range = 50; map{s/^(\d+)([^\d]+)$/(($p{$2}."\*") x $1)."$range\/100"/e; $range+=5; +}@arr; $str = eval join'*', @arr; print $str;

Updated
valavanp, see below for The range is (50,55,60,65,70,75,80,85,90). How can i code that. your solutions.

use strict; use warnings; my $str = "2A2B2C"; my %p = (A => 1.5, B => 2.5, C => 3.5); my @arr = split/(?=\d+)/, $str; my @range = (50,55,60,65,70,75,80,85,90); my $i =0; map{s/^(\d+)([^\d]+)$/(($p{$2}."\*") x $1)."$range[$i]\/100"/e; $i++;} +@arr; $str = eval join'*', @arr; print $str;

Regards,
Velusamy R.


eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://580520]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2024-04-24 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found