Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I multiply negative number with Perl?

Posted on 2003-11-23
3
Medium Priority
?
1,019 Views
Last Modified: 2013-12-25
I need to multiply a variable that contains a negative value by negative one.  Such as $test=(-1*$amount) where amount is negative.  I can't even get print "Test (-1*$amount)"; to work.  This prints: -1*-300.  
0
Comment
Question by:Shearer-Services
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 100 total points
ID: 9807635

Either do

$test = -1 * $amount;
print "$test\n";

or

print -1 * $amount , "\n':

0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 100 total points
ID: 9808762
 $test=(-1*$amount) ;
should work.
so would
  $test = -$amount;

  print "Test (-1*$amount)";
will just print the "Test (-1*" litterally
perhaps you meant
  print "Test", -1*$amount,"\n";
0
 

Author Comment

by:Shearer-Services
ID: 9810319
Despite my typo, you both helped answer the question.  Thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question