Hi all,

I'm trying to figure out why I'm getting a "Useless use of a constant in void context" error message when running a program. I've read princepawn's Useless Use question, but I confess I'm not understanding what's being said. I'm still a fledgling, so some of the explanations are over my head. Note, however, that the program still generates my text file as I expect, so this error isn't stopping the program... I just want to understand it better. Below is my little program (which I think I stole mostly from Ovid):

#!/usr/bin/perl5 -w use strict; use File::Find; my $report = "LDT_results.txt"; open MYOUTPUT, "> $report" or die "Can't open $report: $!"; my @directories = ("/usr/local/lib"); my @foundfiles; # Collect all .pm files below each directory in @directories # and put them into @foundfiles find ( sub { push @foundfiles, $File::Find::name if /\.pm$/ }, @directories); # and output them all to the screen so I can see it's working my $pms = join("\n", @foundfiles), "\n"; print $pms; #and print them to my file "LDT_results.txt" print MYOUTPUT $pms; close MYOUTPUT;

I've tried tilly's and merlyn's suggestions about getting some diagnostics on the command line, but I don't seem to be able to get the right command going. I've tried the following:

command line>perldoc perldiag /Useless use -Mdiagnostics

and I get the following message:

syntax error in file /usr/local/bin/perldoc at line 5, next 2 tokens "use warnings"
syntax error in file /usr/local/bin/perldoc at line 17, next 2 tokens "my $bindir "
syntax error in file /usr/local/bin/perldoc at line 21, next 2 tokens "my $pod2man "
syntax error in file /usr/local/bin/perldoc at line 43, next 2 tokens "my $me "
syntax error in file /usr/local/bin/perldoc at line 55, next 2 tokens "my @global_found"
syntax error in file /usr/local/bin/perldoc at line 110, next 2 tokens "Text:"
syntax error in file /usr/local/bin/perldoc at line 111, next 2 tokens "Text:"
syntax error in file /usr/local/bin/perldoc at line 123, next 2 tokens "am_taint_checking("
syntax error in file /usr/local/bin/perldoc at line 154, next 2 tokens "}"
syntax error in file /usr/local/bin/perldoc at line 166, next 2 tokens "my $opts "
/usr/local/bin/perldoc has too many errors.

I know very little about Unix commands, but I'm starting to learn. I've also read some from the Llama book (I don't have the Camel book yet), but it's a little over my head.

If someone would be so kind as to explain why it doesn't like the way I'm using the variables, I'd appreciate it. Thanks!

Lori


In reply to Help with error msg "Useless use..." by Lori713

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.