hasant has asked for the wisdom of the Perl Monks concerning the following question:

Yesterday I was trying to uninstall a module by issueing
"make uninstall" and it gave message about this way being
depreciate and suggested to manually remove the files as
listed in .packlist file. It turned out that I was tempted
to do it with one-liner, so here it goes,

% perl -0777 -ane 'unlink $ARGV, @F' <packlist_file>

The $ARGV is there to remove the packlist file as well. It
could have been shorter by omitting some whitespaces
and unifying switches. But I'm sure it could have been
even shorter by using more obscure codes. There's no error
checking, so removing failures are ignored.

Of course, just to make sure, this isn't an issue about
how to uninstall modules. s::a::n

Replies are listed 'Best First'.
Re: Removing files listed in another file
by Abigail (Deacon) on Jun 29, 2001 at 16:50 UTC
    If you don't mind some extra error messages, you can save a few strokes:
    $ perl -ne '`rm $ARGV $_`' <packlist_file>
    This will repeatedly try to remove the packlist file, hence the error messages.

    The following trick saves strokes over the original one-liner, and doesn't produce extra error messages. Of course, if you cannot remove a file, it still gives an error message. One can see this as a feature! ;-)

    $ perl -nle '!`rm $ARGV`..`rm $_`' <packlist_file>
    Note the .. in void context.

    -- Abigail

      You cheat. The error message comes from the rm system command. :-)

      Anyway, I believe the range operator is evaluated in scalar context since it returns a sequence number until the file is exhausted.

      s::a::n

        Anyway, I believe the range operator is evaluated in scalar context since it returns a sequence number until the file is exhausted.

        You got it backwards. Context isn't determined by what the expression evaluates to. Context is determined by what is done to the value of an expression. The value of .. is ignored, hence, .. is in void context. Regardless whether it pushed a return value on the stack that got discarded anyway.

        -- Abigail

Re: Removing files listed in another file
by kschwab (Vicar) on Jun 29, 2001 at 16:43 UTC
    I'm not sure I'd want to unlink the contents of a packlist blindly...but, for the same # of chars this seems a little clearer:
    perl -ne 'chomp;unlink' < file;rm file
      You don't even need the chomp there, the -l will do it
      (only with -n or -p).

      % perl -lne 'unlink' < file

      Good for removing only the the list (not the container)
      Thanks.

      s::a::n

Re: Removing files listed in another file
by chipmunk (Parson) on Jun 29, 2001 at 17:13 UTC
    Another approach is to use Unix's very useful xargs command: xargs rm < packlist_file Of course, there's an implementation of xargs in the Perl Power Tools project.
Re: Removing files listed in another file
by Anonymous Monk on Jul 02, 2001 at 16:47 UTC
    Or from the shell:rm `cat file`. Not to use if file looong:-)