Solved

generating number sequence in Perl or PHP

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
The viewer will learn how to dynamically set the form action using jQuery.

828 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