if ($file) { ... open my $file, "< $file", or print &reasons(); ... foreach my $file (@all_lines) {
Why do you have three different variables named $file?
while (<$file>) { my @all_lines = <$file>; foreach my $file (@all_lines) {
When you enter the while loop the first line is read into the $_ variable and then the rest of the lines are read into the @all_lines variable. @all_lines does not contain all of the lines because the first line is missing.
It looks like you may want something like this:
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; }
In reply to Re: Passing info from an array to a system call.
by jwkrahn
in thread Passing info from an array to a system call.
by misconfiguration
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |