|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#46
|
||||
|
||||
|
Your answer wasn't clear to me.
The $row{'column3'} has to match the name of the real column you want to split. Otherwise, it will fail to find any data. Code:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use CGI qw/:standard *table/;
use CGI::Carp qw/fatalsToBrowser/;
print header, start_html, start_table;
my $file = 'tsv_parse.tsv';
{
#local $/ = "\r\n"; #not for you
open my $fh, "<", $file or die "Can't open $file: $!";
my $header = <$fh>;
chomp $header;
my @head = split /\t/, $header;
#print Dumper \@head;
while (<$fh>) {
chomp;
my %row;
@row{@head} = split /\t/;
$row{'column3'} =~ s/"//g;
print h3('ready to split');
my @separators = map {ord($_)} $row{'column3'} =~ m/[^A-Za-z0-9, ]/g;
print table(Tr(td(@separators)));
print start_table;
my @repeat = split /\n/, $row{'column3'};
foreach (@repeat) {
my @data = map {$row{$_} || undef} @head;
$data[2] = $_;
print Tr(td(@data)) if $_ !~ /^\s*$/;
}
print end_table;
}
}
print end_html;
In this version, following the 'ready to split', you should see a line of data. On my computer, all the values are 10. Do you see anything different? Edit: I'm using the tab separated file still. It works for me. The CSV module barfed on the file you provided. May have been because of the embedded new lines. Last edited by keath : April 24th, 2008 at 06:36 PM. |
|
#47
|
|||
|
|||
|
yeah all occurrences of those data in one cell are on column 3.
i tried both files with this code and what happened was TSV outputted 4 lines of 'ready to split' CSV outputted 5 lines of 'ready to split' thx Quote:
|
|
#48
|
|||
|
|||
|
i am using the same file as i sent you and the "column3" as the name is being used. now i understand what you were asking.
Quote:
|
|
#49
|
||||
|
||||
|
Please note my edit above. I'm not using the file you sent. I had to revert to the tab delimited version.
Use a TSV file, and see what the result is. Are yo seeing 10s in the one line, and are you getting any other output below that? This is what I'm getting: Code:
ready to split 10 10 10 10 data1 data2 VISHAY BC COMPONENTS, 2222036 Rule Based Upgrades data4 data5 data6 data7 data8 data9 data10 data11 data12 data13 data14 data15 data16 data1 data2 VISHAY BC COMPONENTS, 2222048 Rule Based Upgrades data4 data5 data6 data7 data8 data9 data10 data11 data12 data13 data14 data15 data16 data1 data2 VISHAY BC COMPONENTS, 2222116 Rule Based Upgrades data4 data5 data6 data7 data8 data9 data10 data11 data12 data13 data14 data15 data16 data1 data2 VISHAY BC COMPONENTS, 2222151 Rule Based Upgrades data4 data5 data6 data7 data8 data9 data10 data11 data12 data13 data14 data15 data16 |
|
#50
|
|||
|
|||
|
i had to save as tsv again and changed the extension to "tsv" like you did. that gave me this instead of just "ready to split":
Code:
ready to split data1 data2 VISHAY BC COMPONENTS, 2222036 Rule Based Upgrades ready to split ready to split ready to split ready to split " data4 data5 data6 data7 data8 data9 data10 data11 data12 data13 data14 data15 data16 Quote:
|
|
#51
|
|||
|
|||
|
what steps should i take to revert the file?
|
|
#52
|
||||
|
||||
|
let me see the full output of this script:
Code:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use CGI qw/:standard *table/;
use CGI::Carp qw/fatalsToBrowser/;
print header('text/text'); #, start_html, start_table;
my $file = 'tsv_parse.tsv';
{
#local $/ = "\r\n"; #not for you
open my $fh, "<", $file or die "Can't open $file: $!";
my $header = <$fh>;
chomp $header;
my @head = split /\t/, $header;
print Dumper \@head;
while (<$fh>) {
chomp;
my %row;
@row{@head} = split /\t/;
$row{'column3'} =~ s/"//g;
print Dumper \%row;
print h3('ready to split');
my @separators = map {ord($_)} $row{'column3'} =~ m/[^A-Za-z0-9, ]/g;
#print table(Tr(td(@separators)));
print Dumper \@separators;
#print start_table;
my @repeat = split /\n/, $row{'column3'};
print Dumper \@repeat;
#foreach (@repeat) {
# my @data = map {$row{$_} || undef} @head;
# $data[2] = $_;
# print Tr(td(@data)) if $_ !~ /^\s*$/;
#}
#print end_table;
}
}
#print end_html;
Put it in CODE tags to preserve the formatting. |
|
#53
|
||||
|
||||
|
Quote:
Ideally, just open Excel again and save as tab-delimited. |
|
#54
|
|||
|
|||
|
Code:
$VAR1 = [
'column1',
'column2',
'column3',
'column4',
'column5',
'column6',
'column7',
'column8',
'column9',
'column10',
'column11',
'column12',
'column13',
'column14',
'column15',
'column16
'
];
$VAR1 = {
'column16
' => undef,
'column1' => 'data1',
'column2' => 'data2',
'column3' => 'VISHAY BC COMPONENTS, 2222036 Rule Based Upgrades',
'column4' => undef,
'column5' => undef,
'column6' => undef,
'column7' => undef,
'column8' => undef,
'column9' => undef,
'column10' => undef,
'column11' => undef,
'column12' => undef,
'column13' => undef,
'column14' => undef,
'column15' => undef
};
<h3>ready to split</h3>$VAR1 = [];
$VAR1 = [
'VISHAY BC COMPONENTS, 2222036 Rule Based Upgrades'
];
$VAR1 = {
'column16
' => undef,
'column1' => 'VISHAY BC COMPONENTS, 2222048 Rule Based Upgrades',
'column2' => undef,
'column3' => undef,
'column4' => undef,
'column5' => undef,
'column6' => undef,
'column7' => undef,
'column8' => undef,
'column9' => undef,
'column10' => undef,
'column11' => undef,
'column12' => undef,
'column13' => undef,
'column14' => undef,
'column15' => undef
};
<h3>ready to split</h3>$VAR1 = [];
$VAR1 = [];
$VAR1 = {
'column16
' => undef,
'column1' => 'VISHAY BC COMPONENTS, 2222116 Rule Based Upgrades',
'column2' => undef,
'column3' => undef,
'column4' => undef,
'column5' => undef,
'column6' => undef,
'column7' => undef,
'column8' => undef,
'column9' => undef,
'column10' => undef,
'column11' => undef,
'column12' => undef,
'column13' => undef,
'column14' => undef,
'column15' => undef
};
<h3>ready to split</h3>$VAR1 = [];
$VAR1 = [];
$VAR1 = {
'column16
' => undef,
'column1' => 'VISHAY BC COMPONENTS, 2222151 Rule Based Upgrades',
'column2' => undef,
'column3' => undef,
'column4' => undef,
'column5' => undef,
'column6' => undef,
'column7' => undef,
'column8' => undef,
'column9' => undef,
'column10' => undef,
'column11' => undef,
'column12' => undef,
'column13' => undef,
'column14' => undef,
'column15' => undef
};
<h3>ready to split</h3>$VAR1 = [];
$VAR1 = [];
$VAR1 = {
'column16
' => undef,
'column1' => ' "',
'column2' => 'data4',
'column3' => 'data5',
'column4' => 'data6',
'column5' => 'data7',
'column6' => 'data8',
'column7' => 'data9',
'column8' => 'data10',
'column9' => 'data11',
'column10' => 'data12',
'column11' => 'data13',
'column12' => 'data14',
'column13' => 'data15',
'column14' => 'data16
',
'column15' => undef
};
<h3>ready to split</h3>$VAR1 = [];
$VAR1 = [
'data5'
];
|
|
#55
|
||||
|
||||
|
You said you were running this on Windows, but it looks to me that your web server must by a Unix type.
Uncomment this line and run the script again: Code:
local $/ = "\r\n"; |
|
#56
|
|||
|
|||
|
Sorry...
Code:
$VAR1 = [
'column1',
'column2',
'column3',
'column4',
'column5',
'column6',
'column7',
'column8',
'column9',
'column10',
'column11',
'column12',
'column13',
'column14',
'column15',
'column16'
];
$VAR1 = {
'column8' => 'data8',
'column9' => 'data9',
'column1' => 'data1',
'column10' => 'data10',
'column11' => 'data11',
'column2' => 'data2',
'column12' => 'data12',
'column3' => 'VISHAY BC COMPONENTS, 2222036 Rule Based Upgrades
VISHAY BC COMPONENTS, 2222048 Rule Based Upgrades
VISHAY BC COMPONENTS, 2222116 Rule Based Upgrades
VISHAY BC COMPONENTS, 2222151 Rule Based Upgrades
',
'column13' => 'data13',
'column4' => 'data4',
'column14' => 'data14',
'column5' => 'data5',
'column15' => 'data15',
'column6' => 'data6',
'column16' => 'data16',
'column7' => 'data7'
};
<h3>ready to split</h3>$VAR1 = [
10,
10,
10,
10
];
$VAR1 = [
'VISHAY BC COMPONENTS, 2222036 Rule Based Upgrades',
'VISHAY BC COMPONENTS, 2222048 Rule Based Upgrades',
'VISHAY BC COMPONENTS, 2222116 Rule Based Upgrades',
'VISHAY BC COMPONENTS, 2222151 Rule Based Upgrades',
' '
];
Quote:
|
|
#57
|
||||
|
||||
|
Back to this:
Code:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use CGI qw/:standard *table/;
use CGI::Carp qw/fatalsToBrowser/;
print header, start_html, start_table;
my $file = 'tsv_parse.tsv';
{
local $/ = "\r\n"; #yes, applies to you too
open my $fh, "<", $file or die "Can't open $file: $!";
my $header = <$fh>;
chomp $header;
my @head = split /\t/, $header;
#print Dumper \@head;
while (<$fh>) {
chomp;
my %row;
@row{@head} = split /\t/;
$row{'column3'} =~ s/"//g;
#print Dumper \%row;
print h3('ready to split');
my @separators = map {ord($_)} $row{'column3'} =~ m/[^A-Za-z0-9, ]/g;
print table(Tr(td(@separators)));
#print Dumper \@separators;
print start_table;
my @repeat = split /\n/, $row{'column3'};
#print Dumper \@repeat;
foreach (@repeat) {
my @data = map {$row{$_} || undef} @head;
$data[2] = $_;
print Tr(td(@data)) if $_ !~ /^\s*$/;
}
print end_table;
}
}
print end_html;
|
|
#58
|
|||
|
|||
|
It WORKS!!! Thank you so much! I asked earlier before that the comma...is it possible to move that to a new column? so how do i insert that correctly in a database? hey Keath, you are staying late at work for this? i really appreciate this. we can continue tomorrow? if you are ever in los angeles, let me know, i am in debt to you. expensive dinner and vip treatment on me. Code:
ready to split 10 10 10 10 data1 data2 VISHAY BC COMPONENTS, 2222036 Rule Based Upgrades data4 data5 data6 data7 data8 data9 data10 data11 data12 data13 data14 data15 data16 data1 data2 VISHAY BC COMPONENTS, 2222048 Rule Based Upgrades data4 data5 data6 data7 data8 data9 data10 data11 data12 data13 data14 data15 data16 data1 data2 VISHAY BC COMPONENTS, 2222116 Rule Based Upgrades data4 data5 data6 data7 data8 data9 data10 data11 data12 data13 data14 data15 data16 data1 data2 VISHAY BC COMPONENTS, 2222151 Rule Based Upgrades data4 data5 data6 data7 data8 data9 data10 data11 data12 data13 data14 data15 data16 |