English 中文(简体)
每一文本的回归价值,作为对双字母的投入
原标题:Perl Script return value as input to second perl script

I need to write a script getPwd.pl($user) that parses a password file an returns the password for a particular user.

file(密码:txt)

DEFINE ALICE =  alice#1 ;
DEFINE BENICE =  benice#1 ;
DEFINE CATHY =  cathy#1 ;

A second script authUser.pl must call getPwd.pl($user) and the returned value will be passed into the second script to authenticate a user.

由于<代码>getPwd.pl将由不同用户拥有,而我将使用代号执行<代码>getPwd.pl。

Please assist and provide some guidance on how to go about this.

问题回答

我同意,整个系统应当固定下来。 如果你能够执行,你肯定有能力解决问题!

However, to answer the actual question, the best thing to do would be to call getPwd.pl as a command (not as a function like you ve shown above).

my $pwd = `getPwd.pl $user`

然后用美元作为答复。

然而,如果你至少能够使其他档案成为模块或来源档案,那么你就会更贴近。

你可以简单地印刷从密码档案中提取的价值,并使用背书或<代码>qx(),在授权书中加以记录。 例如:

my $pass = qx(/path/to/password.pl cathy);

密码可能简单一些:

my $name = shift;
open my $fh,  < ,  /path/to/password.txt  or die $!;
while (<$fh>) {
    /^DEFINE $name =/i && last; # Optional /i modifier for case insensitive match
}

if ($_ && /^DEFINE $name =  ([^ ]+) /) { # Must check $_ is not empty
    print $1;
}




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签