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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.