Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Underscores in numbers

by pegasus (Beadle)
on Apr 12, 2001 at 21:34 UTC ( [id://72112]=perlquestion: print w/replies, xml ) Need Help??

pegasus has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I'm working my way through "Learning Perl" and ran into something on page 140, where they discuss modifying timestamps. $atime = $mtime = 700_000_000;

This seemed weird to me, so I tried it out.

!#/usr/bin/perl my $atime; my $ntime; $atime = $mtime = 700_000_000; print "atime = $atime\nmtime = $mtime\n";

This works with or without the underscores.

I've seen the underscores used in several places (books, articles, etc). What's the significance of the underscores and (since Perl seems to work without them) why do people use them? Is it just a visual convenience?

Replies are listed 'Best First'.
Re: Underscores in numbers
by damian1301 (Curate) on Apr 12, 2001 at 21:42 UTC
    Notice that there is an underscore after each 3 numbers, where a comma would usually be. The significance of the underscore is just a substitute for the comma in an unquoted string. Don't get worked up about it. It is just a visual convenience because it helps you distinguish between 700 million and 70 million by just counting the underscores.

    Almost a Perl hacker.
    Dave AKA damian

    I encourage you to email me
Re: Underscores in numbers
by suaveant (Parson) on Apr 12, 2001 at 21:43 UTC
    Perl allows you to use underscores for legibility in numbers, it is there in place of commas, since commas are list separators so can't be used for legibility in numbers
                    - Ant

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://72112]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found