Leser: 19
![]() |
|< 1 2 3 >| | ![]() |
24 Einträge, 3 Seiten |
2021-10-05T08:23:33 alzachEs gibt Strawberry Perl als Portable (nur für dich als Nutzer, kein Install nötig) ⇒ https://strawberryperl.com/releases.htmlnun ja, ich arbeite mit W10 und möchte den Perl-Interpreter nicht unbedingt installieren, da ich ihn ohnehin nicht oft benötige, aber mit dem experimentieren auf der Konsole hast du natürlich grundsätzlich recht.
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
#!/usr/bin/perl use warnings; use strict; sub toEUR { my $n = shift; $n =~ s/\,/./; if ($n =~ /\,/) { print "\nError: Too many commas in '$n'.\n\n"; exit 1; } $n = sprintf("%.02f", $n); $n =~ s/\./,/; if ($n =~ /\./) { print "\nError: Too many points in '$n'.\n\n"; exit 2; } return $n; } sub print_formatted { # @fields: $quantity, $id, $name, $price, $addtlinfo: my @fields = @_; $fields[3] = toEUR($fields[3]); my @formats = ([5, "r"], [7, "r"], [40, "l"], [6, "r"], [20, "r"]); my $separator = " "; my $s = ""; my $i; my @v; my $spaces; for $i (0 .. $#formats) { @v = @{$formats[$i]}; if (length($fields[$i]) > $v[0]) { print "\nError: Length of '$fields[$i]' shouldn't be bigger than $v[0].\n\n"; exit 3; } $spaces = " " x ($v[0] - length($fields[$i])); if ($v[1] eq "r") { $s .= $spaces; $s .= $fields[$i]; } else { $s .= $fields[$i]; $s .= $spaces; } if ($i == 3) { $s .= " Euro "; } else { $s .= $separator; } } print "$s\n"; } my $youremail = "you\@email.de"; my $b_email = "me\@email.de"; my $day = 3; my @months = qw(Januar Februar März April Mai Juni Juli August September Oktober November Dezember); my $month = 9; my $year = 2021; my $hour = 14; my $min = 10; my $sec = 50; my $b_first = "Max"; my $b_last = "Mustermann"; my $b_addr = ""; my $b_addr2 = "Mustergasse 15"; my $b_zip = 54321; my $b_city = "München"; my $b_phone = "01234/5678"; my $b_fax = "01234/56710"; my $QUANTITY_1 = 10; my $QUANTITY_2 = 10; my $QUANTITY_3 = 10; my $QUANTITY_4 = 10; my $QUANTITY_5 = 10; my $QUANTITY_6 = 10; my $ID_1 = 12345; my $ID_2 = 12345; my $ID_3 = 12345; my $ID_4 = 12345; my $ID_5 = 12345; my $ID_6 = 12345; my $NAME_1 = "Mustermann"; my $NAME_2 = "Mustermann"; my $NAME_3 = "Mustermann"; my $NAME_4 = "Mustermann"; my $NAME_5 = "Mustermann"; my $NAME_6 = "Mustermann"; my $PRICE_1 = 5; my $PRICE_2 = 250.75; my $PRICE_3 = 3; my $PRICE_4 = 125; my $PRICE_5 = 25; my $PRICE_6 = 0.25; my $ADDTLINFO_1 = "Angebot"; my $ADDTLINFO_2 = "Angebot"; my $ADDTLINFO_3 = "Angebot"; my $ADDTLINFO_4 = "Angebot"; my $ADDTLINFO_5 = "Angebot"; my $ADDTLINFO_6 = "Angebot"; print "To: $youremail\n"; print "From: $b_email\n"; print "Subject: Online Bestellung\n"; print "\n\n"; print "Online Bestellung.\n"; print "\n"; print "Bestelldatum: $day. $months[$month] $year $hour:$min:$sec \n"; print " \n"; print "Rechnungsanschrift: \n"; print "-------- \n"; print " $b_first $b_last \n"; print " $b_addr \n"; print " $b_addr2 \n"; print " $b_zip $b_city \n"; print " $b_phone \n"; print " $b_fax \n"; print " $b_email \n"; print " \n"; print " \n"; print "Menge Produkt Name" . " " x 36 . " Preis(Euro) " . " " x 16 . "Info\n"; print "========================================================================================\n"; print_formatted($QUANTITY_1, $ID_1, $NAME_1, $PRICE_1, $ADDTLINFO_1); if( $NAME_2 ) { print_formatted($QUANTITY_2, $ID_2, $NAME_2, $PRICE_2, $ADDTLINFO_2); } if( $NAME_3 ) { print_formatted($QUANTITY_3, $ID_3, $NAME_3, $PRICE_3, $ADDTLINFO_3); } if( $NAME_4 ) { print_formatted($QUANTITY_4, $ID_4, $NAME_4, $PRICE_4, $ADDTLINFO_4); } if( $NAME_5 ) { print_formatted($QUANTITY_5, $ID_5, $NAME_5, $PRICE_5, $ADDTLINFO_5); } if( $NAME_6 ) { print_formatted($QUANTITY_6, $ID_6, $NAME_6, $PRICE_6, $ADDTLINFO_6); }
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
#!/usr/bin/perl use warnings; use strict; package Customer { sub new { my $classname = shift; my $self = {}; $self->{name} = shift; return bless($self, $classname); } } package Product { sub new { my $classname = shift; my $self = {}; $self->{price} = shift; return bless($self, $classname); } } package Order { sub new { my $classname = shift; my $self = {}; $self->{id} = shift; $self->{quantity} = shift; $self->{customer} = shift; $self->{product} = shift; $self->{addtlinfo} = shift; return bless($self, $classname); } } sub toEUR { my $n = shift; $n =~ s/\,/./; if ($n =~ /\,/) { print "\nError: Too many commas in '$n'.\n\n"; exit 1; } $n = sprintf("%.02f", $n); $n =~ s/\./,/; if ($n =~ /\./) { print "\nError: Too many points in '$n'.\n\n"; exit 2; } return $n; } sub print_formatted { # @fields: $quantity, $id, $name, $price, $addtlinfo: my @fields = @_; $fields[3] = toEUR($fields[3]); my @formats = ([5, "r"], [7, "r"], [40, "l"], [6, "r"], [20, "r"]); my $separator = " "; my $s = ""; my $i; my @v; my $spaces; for $i (0 .. $#formats) { @v = @{$formats[$i]}; if (length($fields[$i]) > $v[0]) { print "\nError: Length of '$fields[$i]' shouldn't be bigger than $v[0].\n\n"; exit 3; } $spaces = " " x ($v[0] - length($fields[$i])); if ($v[1] eq "r") { $s .= $spaces; $s .= $fields[$i]; } else { $s .= $fields[$i]; $s .= $spaces; } if ($i == 3) { $s .= " Euro "; } else { $s .= $separator; } } print "$s\n"; } my @customers = (); push(@customers, Customer->new("Mueller")); push(@customers, Customer->new("Meier")); push(@customers, Customer->new("Schulze")); push(@customers, Customer->new("Schmidt")); push(@customers, Customer->new("Schulz")); push(@customers, Customer->new("Scholz")); my @products = (); push(@products, Product->new(5)); push(@products, Product->new(250.75)); push(@products, Product->new(3)); push(@products, Product->new(125)); push(@products, Product->new(25)); push(@products, Product->new(0.25)); my @orders = (); push(@orders, Order->new(12345, 10, $customers[2], $products[0], "Angebot")); push(@orders, Order->new(12346, 25, $customers[1], $products[4], "Aktion")); push(@orders, Order->new(12347, 75, $customers[0], $products[5], "Reduziert")); push(@orders, Order->new(12348, 100, $customers[3], $products[1], "Sonderangebot")); push(@orders, Order->new(12349, 2, $customers[4], $products[2], "Billig")); push(@orders, Order->new(12350, 14, $customers[5], $products[3], "Lieferung")); print "\nMenge Produkt Name" . " " x 36 . " Preis(Euro) " . " " x 16 . "Info\n"; print "========================================================================================\n"; my $order; for $order (@orders) { print_formatted($order->{quantity}, $order->{id}, $order->{customer}->{name}, $order->{product}->{price}, $order->{addtlinfo} ); } print "\n";
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
#!/usr/bin/perl use warnings; use strict; package Customer { sub new { my $classname = shift; my $args = {@_}; my $self = { id => $args->{id}, name => $args->{name} }; $self->{orders} = []; return bless($self, $classname); } sub updateOrders { my $self = shift; my @orders = @_; my $order; foreach $order (@orders) { if ($self->{id} eq $order->{customer}->{id}) { push($self->{orders}, $order); } } } sub getOrders { my $self = shift; return @{ $self->{orders} }; } } package Product { sub new { my $classname = shift; my $args = {@_}; my $self = { price => $args->{price} }; return bless($self, $classname); } } package Order { sub new { my $classname = shift; my $args = {@_}; my $self = { id => $args->{id}, quantity => $args->{quantity}, customer => $args->{customer}, product => $args->{product}, addtlinfo => $args->{addtlinfo} }; return bless($self, $classname); } } sub toEUR { my $n = shift; $n =~ s/\,/./; if ($n =~ /\,/) { print "\nError: Too many commas in '$n'.\n\n"; exit 1; } $n = sprintf("%.02f", $n); $n =~ s/\./,/; if ($n =~ /\./) { print "\nError: Too many points in '$n'.\n\n"; exit 2; } return $n; } sub print_formatted { # @fields: $quantity, $id, $name, $price, $addtlinfo: my @fields = @_; $fields[3] = toEUR($fields[3]); my @formats = ([5, "r"], [7, "r"], [40, "l"], [6, "r"], [20, "r"]); my $separator = " "; my $s = ""; my $i; my @v; my $spaces; for $i (0 .. $#formats) { @v = @{$formats[$i]}; if (length($fields[$i]) > $v[0]) { print "\nError: Length of '$fields[$i]' shouldn't be bigger than $v[0].\n\n"; exit 3; } $spaces = " " x ($v[0] - length($fields[$i])); if ($v[1] eq "r") { $s .= $spaces; $s .= $fields[$i]; } else { $s .= $fields[$i]; $s .= $spaces; } if ($i == 3) { $s .= " Euro "; } else { $s .= $separator; } } print "$s\n"; } my @customers = (); push(@customers, Customer->new(id => 1, name => "Mueller")); push(@customers, Customer->new(id => 2, name => "Meier")); push(@customers, Customer->new(id => 3, name => "Schulze")); push(@customers, Customer->new(id => 4, name => "Schmidt")); push(@customers, Customer->new(id => 5, name => "Schulz")); push(@customers, Customer->new(id => 6, name => "Scholz")); my @products = (); push(@products, Product->new(price => 5)); push(@products, Product->new(price => 250.75)); push(@products, Product->new(price => 3)); push(@products, Product->new(price => 125)); push(@products, Product->new(price => 25)); push(@products, Product->new(price => 0.25)); my @orders = (); push(@orders, Order->new(id => 12345, quantity => 10, customer => $customers[2], product => $products[0], addtlinfo => "Angebot")); push(@orders, Order->new(id => 12346, quantity => 25, customer => $customers[1], product => $products[4], addtlinfo => "Aktion")); push(@orders, Order->new(id => 12347, quantity => 75, customer => $customers[0], product => $products[5], addtlinfo => "Reduziert")); push(@orders, Order->new(id => 12348, quantity => 100, customer => $customers[3], product => $products[1], addtlinfo => "Sonderangebot")); push(@orders, Order->new(id => 12349, quantity => 2, customer => $customers[4], product => $products[2], addtlinfo => "Billig")); push(@orders, Order->new(id => 12350, quantity => 14, customer => $customers[5], product => $products[3], addtlinfo => "Lieferung")); print "\nMenge Produkt Name" . " " x 36 . " Preis(Euro) " . " " x 16 . "Info\n"; print "========================================================================================\n"; my $order; for $order (@orders) { print_formatted($order->{quantity}, $order->{id}, $order->{customer}->{name}, $order->{product}->{price}, $order->{addtlinfo} ); } print "\n"; my $customer; foreach $customer (@customers) { $customer->updateOrders(@orders); } my @o; my $i; foreach $customer (@customers) { print "\nCustomer '$customer->{name}' has the following orders:\n\n"; @o = $customer->getOrders(); foreach $i (@o) { print_formatted($i->{quantity}, $i->{id}, $i->{customer}->{name}, $i->{product}->{price}, $i->{addtlinfo}); } }
![]() |
|< 1 2 3 >| | ![]() |
24 Einträge, 3 Seiten |