Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I understand the underlying condition which causes a Useless use of private variable in void context error. However, I am encountering this error in at least one spot in my code and no matter what I do to tweak the small portion of code we're dealing with here, I can't make the error go away.

Perhaps the problem is occuring outside of this portion of code (it's a large function/sub so I would rather not post the entire thing unless it's necessary). However, the error specifically indicates the line below..

My code does what I need without any problems, but I'm cleaning up my code in general and this one has really got me.

My program is fairly large (all code totals about 16,000 lines) and the following error apperas with use warnings;.

Useless use of private variable in void context at /home/www/somedomain.com/beta.cgi line 2765.

Line 2765 is this:

my $generated_password = &GeneratePassword;

GeneratePassword() is the following:

sub GeneratePassword { my $password = `passwdgen -pa --length=6`; $password =~ s/Your password is: (.*)/$1/; chomp($password); return($password); }

When I run this, $generated_password contains the intended data (a six character password) just as it should. But I still get that error. I have tried parens around $generated_password and even tried doing away with the sub entirely and putting the contents of sub GeneratePassword directly into the calling parent. I still get the same error.

The only thing I could think of was that $1 from the regex match is considered private and "not used", thus useless? But doesn't the fact that $1 is stuffed into $password as the new value of that scalar mean that it is used?

If I haven't provided enough detail, let me know and I'll try to copy in the rest of the calling routine. It's over a hundred lines so I didn't want to pollute this question with even more unless definitely needed.

Hoping this isn't as simplistic and stupid as my gut is telling me it is.


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

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (7)
    As of 2020-12-04 08:24 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How often do you use taint mode?





      Results (58 votes). Check out past polls.

      Notices?