Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-20 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found