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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automated script to generate data 2

Status
Not open for further replies.

ksdh

Technical User
Oct 24, 2007
41
0
0
IN
Can anyone help me develop a perl script to generate a data of lets say 1000 subscribers, having 26 fields. an example would be 262020410000001;MMC;5;01620450752;CDDDDDDAAPOLCU;CDDDDDAAPOLLO;CDDDDDAAWKACU;CDD
DDDDAAWKAUS;CDDDDDDACYBIMM;Mannesmann Mobilfunk GmbH;200016666666;Vodafone;N;N;N
;N;;;UCCCCCCCC;Y;ROAMTIOT;;;;;C

I want to change the 1st feild, 2nd field, 4th feild .
Thanks
Kanav

 
Your requirement is not clear. What have you tried so far?
Have a look at Perl split() function.

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Hello Spookie
I am sorry , i am very new to perl scripting, i dont really have much idea about this in perl, which is why i wanted to get some response in the unix forum. But thats fine, can i request you to guide me through the process please.
I just want to generate a data file (lets say we increment the 1st and 4th feild by 1 each time for 1000000 records and for the second feild, i have 4 values (alpha) which need to occour randomly .

Any help is appreciated
Thanks
Kanav
 
what woould the very first line of the file look like? And what are the 4 random values?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
If you only want to change three of the items exactly as you described, this should do the trick. I am not sure what your 4 interchangeable values are for the second field, but the first and fourth fields are incremented. Everything else remains static.

Since you are unfamiliar with perl I tried to make this relatively simple. The configurations can be changed at the top. A more robust script to allow any of these fields to be incremented or randomized would not be hard to write but it doesn't sound like you need it.

This will overwrite any existing file with the same name.

Code:
use strict;

[COLOR=grey]# These are the configurations that you requested[/color]
my %config = (
  alpha => [[COLOR=green]'MMC','RS-MMC','miniSD','microSD'[/color]],  [COLOR=grey]# Your 4 alpha values[/color]
  field1 => [COLOR=green]262020410000001[/color],                     [COLOR=grey]# The value that field 1 should start at[/color]
  field4 => [COLOR=green]01620450752[/color],                         [COLOR=grey]# The value that field 4 should start at[/color]
  iterations => [COLOR=green]1000000[/color],                         [COLOR=grey]# The number of iterations[/color]
  filename => [COLOR=green]'generatedData.dat'[/color]                [COLOR=grey]# The path to the data file you are creating[/color]
);

open (DATAFILE, ">$config{filename}") || die ("Cannot create file");

for (1..$config{iterations}) {
  [COLOR=grey]# Choose a random entry from the alpha array[/color]
  my $alpha = $config{alpha}->[int rand @{$config{alpha}}];

  [COLOR=grey]# Print the standard data with the changing configurations[/color]
  print DATAFILE "$config{field1};$alpha;5;$config{field4};CDDDDDDAAPOLCU;CDDDDDAAPOLLO;" .
                 "CDDDDDAAWKACU;CDDDDDDAAWKAUS;CDDDDDDACYBIMM;Mannesmann Mobilfunk GmbH;" .
                 "200016666666;Vodafone;N;N;N;N;;;UCCCCCCCC;Y;ROAMTIOT;;;;;C\n";

  [COLOR=grey]# Increment the changing fields[/color]
  $config{field1}++;
  $config{field4}++;
}

close (DATAFILE);
 
HI Colorplane

i got the following error, while trying to run the file:

syntax error at ./kd.pl line 9, near "filename"
Execution of ./kd.pl aborted due to compilation errors

could you advise on this please?


Thanks
Kanav
 
sorry mate, thats resolved now. It was my fault, i just missed a comma at the end of a line. It works now? Cheers colorplane
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top