Im afraid to say that this code is riddled with errors. I dont know how you came to write this, but its very strange indeed.
use Net::AIMTOC; use Term::ReadKey; $version = 0.01; #The version number $screenname = ""; #Contains the screenname for logging in $password = ""; #Password for logging in $out = "STDOUT"; #Set default output to the screen @targets; #Array containing screennames to watch
This is bad. You dont have strictures turned on, and accoridngly are getting warnings for doing dumb things (like put the @targets; all alone on a line like that.) This should read:
use strict; use warnings; use diagnostics; use Net::AIMTOC; use Term::ReadKey; my $version = 0.01; #The version number my $screenname = ""; #Contains the screenname for logging in my $password = ""; #Password for logging in my $out = "STDOUT"; #Set default output to the screen my @targets; #Array containing screennames to watch
But even then $version should change to $VERSION to be compatible with standard convention, and the tools that expect programs to comply with them.
sub process_args($) { my $iterate = 0; #Local variable for adding to @targets if ($_[0] eq "-v" || $_[0] eq "--version") { print "Thanks for supporting AimSpy. You are currently using +version $v +ersion of AimSpy.\n"; }
Now you prototype a sub for no reason at all, and then use $_[0] directly. This is bad practice in every way. (There are reasons to do both, but until you know what they are its unlikely you satisfy them.) And to add insult to injury you are reinventing a wheel here. You should be using Getopt::Long to do this.
open($out = SAVE, ">>$save") or open($out = SAVE, ">$save") or die "Can't save to file $save: $!\n";
This is all wrong. You probably meant something like
open my $out,">>$save" or die "Can't append to '$save': $!\n";
If a file doesnt exist to append to then it is created with >>
$targets[$iterate] = $_[0]; $iterate++;
You need to look up pop/push shift/unshift and splice in perlfunc.
push @targets,$item;
is how we normally write that.
try { $aim = Net::AIMTOC->new; $aim->connect; $aim->sign_on($screenname, $password); } catch Net::AIMTOC::Error with { my $err = shift; print $err->stringify, "\n"; };
try{}catch{} is not part of perl. If you are using this construct then it needs to be defined somewhere. Unless it is defined by Net::AIMTOC then you have a real problem here. Perhaps the Exception module is what you are missing.
I think you need to return to the tutorials for a while my friend. Reread perlsyn and perlopentut and stuff and then retry this. Several of the errors and potential errors in the above code would have prevented the program from compiling under strict. For good reason. In simple and somewhat harsh terms, unless you can explain in detail why you need strictures turned off then there is no excuse at all for not using them.
Good luck.
• Update:
Fixed the bug that Aristotle reported about no mentioning $! in the error message from a failed open. Thanks Aristotle
In reply to Re: Script help
by demerphq
in thread Script help
by Deleuze
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |