Solved

generating number sequence in Perl or PHP

Posted on 2008-06-24
5
651 Views
Last Modified: 2011-09-20
How do I create a file with a million(-1) of lines like these in Perl or PHP?

pippo000001
pippo000002
pippo000003
pippo000004
pippo000005
pippo000006
pippo000007
pippo000008
pippo000009
pippo000010
pippo000011
pippo000012
pippo000013

...
pippo999999
0
Comment
Question by:lucavilla
[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
  • 2
  • 2
5 Comments
 
LVL 1

Assisted Solution

by:morristhebear
morristhebear earned 100 total points
ID: 21858772
This should do it.  Obviously change the file name.  This places each pippoxxx on a newline.

<?php
 
	if ($file = fopen ("C:\\file2.txt", "w")) {
		for ($i = 0; $i < 100000; $i++) {
			fwrite ($file, 'pippo' . str_pad($i, 6, '0', STR_PAD_LEFT) . PHP_EOL);
		}
	}
	
?>

Open in new window

0
 
LVL 1

Expert Comment

by:morristhebear
ID: 21858782
Oh, silly me.  Change the 100000 to 1000000.  I used 100000 for testing.
0
 
LVL 84

Accepted Solution

by:
ozo earned 400 total points
ID: 21859134
perl -le "print for pippo000001 .. pippo999999" > file
0
 

Author Closing Comment

by:lucavilla
ID: 31470297
Wow, I love the simplicity of Perl! :)
0
 

Author Comment

by:lucavilla
ID: 21860561
I posted a new similar question here: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_23512022.html

Thanks again for your help!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

749 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