Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: string functions

by Samy_rio (Vicar)
on Oct 25, 2006 at 09:32 UTC ( #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? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2021-12-02 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (23 votes). Check out past polls.

    Notices?