regex to convert 1000000 -> 1,000,000 ?

B

bad_knee

Hello,
I was wondering if anyone had a quick one for "commatizing" a
number in perl?

Thanks
 
B

Brian McCauley

I was wondering if anyone had a quick one for "commatizing" a
number in perl?

By a strange coincidence, I was wonding if "anyone" ever reads the
FAQ.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
B

bad_knee

Hello,
I was wondering if anyone had a quick one for "commatizing" a
number in perl?

Thanks

Sheesh.. thought this would be an easy one for you guys.
Oh well, for anyone interested...

$number = "10001324512461346234500";
$sep = ",";
$number =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1$sep/g;
print "num:$number\n";

cheers!
 
J

Jürgen Exner

bad_knee said:
(e-mail address removed) (bad_knee) wrote in message


Sheesh.. thought this would be an easy one for you guys.

What do you mean?
Is there anything wrong with the answer given in the FAQ?
perldoc -q comma: "How can I output my numbers with commas added?"

jue
 
J

James Willmore

On 15 Nov 2003 05:38:41 -0800
(e-mail address removed) (bad_knee) wrote in message
Hello,
I was wondering if anyone had a quick one for "commatizing" a
number in perl?

Thanks

Sheesh.. thought this would be an easy one for you guys.
Oh well, for anyone interested...

$number = "10001324512461346234500";
$sep = ",";
$number =~
s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1$sep/g; print
"num:$number\n";

cheers!

I'm glad to see you looked at the FAQ for yourself - since this is
where you got the answer to your own question.

perldoc -q 'How can I output my numbers with commas added'

If this was supposed to be a test, you should have said so in your
post - so we could plonk you earlier :)

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Eighty percent of air pollution comes from plants and trees. --
Ronald Reagan, famous movie star
 
W

Wally Sanford

Brian said:
By a strange coincidence, I was wonding if "anyone" ever reads the
FAQ.

And as usual, you miss the point that most new people would not have
_knowlege_ of na faq. It's like when ou go to a new place. Say, you move
to a new state, go to a new school, you know not wher anything really
is, you tend to ask around "hey, do you know where I can find this or
that?". You _can't_ expect every new person to know where to find
everything, becuase they may not even know of the exisitance of such a
tool.

Nothing wrong with pointing them ot an FAQ, but chastizing a new person
for not checking an FAQ they may not know about is just plain mean
spirted and absurd (need I mention arrogant?) If you find your self
wanting to post something ill spirited like this it may be better to
just stfu. I dont give a flying crap how helpful you overwise are.

There is nothing wrong with being new. One must start somewhere.
 
S

Sam Holden

And as usual, you miss the point that most new people would not have
_knowlege_ of na faq. It's like when ou go to a new place. Say, you move
to a new state, go to a new school, you know not wher anything really
is, you tend to ask around "hey, do you know where I can find this or
that?". You _can't_ expect every new person to know where to find
everything, becuase they may not even know of the exisitance of such a
tool.

School's tend not to have FAQs, so that's a pretty stupid analogy.

And of course posting to usenet is more like asking "where is the canteen"
over the school PA system, or from the middle of the playground with a
megaphone. See how well that goes down.
Nothing wrong with pointing them ot an FAQ, but chastizing a new person
for not checking an FAQ they may not know about is just plain mean
spirted and absurd (need I mention arrogant?) If you find your self
wanting to post something ill spirited like this it may be better to
just stfu. I dont give a flying crap how helpful you overwise are.

There is nothing wrong with being new. One must start somewhere.

And one starts by reading the documentation for the language, compiler,
software package, whatever it is you are new to. For perl the FAQ
is a big chunk of that documentation and pretty hard to miss, unless
of course you didn't bother looking at any of the documentation.
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

And as usual, you miss the point that most new people would not have
_knowlege_ of na faq. It's like when ou go to a new place. Say, you move
to a new state, go to a new school, you know not wher anything really
is, you tend to ask around "hey, do you know where I can find this or
that?". You _can't_ expect every new person to know where to find
everything, becuase they may not even know of the exisitance of such a
tool.

On the other hand, usenet is an established community with an established
culture, and ignoring the culture of the place you're visiting is most
definitely rude.

- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP7bC9WPeouIeTNHoEQIg4QCg6kFeBr+oLvD72aWGEcp6eDBWRLQAoKIA
Prkt90Zc7z603nNX81ZWCfCn
=3zoC
-----END PGP SIGNATURE-----
 
W

Wally Sanford

Sam said:
And one starts by reading the documentation for the language,
compiler, software package, whatever it is you are new to. For perl
the FAQ
is a big chunk of that documentation and pretty hard to miss, unless
of course you didn't bother looking at any of the documentation.

Actually, the whole situation is like this: Perl is like a software
package from a store that has a nice manual that under a hidden panel.
you don't know it's there unless you KNOW it's there.

Someone who is starting will likely not even of heard of "perldoc".

If they are unixsavy they might try something like: $ perl --help | grep
doc
Which doesn not return anything. `$ perl --help` by it self does nothing
to guide you to the docs.

Even grepping the man page for perl doesn't ofer much:

$ man perl | grep doc
perltoc Perl documentation table of contents
perlpod Perl plain old documentation
Extensive additional documentation for Perl modules is
this additional documentation in the
additional documentation is distributed standard with
Perl, but you'll also find documentation for third-party
You should be able to view Perl's documentation with your

So a newbie might be inclined to try

$ perltoc
bash: perltoc: command not found

And `$ man perl | grep perldoc` return nothing, but the point is they
have to first KNOW of perldoc.

$ man perl | grep help
you're not sure where you should look for help, try the -w
Larry Wall <[email protected]>, with the help of oodles of
help to others who wish to advocate the use of Perl in
help mail in a bug report.

This could bery well lead

$ help perl
bash: help: no help topics match `perl'. Try `help help'.

Many newsbies could of installed some linux distro that came with Perl
and they decide on exploring it. Looking for documentation seems to be
more then a trivial task.

So, just short of going to www.perl.org, how is one suppost to know of
perldoc and it's faq's off the bat?

It's not a question of a newsgroup being like a coutry or whatever, but
the lack of self advertising of perldoc it self. The fact thast there is
no mention of it in the man page doing simple greps is unacceptable.

Expecting someone to of read documentation thats buried in a way that
you didnt even know it was there in the "box" is what is unacceptable.

Now that I think about it, I never even heard of perldoc until I first
read this group a good some time ago.
 
C

Chris Mattern

So, just short of going to www.perl.org, how is one suppost to know of
perldoc and it's faq's off the bat?

Well, if you come to this group, the posting guidelines, posted twice
every week, if you *read* the group before *post* to it, like you should
(remember why the good Lord gave two ears and only one mouth!)

Your points about the difficulty of finding perldoc are well taken.
But it doesn't excuse clueless posts, because people who have found
this newsgroup have found the key to finding perldoc if they will
*read*.

Chris Mattern
 
W

Wally Sanford

Chris said:
Well, if you come to this group, the posting guidelines, posted twice
every week, if you *read* the group before *post* to it, like you
should (remember why the good Lord gave two ears and only one mouth!)

Twice a week? I have seen them posted at all the last few months. I have
been through 3 different isp's so that is not limited to just my news
service. Wehre is this being posted from? Under what name?
Your points about the difficulty of finding perldoc are well taken.
But it doesn't excuse clueless posts, because people who have found
this newsgroup have found the key to finding perldoc if they will
*read*.

Well if other people cannot see the faq being posted as you say, jsut
like it does nto show on my server, then that too is a broken bridge
that cannot be crossed, and would also exaplin why some newbies seem to
give blank stairs when asked why they didnt read it.
 
W

Wally Sanford

Wally said:
Twice a week? I have seen them posted at all the last few months. I
have been through 3 different isp's so that is not limited to just my
news service. Wehre is this being posted from? Under what name?

That should be "I -haven't- seen them ..." Sorry.
 
C

Chris Mattern

Wally said:
Twice a week? I have seen them posted at all the last few months. I have
been through 3 different isp's so that is not limited to just my news
service. Wehre is this being posted from? Under what name?

Tad McClellan posts it, regular as clockwork. Which may explain why he
sometimes gets a mite testy when it seems nobody reads it.

Here's the tally for the previous month:
http://groups.google.com/groups?q=g...fe=off&[email protected]
http://groups.google.com/groups?q=g...fe=off&[email protected]
http://groups.google.com/groups?q=g...fe=off&[email protected]
http://groups.google.com/groups?q=g...fe=off&[email protected]
http://groups.google.com/groups?q=g...fe=off&[email protected]
http://groups.google.com/groups?q=g...fe=off&[email protected]
http://groups.google.com/groups?q=g...fe=off&[email protected]
http://groups.google.com/groups?q=g...fe=off&[email protected]

Eight times in the past month. I've accessed the newsgroup from several
different ISPs and Google, and they've always been there. Not sure how
you missed it.
Well if other people cannot see the faq being posted as you say, jsut
like it does nto show on my server, then that too is a broken bridge
that cannot be crossed, and would also exaplin why some newbies seem to
give blank stairs when asked why they didnt read it.
If it doesn't show on your server, it can only be because your server
is broken, which is scarcely the fault of the Perl documentation or
its maintainers.


Chris Mattern
 
S

Sam Holden

Actually, the whole situation is like this: Perl is like a software
package from a store that has a nice manual that under a hidden panel.
you don't know it's there unless you KNOW it's there.

Someone who is starting will likely not even of heard of "perldoc".

If they are unixsavy they might try something like: $ perl --help | grep
doc
Which doesn not return anything. `$ perl --help` by it self does nothing
to guide you to the docs.

A unixsavy person will type "man perl" which nicely lists all the other
man pages. inclusing perlfaq. A unixsavy person knows what:

"For ease of access, the Perl manual has been split up into several sections."

followed by a list of man page names means.
Even grepping the man page for perl doesn't ofer much:

$ man perl | grep doc
perltoc Perl documentation table of contents
perlpod Perl plain old documentation
Extensive additional documentation for Perl modules is
this additional documentation in the
additional documentation is distributed standard with
Perl, but you'll also find documentation for third-party
You should be able to view Perl's documentation with your

Who greps manpages for "doc"? The manpage is the documentation. You
read it, and in the case of perl read the other pages it tells you
about.
So a newbie might be inclined to try

$ perltoc
bash: perltoc: command not found

If the newbie is an idiot, and uses grep not to search and then check the
context, but to read.

A newbie needs to learn how to read documentation on their system before
they learn how to use perl.
And `$ man perl | grep perldoc` return nothing, but the point is they
have to first KNOW of perldoc.

perldoc is irrelevant, man works just fine and provides access to the
same documentation. Arguably better access due to the wonders of
man -k/apropos.

If someone uses unix and does not know about man, then they should stop
and learn about it *before* doing anything else with unix. Unix is
unusable without it.
$ man perl | grep help
you're not sure where you should look for help, try the -w
Larry Wall <[email protected]>, with the help of oodles of
help to others who wish to advocate the use of Perl in
help mail in a bug report.

This could bery well lead

$ help perl
bash: help: no help topics match `perl'. Try `help help'.

How does that random text lead to trying a "help" command. I see no
reference to such a command. How does it lead to "help perl" more than
it leads to "oodles perl" or "mail perl"?
Many newsbies could of installed some linux distro that came with Perl
and they decide on exploring it. Looking for documentation seems to be
more then a trivial task.

So, just short of going to www.perl.org, how is one suppost to know of
perldoc and it's faq's off the bat?

man perl
man perlfaq
man perlfaq said:
It's not a question of a newsgroup being like a coutry or whatever, but
the lack of self advertising of perldoc it self. The fact thast there is
no mention of it in the man page doing simple greps is unacceptable.

Again, perldoc is irrelevant. man works just fine. It is not the job of
the perl documentation to explain the use of man, that is the job of
"man man" :)

Do you want the perl documentation to include tutorial information on the
use of man, the use of the various microsoft help systems, the use of
a web browser to view HTMLized docs, etc, etc.

Assumming the reader can read documentation on the system they are using
is reasonable. How did they know to how to run perl otherwise? How did they
know how to create a file?

You could always of course upgrade to the current stable version of perl
which does in fact provide a reference to perldoc findable by your strange
"grep the man page for doc" approach to reading manpages:

; man perl | grep doc
Reformatting perl(1), please wait...
gate the rest of Perl's extensive documentation.
perltoc Perl documentation table of contents
perlpod Perl plain old documentation
perlpodspec Perl plain old documentation format specification
perldoc Look up Perl documentation in Pod format
tains the majority of the standard Perl documentation and the perldoc
Extensive additional documentation for Perl modules is available, both
You should be able to view Perl's documentation with your man(1) pro-

Complaining about things which have been fixed has no useful purpose.
Expecting someone to of read documentation thats buried in a way that
you didnt even know it was there in the "box" is what is unacceptable.

It isn't buried.
Now that I think about it, I never even heard of perldoc until I first
read this group a good some time ago.

So what, perldoc isn't important. It provides a nice way of specifying
perl documentation in this newsgroup, saying "perldoc perldata" is
nice since "man perldata" is meaningless on windows.

perldoc is nice for searching the FAQ (though not as nice as grep), but
you aren't meant to search the FAQ at the beginning, you are meant to
*read* it.
 
S

Sam Holden

Sam Holden ([email protected]) wrote on MMMDCCXXVIII
September MCMXCIII in <URL:;;
;; School's tend not to have FAQs, so that's a pretty stupid analogy.


I can't recall in my many years of getting an education to have attended
a school without a student guide full of frequently needed information.

But that isn't a FAQ. Maybe schools in your part of the world are different
than over here. But over here I've never seen something that resembles a FAQ,
something with a list of questions which are have actually been asked
frequently (or even just once) with answers.

Things like:

* Which teacher is most likely to let me leave early?

* Which areas are best avoided if I don't wish to get in a fight at lunch?

* Which toilets are the cleanest?

* On which day are the weekly staff meetings that make it easy to sneak out
at lunch?

* Which computer in the library is fastest?

* How late can I be for roll call?
 
T

Trent Curry

Chris said:
Tad McClellan posts it, regular as clockwork. Which may explain why
he sometimes gets a mite testy when it seems nobody reads it.

Maybe he sould ask if the person he's replying to can even see those
posts?
Eight times in the past month. I've accessed the newsgroup from
several different ISPs and Google, and they've always been there.
Not sure how you missed it.

Apparently hes not the only one.
If it doesn't show on your server, it can only be because your server
is broken, which is scarcely the fault of the Perl documentation or
its maintainers.

Actually I don't see those posts either. I think since so many people
seem to have a problem seeing it, could it be something with Tad's
server not properly propagating posts? Why assume it's someone's else
when it is possible the problem can be at the source. Other then his
posts my server seems to show anything that google shows (and then
some.) Just Tad's posts don't always appear.

--
Trent Curry

perl -e
'($s=qq/e29716770256864702379602c6275605/)=~s!([0-9a-f]{2})!pack("h2",$1
)!eg;print(reverse("$s")."\n");'
 
W

Wally Sanford

Abigail wrote:
[Abigail's Non standard broken quoting fixed;
Btw why do you continue to post like this knowing it breaks many
quoting schemes that readers use, inparticular color coding???]
Wally Sanford ([email protected]) wrote on MMMDCCXXX September
MCMXCIII in URL:

No, if they are Unix savy, they try "man perl", and guess what? On the
second page it mentions the FAQ!

$ man perl | grep -i faq
perlfaq Perl frequently asked questions
perlfaq1 General Questions About Perl
perlfaq2 Obtaining and Learning about Perl
perlfaq3 Programming Tools
perlfaq4 Data Manipulation
perlfaq5 Files and Formats
perlfaq6 Regexes
perlfaq7 Perl Language Issues
perlfaq8 System Interaction
perlfaq9 Networking

It *mentions* perlfaq but says NOTHING of how to *access* it. Thats whe
whole point ehre.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top