Monks,
I am a fairly new Perl programmer and I'm sort of hung-up on a process here. I have defined a hash with a system command to handle if a particular command has been defined.
my %systemcmd = (
add => "addqueue -h $add -q $add -i 3",
remove => "removequeue -f -q $remove",
status => "lpstat -p$status",
cancel => "cancel -e $cancel",
add_slurp => "addqueue -h $file -q $file -i 3"
);
Now here is the process that does the dirty work and then calls the actual system function to handle the addition of the queue. On the HP-UX machine I get 'invalid queue format' I get the feeling that it's my noob ways of programming that is causing each line from the text file it reads not to be passed to the system command properly. I'm also having a hard time telling Perl to ignore any \n's in the text file It's reading. For some reason "" is trying to be added as a queue.
if ($file) {
$file = lc($file);
my $FH = "$file";
open my $file, "< $file",
or print &reasons();
print "Please wait... Reading from the file... \n";
sleep 5;
while (<$file>) {
my @all_lines = <$file>;
foreach my $file (@all_lines) {
if ( -e "/var/spool/lp/request/$file" ) {
die "This printer is already defined!\n";
}
else {
print "Adding queue \"$file\"\n";
sleep 1;
system( $systemcmd {'add_slurp'} );
}
}
close($file);
}
exit;
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.