All pastes #495565 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-05-18 20:33 UTC
rendered paste body
#!/usr/bin/perl -w
use strict;
use warnings;
use Text::CSV;
my $debug = 1;

my $file = 'hosts.csv';

my $csv = Text::CSV->new();

open (CSV, "<", $file) or die $!;

while (<CSV>) {
next if ($. == 1);
if ($csv->parse($_)) {
my @columns = $csv->fields();
print "define host{\n\tuse\t\t$columns[3]\n\thost_name\t$columns[0]\n\talias\t\t$columns[1]\n\taddress\t\t$columns[2]\n\tregister\t1\n\t}\n";}
else {
my $err = $csv->error_input;
print "Failed to parse line: $err";
}
}
close CSV;