我想将密码组密码从wpa_passphrase返回到perl脚本中。当我说:
wpa_passphrase mywifi mypassword我得到了这个结果:
network={
ssid="mywifi"
#psk="mypassword"
psk=f7170c7cf32060e75d4a0a9dad35640ee513c4d3706f55b4358f31c4b768ed21
}在perl中,我尝试了5行
my $res = `/usr/bin/wpa_passphrase mywifi mypassword`;
my $res2 = substr($V_FILERESULT,index($res ,"psk")+4);
$res2 = substr($res2 ,index($res2 ,"psk")+4,length($res2 )-2);
$res2 = substr($res2 ,0,length($res2 )-2);
$res2 =~ s/\s+$//g;它工作,但我认为不是很干净的代码。你知道我怎么才能用正确的方式写作吗?
发布于 2014-03-11 22:48:55
你可以这样做:
`/usr/bin/wpa_passphrase mywifi mypassword` =~ /\spsk=(.*)/;
print $1;模式细节:
\s # a white character
psk= # psk=
(.*) # capturing group 1: all the content until the newlinehttps://stackoverflow.com/questions/22337969
复制相似问题