peschkaj has asked for the wisdom of the Perl Monks concerning the following question:

I wrote a piece of cam-like software today out of shear laziness and nothing to do at work. I have found a program that works astonishingly well (gqcam) on my linux box. The only problem being that it doesn't auto upload. So, I took it upon myself to write some code for it:
#!/usr/bin/perl -w use Net::FTP; my $hostname; my $username; my $password; my $boink; my $directory; my $filename; my $ftp; my $sleeptime; $boink = 0; `gqcam &`; while ($boink == 0) { $ftp = Net::FTP->new($hostname) or die "can't connect: $@\n"; $ftp->login($username,$password) or die "can't login: $@\n"; $ftp->cwd($directory) or die "can't cwd to $directory\n"; $ftp->type(binary) or die "cannot change type to binary\n"; $ftp->put($filename) or die "cannot put $filename\n"; $ftp->close; sleep($sleeptime); }
Although this is nothing revolutionary, I thought that I might as well post it because it runs under -w, as far as I am aware. I attempted to launch gqcam from the program with: `gqcam &` but that generated error after error for the cam program. How could I get perl to call gqcam and not spew forth masses of errors to gqcam?

Replies are listed 'Best First'.
Re: Slew or error messages
by runrig (Abbot) on Aug 08, 2001 at 00:20 UTC
    You're using alot of uninitialized variables there. And one bareword. I'd use strict for good measure. I don't know what gqcam does, are you trying to process the output of it, or interact with it? If the former, save the output to a variable:
    my @array = `gqcam...`;
    If the latter, then use Expect. Also '$boink' never changes; did you want an infinite loop?

    And when putting things between code tags, you don't have to escape '&' as '&'. I'm assuming that you don't really have '&' there.

      I intentionally left the code general so that people could try it out themselves. the & came in from the HTML thingamajig, somehow.

      gqcam is a webcam program. I merely want to launch it in the background and have it update the cam every $howevermany seconds. It saves a file that is uploaded to the ftp server by this snippet of code.

      As for $boink, I would like for the loop to be infinite until i close that terminal window or kill the process.

        You might have some contention issues if you start your upload while gqcam is rewriting the file. You might want to rename the file first, wait a bit, then upload the renamed file. And go ahead and use system to start gqcam: system('gqcam &') and die "Error starting gqcam";

        For an infinite loop, all you need is a bare block:

        LOOP: { #do stuff redo LOOP; }

        What sort of errors does gqcam 'spew'?? Are they significant, or can you just redirect them to /dev/null and ignore them?