Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.1.1 Printing Numeric Literals

As with string literals, you can also use the print function in Perl to print numerical literals. Consider this program:

#!/usr/bin/perl use strict; use warnings; print 2E-4, ' ', 9.77E-5, " ", 100.00, " ", 10_181_973, ' ', 9.87E9, " ", 86.7E14, "\n";
which produces the output:
0.0002 9.77e-05 100 10181973 9870000000 8.67e+15

First of all, we have done something new here with print. Instead of giving @builtin{print} one argument, we have given it a number of arguments, separated by commas. Arguments are simply the parameters on which you wish the function to operate. The print function, of course, is used to display whatever arguments you give it.

In this case, we gave a list of arguments that included both string and numeric literals. That is completely acceptable, since Perl can usually tell the difference! The string literals are simply spaces, which we are using to separate our numeric literals on the output. Finally, we put the newline at the end of the output.

Take a close look at the numeric literals that were output. Notice that Perl has made some formatting changes. For example, as we know, the _'s are removed from 10_181_973. Also, those decimals and large integers in exponential notation that were relatively reasonable to expand were expanded by Perl. In addition, Perl only printed 100 for 100.00, since the decimal portion was zero. Of course, if you do not like the way that Perl formats numbers by default, we will later learn a way to have Perl format them differently (see section 2.5 Output of Scalar Data).




 
 
  Published under the terms of the GNU General Public License Design by Interspire