Thread Zeichenlimit einrichten (40 answers)
Opened by andy at 2013-05-03 14:53

bloonix
 2013-05-31 14:14
#167895 #167895
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Guest wer
Was sollen die Zuweisungen außerhalb der Schleife? Warum erst in ein Array lesen und dann bearbeiten? Warum globale Filehandles? Warum kein strict und warnings?

Code (perl): (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
#!/usr/bin/perl
use strict;
use warnings;

my $in_file1='content.csv';
my $in_file2 'common.csv';
my $out_file='neu.csv';

my %gesetze;
open(my $ifh1, '<', $in_file1) or die "ERROR OPEN $in_file1 ($!)\n";
while(my $line=<$ifh1>) {
  chomp $line ;
  my ($nummer, $kuerzel, $gesetz) = split /;/, $line, 3;
  $gesetze{$kuerzel}=$gesetz;
}
close $ifh1;

open(my $ifh2, '<', $in_file2) or die "ERROR OPEN $in_file2 ($!)\n";
open(my $ofh,  '>', $out_file) or die "ERROR OPEN $out_file ($!)\n";
while(my $line=<$ifh1>) {
  chomp $line;
  my ($nummer, $kuerzel, $gesetz) = split /;/, $line, 3;
  if( exists $gesetze{$kuerzel} ) {
    print $ofh join(';', $kuerzel, $gesetze{$kuerzel}, $gesetz)."\n";
  }
}
close $ofh;
close $ifh2;


Welchen Sinn hat strict und warnings, wenn du nichtmal "my $in_file2 'common.csv';" bemerkst?

Was soll das unnötige Zeichenrauschen und der inkonsequente Stil?
Du packst open in runde klammern, aber nicht close ;-)

open(my $if1...) ohne Whitespace.
if ( exists ... ) mit Whitespaces.
my ($nummer, $kuerzel, $gesetz) = split /;/, $line, 3; mit Whitespaces zwischen "=".
$gesetze{$kuerzel}=$gesetz; ohne Whitespaces zwischen "=".
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread Zeichenlimit einrichten