Welcome to WebmasterWorld Guest from 54.234.153.186

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Search for abcNUMBERdef, make it a variable, then do math?

     

Jesse_Smith

2:31 am on Jan 22, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How do you make perl search for say today([^&]+)today, where ([^&]+) is any number, then make it a variable, for example $12345. Then change it to 123.45, and then do math to it, 123.45*.40 = 49.38 with 49.38 being what the $12345 variable is at the end?

Is it possible to change

$id2 =~ s*today([^&]+)today*$1*g;

so it creates the $12345 variable?

Jesse_Smith

5:35 am on Jan 22, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What perl is searching is...

Today: today408today
Clicks: 34
Yesterday: yesterday555yesterday
Clicks: 61
This Month: this11360this
Clicks: 812
Last Month: last5350last
Clicks: 454

where the numbers are always changing, and I've come up with...

$id3 =~ /today(d+)today/;
my $ans = $1 * .40;
$final = ($ans / 100);

$id4 =~ /yesterday(d+)yesterday/;
my $ans2 = $2 * .40;
$final2 = ($ans2 / 100);

$id5 =~ /this(d+)this/;
my $ans3 = $3 * .40;
$final3 = ($ans3 / 100);

$id6 =~ /last(d+)last/;
my $ans4 = $4 * .40;
$final4 = ($ans4 / 100);

{
print "Content-Type: text/html\n\n";
print <<EOM;
<PRE>
$id2
<HR>
Original Number: $1 - $2 - $3 - $4
<HR>
After it's been converted: $ans - $ans2 - $ans3 - $ans4
After being divide by 100: $final - $final2 - $final3 - $final4


which spits out

spits out

Original Number: 5350 - - -
After it's been converted: 2140 - 0 - 0 - 0
After being divide by 100: 21.4 - 0 - 0 - 0

only messing with the last number, last5350last.

Software error:

Can't locate /home/deploy/webmasterworld/code_format-v6.lib in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at decode-post-v6.lib line 27, <THREADDAT> line 4.

For help, please send mail to the webmaster (it@imninjas.com), giving this error message and the time and date of the error.