in reply to Passing info from an array to a system call.
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Passing info from an array to a system call.
by misconfiguration (Sexton) on Jan 30, 2008 at 15:27 UTC | |
by misconfiguration (Sexton) on Jan 31, 2008 at 20:29 UTC |