if ($file) {
...
open my $file, "< $file",
or print &reasons();
...
foreach my $file (@all_lines) {
####
while (<$file>) {
my @all_lines = <$file>;
foreach my $file (@all_lines) {
####
my %systemcmd = (
add => sub { 'addqueue', '-h', $_[ 0 ], '-q', $_[ 0 ], '-i', '3' },
remove => sub { 'removequeue', '-f', '-q', $_[ 0 ] },
status => sub { 'lpstat', "-p$_[0]" },
cancel => sub { 'cancel', '-e', $_[ 0 ] },
add_slurp => sub { 'addqueue', '-h', $_[ 0 ], '-q', $_[ 0 ], '-i', '3' },
);
if ( $file ) {
$file = lc $file;
open my $FH, '<', $file or die reasons();
print "Please wait... Reading from the file... \n";
sleep 5;
<$FH>; # remove first line
while ( my $line = <$FH> ) {
if ( -e "/var/spool/lp/request/$line" ) {
die "This printer is already defined!\n";
}
else {
print "Adding queue \"$line\"\n";
sleep 1;
my @args = $systemcmd{ add_slurp }->( $line );
0 == system @args or warn "system @args failed: $?";
}
}
close $FH;
exit 0;
}