CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
after substituting given word with respected value i want to do math operation.

 



harshmane
Novice

Jul 17, 2011, 11:54 PM

Post #1 of 2 (959 views)
after substituting given word with respected value i want to do math operation. Can't Post

after substituting given word with respected value i want to do math operation.


like i open 1 file in starting of the file i m having all d word with respected value wich store it in hash and i replace it also now i want to do some mathematical operzation on the same line wheere substitution happen like


Code
 hi=3 ; 
my=4;
before substitution.
hi + my
afetr substitution
3 +4.
now i want
7



BillKSmith
Veteran

Jul 18, 2011, 12:43 PM

Post #2 of 2 (933 views)
Re: [harshmane] after substituting given word with respected value i want to do math operation. [In reply to] Can't Post


Code
use strict; 
use warnings;
my $string = 'hi + my';
my $hi = 3;
my $my = 4;
print $string, "\n";
$string =~ s/hi/$hi/;
$string =~ s/my/$my/;
print $string, "\n";
my $sum = eval($string);
print $sum, "\n";

Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives