Michael Goldshteyn wrote:
> That is, why does the output differ between:
> 
> perl -e "print join(\"\n\",@{[`dir`]});"
> 
> and
> 
> dir | perl -pne ""

$ which dir
$ alias dir
alias dir='ls -l'
$ unalias dir
$ alias dir
bash: alias: dir: not found
$ which dir
/usr/bin/dir


It looks like the first example is using the executable in /usr/bin and the
second is using the Bash alias (if that is how you have them set up in your
environment.)


Note that in the second example the -n switch is superfluous:

perldoc perlrun
[snip]
       -p   causes Perl to assume the following loop around your program,
            which makes it iterate over filename arguments somewhat like sed:

              LINE:
                while (<>) {
                    ...             # your program goes here
                } continue {
                    print or die "-p destination: $!\n";
                }

            If a file named by an argument cannot be opened for some reason,
            Perl warns you about it, and moves on to the next file.  Note that
            the lines are printed automatically.  An error occurring during
            printing is treated as fatal.  To suppress printing use the -n
            switch.  A -p overrides a -n switch.
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^

Also the expression:

print join(\"\n\",@{[`dir`]});

is more readable as:

print join qq(\n), qx(dir);



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to