Dear Monks,

I'm very new to PERL (or programing) and wrote only one script so far. Even though the script runs fine, I have a warning and wish to ask your wisdom to understand it.

The purpose of the script is to parse a log and retrieve the relevant UserID's. After locating the userID in a line in the log I send it to the following sub (AddToUserArray) which inserts it to my user array (only if it wasn't inserted before).

The warning I receive is in the AddToUserArray sub. The warning is: "useless use of private variable in void context at ..." The line it points to is the sub line 18 (yes it only has brackets)

1 sub AddToUserArray { 2 my $UserID=$_[0]; 3 my $i=0; 4 my $Pexists=0; 5 my $Size; 6 7 if($UserID eq "") { # incase a bad UserID was recived. if Pexi +sts=1 it will skip &addtouserlog 8 $Pexists=1; 9 return $Pexists; 10 } 11 12 $Size=scalar(@Participants); 13 for($i;$i<$Size;$i++) { 14 if ($Participants[$i] eq $UserID) { 15 $Pexists=1; 16 last; 17 } 18 } 19 if ($Pexists==0) { 20 $Participants[$i]=$UserID; 21 } 22 return $Pexists; 23 }

Again, the entire script works fine but I want to understand this warning.

Thank you!

In reply to Useless use of private variable in void context by okarmi

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.