Perl script to create csv files with a pattern – Generic script.
I was having a really bad day and needed a quick solution to create some csv files. And this I needed to do for multiple data kinds and patterns, so I created this small script to do the job for me…
#Number of rows required in the output.
$rows = 100;
#The config and the output file
open (CF_FILE, ”<Config.test”);
open (OUT_FILE, ”>test.csv”);#—————————————————————————
# No need to change anything below this.
#—————————————————————————$count = 0 ;
#read a line from <a class="zem_slink freebase/en/configuration_file" title="Configuration file" rel="wikipedia" href="http://en.wikipedia.org/wiki/Configuration_file">config file of the type
#also any line starting with # is treated as comment.
# startingvalue incrementvalue
# so you can have any number of fields here and all of them you would be joined with , to write to the output file.
while (<CF_FILE>)
{
/^#/ && next;
chomp();
@vars = split(/ /);
$arr[$count] = $vars[0];
$arr_inc[$count] = $vars[1];
$count++;
}
for ($i=0; $i < $rows; $i++)
{
$line = join (”,”,@arr);
print OUT_FILE ”$line\n”;
for ($j=0; $j < $count; $j++)
{
$arr[$j] += $arr_inc[$j];
}
}<div class="zemanta-pixie"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/ed184035-8325-46df-9cb2-05553f9f59d0/"><img class="zemanta-pixie-img" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/reblog_b5.png" alt="Reblog this post [with Zemanta]" /><span class="zem-script more-related more-info pretty-attribution paragraph-reblog">
Related Articles:
- 2010/01/04 Display the output of a command from the first line until the first instance of a regular expression.
- 2009/11/17 Calculations
- 2009/11/21 5 Sites To Find Free Alternatives To Popular Software
- 2009/10/05 Tag2Find – Tag Your Windows Files with Web-like Tags
- 2009/08/12 Consider your account to be for you then use Linux