codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  need help writing a simple perl script  ashylarry at 15:34 on Thursday, July 27, 2006
 

I'm not a programmer, so I need some help with a task I need to accomplish. Hopefully one of you perl experts out there can help me out here.

I have a file containing about 1000 or so large, out of sequence numbers in a single column that I need to do the following with:

Convert the list of numbers:
125
23
291
95
5
etc...

to a two-column list of all possible number pairings:
125 23
125 291
125 95
125 5
23 291
23 95
23 5
291 95
291 5
95 5
etc...

Can anyone provide me a script that would do this? I know it would involve putting the numbers into an array and then iterating over the array in a nested loop, but I have no idea how to actually code this.

Thanks in advance!!

  Re: need help writing a simple perl script  javabits at 07:52 on Friday, August 11, 2006
 

Something like this would work.

assuming the numbers are in a file called test.input.

If you don't want the number to pair with itself you have to do a bit more work. but you weren't really clear on that point.

#!/usr/bin/perl
open FILE, "< test.input" or die "Can't open file";

my @f = <FILE>;
close F;

foreach ( @f ) {
chomp;
$outer = $_;
foreach ( @f ) {
chomp;
print "$outer $_\n";
}
}








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  static asp url by 404 custom error code for Search Engine
•  Newbie needs Help
•  Need expertise - converting
•  Re: link spider
•  Re: Yahoo Tabbed menu control
•  Re: Insert Contents of .txt file into a .html page
•  Re: strange Perl loop
•  Re: need help writing a simple perl script
•  Pass a variable to open popup window w/o forms


Recent Articles
What is a pointer in C?
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net


© Copyright codetoad.com 2001-2006