Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Underscores in numbers

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

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


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?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2021-10-22 20:24 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (85 votes). Check out past polls.