in reply to Command line question

You're probably picking up a newline character. Use chomp to get rid of it:

perl -pe 'chomp; print `ls /home/$_/bin`;' file | grep filename

Any suggestions for a pure Perl one-liner, anyone? Maybe something like:

perl -pe 'print if glob <"/home/$_/bin/filename">;' file

Replies are listed 'Best First'.
Re: Re: Command line question
by Kanji (Parson) on Dec 03, 2000 at 11:04 UTC

    I'd be more inclined to use -l in a command line so that chomps are done automatically when used with -n or -p, but a pure perl one liner could be ...

    perl -nle 'print if -e "/home/$_/bin/filename"' file

    ... if you needed to use a seperate file, but on UNIXish systems (possibly others?) you can use getpwent() to get usernames and home directories (esp. since they may not always be under /home/!) of active accounts instead of using a seperate file.

    perl -le 'while (($u,$d)=(getpwent)[0,7]) { print $u if -e "$d/bin/$ARGV[0]" }' filename

        --k.