Thread Ordnung auf der Kommandozeile
(21 answers)
Opened by rosti at 2014-09-18 08:44
Hmm - und was ist jetzt der Unterschied, ob die unzählingen Scripts *.pl oder *.pm heißen?
Edit: ich hab mir auch mal so was "drumrum" geschrieben, weil man in jedem Skript immer wieder das Gleiche zu tun hat, aber es bleiben bei mir pl-dateien. Ich seh da keinen großen Vorteil ein Modul draus zu machen, das noch zusätzlch plötzlich APIs erfüllen muss. 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 use strict; use warnings; use feature qw/:5.10/; #use ...; $| = 1; BEGIN { sub script_path { my $script_path = $0; $script_path =~ s/(.+)\\.+$/$1/; return $script_path; } push @INC, script_path(); binmode(STDOUT, ":encoding(cp850)"); binmode(STDIN, ":encoding(cp850)"); } $SIG{INT} = sub { exit }; # ein paar gängige subs # sub Foo { ... } my $x = 1; my @perl_files = glob script_path.'/*.pl'; for my $perl_file (@perl_files) { printf("%2d %s\n", $x++, $perl_file); } print "\n"; my $choice = <>; chomp($choice); print "\n===========================\n\n"; open (my $fh, '<', $perl_files[$choice-1]) || die "$!"; my $data = join('', <$fh>); eval qq|#line 1 "$perl_files[$choice-1]"\n$data|; die $@ if $@; close $fh; Das listet die Skripte im Verzeichnis auf, man kann die Nummer eingeben und es wird ausgeführt Last edited: 2014-09-18 10:05:26 +0200 (CEST) 1 + 1 = 10
|