代码之家  ›  专栏  ›  技术社区  ›  Vijay

perl系统命令中的“tar cvf fred_flintstone<barney&barney>betty”是做什么的?

  •  1
  • Vijay  · 技术社区  · 14 年前

    下面的陈述确切地说了什么?

    my @dirs = qw(fred|flintstone <barney&rubble> betty );
    

    完整的故事是:

    my $tarfile = "something*wicked.tar";
    my @dirs = qw(fred|flintstone <barney&rubble> betty );
    system "tar", "cvf", $tarfile, @dirs;
    

    这是从 Perl语言入门 ,第四版。

    结果是 system command 将在shell上运行的是:

    tar cvf fred|flintstone <barney&rubble> betty
    

    但是这个命令在Unix上有意义吗?

    4 回复  |  直到 14 年前
        1
  •  4
  •   eumiro    14 年前

    qw() "fred|flintstone", "<barney&rubble>", "betty"

    tar cvf fred|flintstone <barney&rubble> betty
    

    | < > &

    tar cvf fred flintstone

    < barney

    &

    > rubble betty

        2
  •  5
  •   Eugene Yarmash    14 年前

    perldoc perlop

    qw/STRING/
               Evaluates to a list of the words extracted out of STRING, using
               embedded whitespace as the word delimiters.  It can be understood
               as being roughly equivalent to:
    
                   split(' ', q/STRING/);
    
               the differences being that it generates a real list at compile
               time, and in scalar context it returns the last element in the
               list.  So this expression:
    
                   qw(foo bar baz)
    
               is semantically equivalent to the list:
    
                   'foo', 'bar', 'baz' 
    
        3
  •  3
  •   Matteo Riva    14 年前

    fred|flinstone
    <barney&rubble>
    betty
    

    @dirs

    qw

    tar cvf

    c - create archive
    v - verbose mode
    f - use following argument as archive name
    

        4
  •  2
  •   Aif    14 年前

    $ perl -e 'use Data::Dumper; my @dirs = qw(fred|flintstone <barney&rubble> betty ); print Dumper(@dirs);'
    
    $VAR1 = 'fred|flintstone';
    $VAR2 = '<barney&rubble>';
    $VAR3 = 'betty';
    

    $ perl -e 'use Data::Dumper; my @dirs = qw(fred|flintstone <barney&rubble> betty ); print Dumper \@dirs;'
    $VAR1 = [
              'fred|flintstone',
              '<barney&rubble>',
              'betty'
            ];
    

    Quote_and_Quote_like_Operators