Solved

generating number sequence in Perl or PHP

Posted on 2008-06-24
5
648 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now