Perl script to create csv files with a pattern – Generic script.

2010-01-19 197 words 1 min read

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, &#8221;<Config.test&#8221;);
open (OUT_FILE, &#8221;>test.csv&#8221;);

# 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="">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;
@vars = split(/ /);
$arr[$count] = $vars[0];
$arr_inc[$count] = $vars[1];
for ($i=0; $i < $rows; $i++)
$line = join (&#8221;,&#8221;,@arr);
print OUT_FILE &#8221;$line\n&#8221;;
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=""><img class="zemanta-pixie-img" src="" alt="Reblog this post [with Zemanta]" /><span class="zem-script more-related more-info pretty-attribution paragraph-reblog">


Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it