[Cologne-pm] script auf mehreren CPU's starten

A. Pagaltzis pagaltzis at gmx.de
Fri Nov 11 08:20:08 PST 2005


* Michael Lamertz <mike at lamertz.net> [2005-11-11 10:35]:
> Also, 'tar => 1,2,3' macht nix anderes, als Dir eine Liste
> ('tar', 1, 2, 3) zu erzeugen.

Ja, oder um es anders zu sagen, der `=>` ist nichts anderes als
ein Komma, das es einem erspart, wenn man auf der linken Seite
einen sehr einfach String hat, ihn in Anführungszeichen zu
setzen. (Der String darf nur Buchstaben, Ziffern und Unterstriche
enthalten.)

> Gibst Du also PROGRAM *ohne Komma* vor der Liste an, so ist
> dies das Programm, dass gestartet werden soll, waehrend das
> erste Element der Liste der Name ist, von dem das gestartete
> Programm denkt, wie es heisst. (Was fuer ein scheiss Satz @-)

Das wichtige hierbei ist, dass

    system @arguments;

zweideutig ist, wenn @arguments nur ein Element enthält. Dann
kann die Funktion nämlich nicht unterscheiden, ob man sie als
`system( $shellkommando )` aufgerufen hat (was die erwähnten
Shell-Metazeichen-Probleme birgt) oder als `system( @arguments )`.
Der Aufruf der Form `system { $arguments[0] } @arguments` dagegen
ist immer eindeutig, auch wenn @arguments nur ein Element
enthält.

Finde ich ehrlich gesagt nervtötend umständlich – wo Perl es
einem doch sonst immer so leicht macht, gleich die sichere
Variante zu verwenden (zB `open` mit drei Argumenten). Aber damit
muss man halt leben…

> Btw.: Wusstet Ihr, dass $0 bei Perl von aussen anscheinend
> nicht ueberschrieben werden kann?

Jepp. Aus `perldoc perlvar`:

    On some (read: not all) operating systems assigning to $0
    modifies the argument area that the "ps" program sees. On
    some platforms you may have to use special "ps" options or a
    different "ps" to see the changes. Modifying the $0 is more
    useful as a way of indicating the current program state than
    it is for hiding the program you're running. (Mnemonic: same
    as sh and ksh.)

    Note that there are platform specific limitations on the the
    maximum length of $0. In the most extreme case it may be
    limited to the space occupied by the original $0.

    In some platforms there may be arbitrary amount of padding,
    for example space characters, after the modified name as
    shown by "ps". In some platforms this padding may extend all
    the way to the original length of the argument area, no
    matter what you do (this is the case for example with Linux
    2.2).

    Note for BSD users: setting $0 does not completely remove
    "perl" from the ps(1) output. For example, setting $0 to
    "foobar" may result in "perl: foobar (perl)" (whether both
    the "perl: " prefix and the " (perl)" suffix are shown
    depends on your exact BSD variant and version). This is an
    operating system feature, Perl cannot help it.

M.a.W., das Verändern von $0 ist extrem plattformspezifisch und
daher keine besonders gute Angewohnheit.

Gruss,
-- 
#Aristoteles
*AUTOLOAD=*_=sub{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;


More information about the Cologne-pm mailing list