On Sat, Feb 7, 2009 at 08:59, pouliakhina <pouliakh...@gmail.com> wrote:
> Hello,
>
> I try to write the name of the current directory in $x:
>
> $x = system ("pwd");
>
> But it doesn't work. It also doesn't work in all these combinations:
> 
> $x = 'system("pwd")';
> $x = system("`pwd`");
>
> Can You help me to write the result of 'pwd' in $x?
snip

This is because the system function* does not return the stdout of the
program being run.  You might be looking for the qx// operator** (also
known as backticks or ``):

my $pwd = qx{pwd};

But that is not a good idea***.  You really want is the getcwd
function from the Cwd module****:

use Cwd;

my $pwd = getcwd();

It is part of Core Perl, so, unless your version of Perl is broken, it
will exist on any box Perl is installed on.

* http://perldoc.perl.org/functions/system.html
** http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators
*** calling external programs to do things that can be done in Perl is
fragile (OS dependent, the error checking is harder, etc.)
**** http://perldoc.perl.org/Cwd.html

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to