Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help needed on another script!

Status
Not open for further replies.

Captainrave

Technical User
Nov 16, 2007
97
GB
Hi have this script:

Code:
use strict;
use warnings;
use Text::CSV_XS;

my $len = shift;
my $csv = Text::CSV_XS->new();

while (<>) {
  $csv->parse($_);
  my ($string, $num, $num2) = $csv->fields();
  print "$string,$num,$num2\n" if (length($string) >= $len);
}

Basically it reads a list of data in the following format:
AAAAAAA 100 200
TTTTTTTTTTT 211 300


If I set the paparmaters at 5 for example it will only output the numbers following 5 letters or more. I run this 15 times individually parameters of 5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 by changing the command:

perl myscript.pl n input.csv > output.csv where n is the modified parameter.

Is there a way to automate this script rather than me running it individually 15 times? As you can imagine it is incredibly time consuming!

Many thanks for any input!
 
I'm not sure If I'm completely clear on what you need, but for iterations u can use a for loop

for ($i = 5; $i<=20; $i++) {
}
 
That script looks vaguely familiar. Anyway, it seem to me that you could probably work this one out yourself with a nudge in the right direction.
Perl:
foreach my $len (5..20) {
   print "output_$len.csv\n";
}
Run that, and go figure...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top