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.


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

• 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

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.