in reply to Re: Processing CSV File
in thread Processing CSV File
Thanks for the response.. I did the following;
#!/usr/bin/perl # $template_file_name="rtr-template.txt"; open(OFILE, "> test") || die "output config file $ofile_name: $!\n"; while(<>) { ($location, $name, $lo0ip, $frameip, $framedlci, $eth0ip, $x) = split (/,/); open(TFILE, "< $template_file_name") || die "config template file $ +template_file_name: $!\n"; $ofile_name = $name . ".txt"; while (<TFILE>) { s/##location##/$location/; s/##rtrname##/$name/; s/##eth0-ip##/$eth0ip/; s/##loop0-ip##/$lo0ip/; s/##frame-ip##/$frameip/; s/##frame-DLCI##/$framedlci/; printf OFILE $_; } }
I tried just moving the line as is, but since $ofile_name hadn't been defined yet, that would't work.. so i replaced the variable with 'Test' This creates a file called Test with the information required.. however still only processes the first line of the CSV - as i guess is expected, as it is emulating the same problem as before.. If i move the line "$ofile_name = $name . ".txt";" to the top aswell, so it looks like:
#!/usr/bin/perl # $template_file_name="rtr-template.txt"; $ofile_name = $name . ".txt"; open(OFILE, "> test") || die "output config file $ofile_name: $!\n"; while(<>) { ($location, $name, $lo0ip, $frameip, $framedlci, $eth0ip, $x) = split (/,/); open(TFILE, "< $template_file_name") || die "config template file $ +template_file_name: $!\n"; while (<TFILE>) { s/##location##/$location/; s/##rtrname##/$name/; s/##eth0-ip##/$eth0ip/; s/##loop0-ip##/$lo0ip/; s/##frame-ip##/$frameip/; s/##frame-DLCI##/$framedlci/; printf OFILE $_; } }
then when i run the code, I don't get any files outputted.. Do you have any ideas, what is going on... Thanks again
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Processing CSV File
by Kenosis (Priest) on Oct 03, 2012 at 07:57 UTC | |
by Perl3r (Novice) on Oct 04, 2012 at 00:21 UTC | |
by Kenosis (Priest) on Oct 04, 2012 at 18:09 UTC | |
by Anonymous Monk on Oct 05, 2012 at 00:44 UTC | |
by Kenosis (Priest) on Oct 05, 2012 at 01:13 UTC | |
|
In Section
Seekers of Perl Wisdom