Hi John,

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, 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.

For using ...

use Sys::Hostname;
my $server = hostname;

The above one is only for the hostname? 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? 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?

Quoting "John W. Krahn" <[EMAIL PROTECTED]>:

[EMAIL PROTECTED] wrote:
Hi all,

Hello,

I currently have a MS-DOS batch file that am trying to convert to a Perl script. I have something like this in the .BAT file where variables are "set" based on some parsing of a variable passed as a command line argument whenever the .BAT
file is executed by the application.

The command line variable is parsed/cut-down-into pieces of source_drive,
source_root, source_file, source_extn and source_path as the contents of the
.BAT file shows below:

You probably want File::Spec and File::Basename:

perldoc File::Spec
perldoc File::Spec::Win32
perldoc File::Basename


[snip]

Can someone tell me how can I achieve what the .BAT file is currently trying to
do in a Perl script? I tried doing system "set source_drive=%~dp0"; or
$source_drive=system "set source_drive=%~dp0";to try and assign the output of the set command to a variable but that does not seem to work? I do not get the
result that am expecting which is the value of %~dp0, instead I presume am
getting more like the return code of running the system "set
source_drive=%~dp0".

perldoc -f system


Can someone please advise on what am doing wrong and what must I be doing
instead?

I may have to do the same thing for converting UNIX Ksh script to Perl script.
And checking the Ksh script, there is a lot of UNIX commands executed from
within the Ksh script that assigns that output of UNIX commands to variable,
for example, server=`hostname`, I cannot work out how I should be doing this on Perl, I tried $server=system "hostname" and that does not work as $server when I try to print it gives 0 (zero) which I think is more like the return code for
running system "hostname" and not the result that am after which is the
hostname of the server.

use Sys::Hostname;

my $server = hostname;



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>





--
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