Solved

generating number sequence in Perl or PHP

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

744 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

11 Experts available now in Live!

Get 1:1 Help Now