Solved

generating number sequence in Perl or PHP

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

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 …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

803 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