[EMAIL PROTECTED] wrote:
> Hi John,

Hello,

> Thanks for your prompt response as usual ...
> 
> Not exactly need File::Spec and File::Basename per se, I really need to
> grab some of the environment variables that are set when the Perl script
> is run or in the case of the .BAT file, when the batch file is run. For
> example, I want to know what is %TEMP% and if it is C:\WINDOWS\TMP,

Environment variables are in the %ENV hash so $ENV{ TEMP } has the contents of
%TEMP%.


> I
> want to change it to C:\TEMP instead whenever I run by script by doing
> SET TEMP=C:\TMP, but this is all straightforward in the batch file but
> am confused on how to do it inside Perl.

You can change it while the Perl program is running but it won't affect other
programs and the changes will disappear when the program ends.


> For using ...
> 
> use Sys::Hostname;
> my $server = hostname;
> 
> The above one is only for the hostname?

Yes.


> In some of the existing UNIX scripts, I
> have num_of_developers=`cat /etc/passwd | grep developer | wc -l` which
> gives the number of developer logins. So how do I get it to do the same
> in Perl?

my ( $gcos, $num_of_developers );

$gcos =~ /developer/ && $num_of_developers++ while $gcos = (getpwent)[6];


> I
> tried $num_of_developers=system "cat /etc/passwd | grep developer | wc -l",
> that doesn't work and I think I understand that Perl is giving the return
> code of running the system function. So how do I get Perl to give the
> resultset of running the OS commands that I passed on to system?

Did you read the documentation for system()?

perldoc -f system

    system LIST
    system PROGRAM LIST

[snip]
            The return value is the exit status of the program as returned by
            the "wait" call.  To get the actual exit value shift right by
            eight (see below).  See also "exec".  This is not what you want to
            use to capture the output from a command, for that you should use
            merely backticks or "qx//", as described in "'STRING'" in perlop.
            Return value of -1 indicates a failure to start the program
            (inspect $! for the reason).


So (without the UUOC):

chomp( my $num_of_developers = qx[ grep developer /etc/passwd | wc -l ] );



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