Hola, me presento: soy Rafael, estoy aprendiendo Perl, la verdad soy muy nuevo en esto.
Éste lo acabo de hacer pero está sujeto a cambios y mejoras. Por lo pronto solo lee el archivo y lo inserta en una tabla de MySQL, por si a alguien le sirve.
Using perl Syntax Highlighting
#!/usr/bin/perl -w
use warnings;
use strict;
use lib '/modules';
use azdb;
my $dbh = azdb->connect_callcenterdb();
my @lines = ();
my $line = "";
open( CSV, "<", "tablacsv1.csv" ) or die("Can not open input file: $!");
@lines = <CSV>; #Lines
close(CSV);
my @data = parse_csv( shift(@lines) );
foreach my $line (@lines) {
@data = parse_csv($line); #
$dbh->do("INSERT INTO test.pruebarafa VALUES (null, '$data[0]', '$data[1]', '$data[2]', '$data[3]', '$data[4]')");
print "INSERT INTO test.pruebarafa VALUES (null, '$data[0]', '$data[1]', '$data[2]', '$data[3]', '$data[4]' ";
#Returns an array with all the fields of a row from the csv file
sub parse_csv {
my $text = shift;
my @new = ();
push( @new, $+ ) while $text =~ m{
"([^\"\\]*(?:\\.[^\"\\]*)*)",?
| ([^,]+),?
| ,
}gx;
#The regex above splits each file by comma and ignores a comma between " "
push( @new, undef ) if substr( $text, -1, 1 ) eq ',';
return @new;
}
}
Estoy tratando de hacer un sistema que lea archivo CSV y los guarde en sus propias tablas,
para mostrarlos acomodados en un Website. Son web
schedules lo que quiero hacer.