in reply to Re: Passing info from an array to a system call.
in thread Passing info from an array to a system call.

I appreciate everyone willing to help! I have tried many different methods and I'm still having issues dealing with Perl reading the file and dealing with addqueue properly. The reason why I had $file mentioned so much probably is silly to you guys but I'm using Getopt::Long, I setup an option called -f which stores as \$file, if $file is called then I'll execute my code, unfortunatly I couldn't see another way to open the file handle other than $file since of course the string rely's on <STDIN>.

The purpose of this program is to make the process of adding print queues standard and seemless, (we have various flavors of *nix), if I can make it intuitive enough; I can pass the workload to the applications teams :).

I wanted to have the functionality of a user throwing a text file in wherever they want and then call the option. Such as mkpq -f /tmp/printers.txt, of course the /tmp/printers.txt will be stored as $file and that's why it was mentioned so much.

I am a new Perl programmer I'm trying to read as much as possible but with no programming background it makes it tough to do things correct. Albeit I do appreciate constructive criticism, I'll keep poking around with this chunk of code, as the rest of my program works great!

Thanks again Monks.
  • Comment on Re^2: Passing info from an array to a system call.

Replies are listed 'Best First'.
Re^3: Passing info from an array to a system call.
by misconfiguration (Sexton) on Jan 31, 2008 at 20:29 UTC
    Here is the product of your guys' advice, thanks again!

    if ($file) { lc($file); if ( -e "$file" ) { my $fh; open( $fh, '<', $file or die &reasons() ); my @lines = <$fh>; foreach my $q (@lines) { chomp($q); if ( -e "/var/spool/lp/request/$q" ) { die "Printer \"$q\" is already defined!\n"; } else { print "Adding queue \"$q\": "; # "addqueue -h QUEUENAME -q QUEUENAME -i 3" my %file_cmd = ("addqueue -h $q -q $q -i 3"); system( $file_cmd {'$file_cmd'} ); } } close($fh); } else { &reasons(); } }