/[clipping]/bin/import.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /bin/import.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Fri Jan 16 22:46:52 2004 UTC (20 years, 3 months ago) by dpavlin
Branch point for: MAIN, phperl
File MIME type: text/plain
Initial revision

1 dpavlin 1.1 #!/usr/bin/perl
2    
3     # Import data from CSV file
4     # (first line should describe data structure)
5    
6     use strict;
7    
8     my @file = <>;
9     my $header = shift(@file);
10     chomp $header;
11    
12     $header =~ s/^\s*#\s*//;
13    
14     my @fields = split (";", $header);
15    
16     my ($t_name, @valid_fields);
17    
18     # $t_name = 'c_customer';
19     # @valid_fields = qw (c_customer_name c_customer_phone c_customer_email c_customer_notes);
20    
21     # $t_name = 'c_source';
22     # @valid_fields = qw (c_source_description c_source_notes);
23    
24     # $t_name = 'c_type';
25     # @valid_fields = qw (c_type_description c_type_notes);
26    
27     # $t_name = 'c_news';
28     # @valid_fields = qw (c_news_section c_news_page c_news_title c_news_abstract c_news_full_text);
29    
30    
31     die unless defined $t_name;
32     die unless defined @valid_fields;
33    
34     foreach my $f (@file) {
35     chomp $f;
36    
37     my @f = split (";", $f);
38    
39     my %f = ();
40     foreach (@fields) {
41     $f{$_} = shift (@f);
42     }
43    
44     print "INSERT INTO $t_name (" .
45     join (",", @valid_fields) .
46     ") VALUES (" .
47     join (",", map ("'$f{$_}'", @valid_fields)) . ");\n";
48     }

  ViewVC Help
Powered by ViewVC 1.1.26