Schrift
[thread]3692[/thread]

list ==> text



<< >> 5 Einträge, 1 Seite
uvbaz
 2006-06-06 12:51
#34438 #34438
User since
2006-06-06
3 Artikel
BenutzerIn
[default_avatar]
hallo, everyone

i'm new in perl, i want to do the following job in perl, to convert a list to a
text. how can i do it?  which format can i use to store the list? Excel? or can i
only use the pure text format?

souce:
G11  G12  G13 |G21 G22 |G31 G32 G33 |
1     0 1      | 1 0     | 1   0     1   |
0     0 1      | 0 1     | 0   1     1   |

des:
G11, G13, G21 --> G31, G33;
G13, G22 --> G32, G33;

thank you very much for your answer!
Cheng
renee
 2006-06-06 13:39
#34439 #34439
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
You can create an Excel file with Perl (CPAN:Spreadsheet::WriteExcel or CPAN:Spreadsheet::SimpleExcel), but I can't see an advantage of Perl in your aims.

If you want to "convert" your table into a text as you have shown in your post, I would use a plain text file.
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
uvbaz
 2006-06-06 13:52
#34440 #34440
User since
2006-06-06
3 Artikel
BenutzerIn
[default_avatar]
vielen Dank für deine Antwort.
die List kann ich auch als rein Text speichern, wenn es mehr geeignet ist. kannst du mir mal zeigen, wie kann ich dieses "Übersetzung" implementieren?

danke noch mal
renee
 2006-06-06 13:52
#34441 #34441
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
I know, the following code seems to be confusing, but if you get a better understanding of map (perldoc -f map) and grep (perldoc -f grep), the code is not very complicated...

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl

use strict;
use warnings;
use Tie::File;

my $source_file = './source.txt';

tie my @array,'Tie::File',$source_file or die $!;

my $string = $array[0];
chomp $string;

my $source = substr($string,0,index($string,'|',index($string,'|')+1));
my $dest = substr($string,index($string,'|',index($string,'|')+2));

my @sources = grep{$_}split(/[\s|]+/,$source);
my @dests = grep{$_}split(/[\s|]+/,$dest);


for(1..scalar(@array)-1){
$string = $array[$_];

my $source2 = substr($string,0,index($string,'|',index($string,'|')+1));
my $dest2 = substr($string,index($string,'|',index($string,'|')+2));


my @tmp = grep{defined $_ and $_ ne ''}split(/[\s|]+/,$source2);
my @info = map{$sources[$_]}grep{$tmp[$_]}(0..scalar(@tmp)-1);

@tmp = grep{defined $_ and $_ ne ''}split(/[\s|]+/,$dest2);
my @targets = map{$dests[$_]}grep{$tmp[$_]}(0..scalar(@tmp)-1);
print join(',',@info),' --> ',join(',',@targets),";\n";
}

untie @array;


the source file:
Code: (dl )
1
2
3
G11  G12  G13 |G21 G22 |G31 G32 G33 |
1 0 1 | 1 0 | 1 0 1 |
0 0 1 | 0 1 | 0 1 1 |


Edit: dann hätte ich ja auch auf Deutsch antworten können ;)\n\n

<!--EDIT|renee|1149587626-->
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
uvbaz
 2006-06-06 14:06
#34442 #34442
User since
2006-06-06
3 Artikel
BenutzerIn
[default_avatar]
du bist sooooo nett. ich muss jetzt die Code mal learnen. :blush:
<< >> 5 Einträge, 1 Seite



View all threads created 2006-06-06 12:51.