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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
$count=0; my $file1="38579.txt"; my @a; my @neu1; my $in; my $datei; open ($in, "<", $file1) or die "Datei $file1 existiert nicht\n"; while (<$in>){ chomp ($_); @a=split (/\t/, $_); push (@neu1, "$a[1]\t$a[12]\n"); } close ($in); while ($count <=$#neu1){ $count++; } $count--; open ($datei, ">", "38579neu.txt"); print $datei "no. entries: $count\n\n"; foreach (@neu1){ print $datei $_; } close ($datei); $count=0; my $file2="38943.txt"; my @b; my @neu2; my $in2; my $datei2; open ($in2, "<", $file2) or die "Datei $file1 existiert nicht\n"; while (<$in2>){ chomp ($_); @b=split (/\t/, $_); push (@neu2, "$a[1]\t$a[12]\n"); } close ($in2); while ($count <=$#neu2){ $count++; } $count--; open ($datei2, ">", "38943neu.txt"); print $datei2 "no. entries: $count\n\n"; foreach (@neu2){ print $datei2 $_; } close ($datei2);
my $count = 0;
if ($a == 1) { ... }
chomp($a);
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
use warnings; use strict; my $file1; my $file2; my $in1; my $in2; my $datei1; my $datei2; my @out1; my @out2; print 'Enter ID Sample 1: '; $file1 = <STDIN>; chomp($file1); print 'Enter ID Sample 2: '; $file2 = <STDIN>; chomp($file2); for ($file1){ open ($in1, "<", $file1) or die "Datei $file1 konnte konnte wnicht gefunden werde!"; while (<$in1>) { chomp($_); my @a = split(/\t/, $_); push (@out1, "$a[1]\t$a[12]\n"); } close ($in1); open($datei1, ">", "out1.txt"); foreach (@out1) { print $datei1 $_; } close($datei1); } for ($file2){ open ($in2, "<", $file2) or die "Datei $file2 konnte konnte wnicht gefunden werde!"; while (<$in2>) { chomp($_); my @b = split(/\t/, $_); push (@out2, "$a[1]\t$a[12]\n"); } close ($in2); open ($datei2, ">", "out2.txt"); foreach (@out2) { print $datei2 $_; } close($datei1); } Die erste Datei Out1.txt enthält genau das, was ich haben will, die zweite Datei Out2.txt enthält aber leider nur den letzten Eintrag der ersten Datei (x-mal). Woran liegt das denn? Wo liegt der Fehler?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/perl use warnings; use strict; for my $i (1 .. 10) { # Block 1 print "i: $i\n"; for my $u (1 .. 5) { # Block 2 print "u: $u\n"; } }
for ($file1) { ... }
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#!/usr/bin/perl use warnings; use strict; my $file1; my $file2; my $in1; my $in2; my $datei1; my $datei2; my @out1; my @out2; my $i; print 'Enter ID Sample 1: '; $file1 = <STDIN>; chomp($file1); open ($in1, "<", $file1) or die "Datei $file1 konnte konnte nicht gefunden werden!"; while (<$in1>) { chomp($_); my @a = split(/\t/, $_); push (@out1, "$a[1]\t$a[12]\n"); } close($in1); open($datei1, ">", "out1.txt"); foreach $i (@out1) { print $datei1 $i; } close($datei1); print 'Enter ID Sample 2: '; $file2 = <STDIN>; chomp($file2); open ($in2, "<", $file2) or die "Datei $file2 konnte konnte nicht gefunden werden!"; while (<$in2>) { chomp($_); my @b = split(/\t/, $_); push (@out2, "$b[1]\t$b[12]\n"); } close($in2); open ($datei2, ">", "out2.txt"); foreach $i (@out2) { print $datei2 $i; } close($datei1);
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
#!/usr/bin/perl use warnings; use strict; sub processFile { my $nr = shift; my @a; my @out; my $i; print "\nEnter ID Sample $nr: "; my $filename = <STDIN>; chomp($filename); open (my $in, "<", $filename) or die "Datei $filename konnte konnte nicht gefunden werden!"; while (<$in>) { chomp($_); @a = split(/\t/, $_); push(@out, "$a[1]\t$a[12]\n"); } close($in); open(my $datei, ">", "out$nr.txt"); foreach $i (@out) { print $datei $i; } close($datei); } processFile("1"); processFile("2");
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/usr/bin/perl use v5.12; use warnings; sub processFile { my $nr = shift; my @a; print "\nEnter ID Sample $nr: "; chomp(my $filename = <STDIN>); open (my $in, "<", $filename) or die "Datei $filename konnte konnte nicht gefunden werden!"; open(my $out, ">", "out$nr.txt"); while (<$in>) { chomp; @a = split /\t/; say $out $a[1],"\t",$a[12]; } close($in); close($out); } processFile($_) for qw/1 2/;
for ($file2){