1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/perl use strict; use warnings; my @list = qw(a b c d e f g h i j k l m n o p q r s t u v w x y z); foreach my $f(@list){ foreach my $s(@list){ my $fn = $f.$s; my $new_fn = '$'.$fn; open($new_fn, ">", "Extraction_$fn.txt") or die $!; } }
QuoteCan't use string ("aa") as a SCALAR ref while "strict refs" in use at
1 2 3
my $fh = substr $mpn, 0,2; my $new_fh = '$'.$fh; print $new_fh "$query\t$mpn\t......";
1 2 3 4 5 6
... for my $f (@list) { for my $s (@list) { open my $dummy, '>', "Extraction_$f$s.txt") or die $!; } }
1 2 3
my $fh = substr $mpn, 0,2; my $new_fh = '$'.$fh; print $new_fh "$query\t$mpn.....";
perldoc -q 'variable name'
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
#!/usr/bin/perl use strict; use warnings; my @list = qw(a b c); my %fh; foreach my $f(@list){ foreach my $s(@list){ my $key = $f.$s; open($fh{$key}, ">", "fh_$key.txt") or die; } } while(<DATA>){ chomp; my $sub = substr($_, 0,2); print $sub "$sub\n"; } __DATA__ aaK acK bcK baK bbK
Quoteauskommentiere, dann bekomme ich, was ich haben möchte.use strict;
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
#!/usr/bin/perl #use strict; use warnings; my @list = qw(a b c); foreach my $f(@list){ foreach my $s(@list){ my $aaa = $f.$s; open($aaa, ">", "test_$aaa.txt") or die; } } while(<DATA>){ chomp; my $sub = substr($_, 0,2); print $sub "$sub\n"; } __DATA__ aaK acK bcK baK bbK
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
#!/usr/bin/perl use strict; use warnings; my @list = qw(a b c); my %fh; foreach my $f(@list){ foreach my $s(@list){ my $key = $f.$s; open($fh{$key}, ">", "fh_$key.txt") or die; } } while(<DATA>){ chomp; my $sub = substr($_, 0,2); print $fh{$sub} "$sub\n"; } __DATA__ aaK acK bcK baK bbK
QuoteString found where operator expected at wer_loesung.pl line 18, near "} "$sub\n""
(Missing operator before "$sub\n"?)
syntax error at wer_loesung.pl line 18, near "} "$sub\n""
Execution of wer_loesung.pl aborted due to compilation errors.
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
#!/usr/bin/perl use strict; use warnings; my @list = qw(a b c); my %fh; foreach my $f(@list){ foreach my $s(@list){ my $key = $f.$s; open($fh{$key}, ">", "fh_$key.txt") or die; } } while(<DATA>){ chomp; my $sub = substr($_, 0,2); my $filehandle =$fh{$sub}; print $filehandle "$sub\n"; } __DATA__ aaK acK bcK baK bbK
QuoteIf you're storing handles in an array or hash, or in general whenever you're using any expression more complex than a bareword handle or a plain, unsubscripted scalar variable to retrieve it, you will have to use a block returning the filehandle value instead