我使用PopId()和PushId()让许多用户共享10个登录ID到系统。有时候我收到了这个错误:
无法打开' \ ccreqpwebp01 \ ccstg \ Informatica \ APIUSR.txt' - 权限在\ ccreqpwebp01 \ ccstg \ Informatica / bccpbmod.pm行被拒绝 1206。
第1206行是打开要写的文件。 PopId()弹出APIUSR.txt中的第一个id,删除APIUSR.txt,然后使用其余的id重新创建APIUSR.txt。
任何人都可以帮我把它弄好吗?
[Category1] => Array
(
[0] => Array
(
[id] => 4
[parent_id] => 1
[name] => tere14
)
[1] => Array
(
[id] => 6
[parent_id] => 1
[name] => tere1
)
)
:
test_id.pl
$api_usr_file = "APIUSR.txt";
$id = PopId();
print "pop id=$id\n";
PushId($id);
sub PopId {
$path_to_file = $api_usr_file;
#$path_to_file = "\\\\ccreqpwebd01\\ccstg\\Unix\\APIUSR.txt";
# Read file into the array
open (my $fh, '<', $path_to_file) or die "Could not open '$path_to_file' - $!";
chomp(my @lines = <$fh>);
close $fh;
#print "Before Pop: @lines\n";
# Pop the first id
my $uid = "";
while ($uid eq "") {
$uid = shift(@lines);
}
print "Pop id:$uid\n";
#print "After Pop:@lines\n";
# Write the rest of ids back to the file
unlink $path_to_file or die "Could not delete '$path_to_file' - $!";
open (my $fd, ">>$path_to_file") or die "Could not open '$path_to_file' - $!";
sleep 3;
foreach (@lines) {
print $fd $_;
print $fd "\n";
}
close $fd;
return $uid;
}
sub PushId {
$path_to_file = $api_usr_file;
#$path_to_file = "\\\\ccreqpwebd01\\ccstg\\Unix\\APIUSR.txt";
my ($uid) = @_;
# Read file into the array
open (my $fh, '<', $path_to_file) or die "Could not open '$path_to_file' - $!";
chomp(my @lines = <$fh>);
close $fh;
#print "Before Push:@lines\n";
# unshift(@lines,$uid);
push (@lines,$uid);
#print "After push:@lines\n";
# Write to the file
unlink $path_to_file or die "Could not delete '$path_to_file' - $!";
open(my $fd, ">>$path_to_file") or die "Could not open '$path_to_file' - $!";
sleep 3;
foreach (@lines) {
print $fd $_;
print $fd "\n";
}
close $fd;
}
:
APIUSR.txt