in reply to Re: use of $sub
in thread use of $sub

smdr appears in the text of the error message of the code I linked to in the same line of the code that has $sub. I think it may have simply been something to do with the original use of the code. It wasn't part of a system error output. Yes, the error is 'used only once' as you stated. I think my real question is how do I use $sub with 'use warnings' and not get the warning? Also, the links I found on the use of sub were "sub" rather than "$sub" and I would like to understand the addition of "$".

Replies are listed 'Best First'.
Re^3: use of $sub
by tobyink (Canon) on Oct 19, 2012 at 14:30 UTC

    I would like to understand the addition of "$"

    Not, "$" but "$!". The exclamation mark is not just for decoration. See perlvar.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      Not, "$" but "$!".

      No, I don't mean "$!". I looked up "$!" and understood that. I mean the addition of "$" to "SUB" resulting in "$SUB".

        Oh OK. $SUB is just a variable... same idea as $TUB or $PUB or $RUB... nothing special. In this case it's undefined, so when interpolated into the string doesn't do anything.

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re^3: use of $sub
by roboticus (Chancellor) on Oct 19, 2012 at 14:50 UTC

    JimLS:

    I expect that just adding something like this:

    sub PREVENT_USELESS_WARNING { my $t = $sub }

    or similar shenanigans would do fine.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re^3: use of $sub
by Anonymous Monk on Oct 19, 2012 at 14:27 UTC
    Go ahead and add use diagnostics; to see
    $ perl -Mdiagnostics -e " $foo = 1; " Name "main::foo" used only once: possible typo at -e line 1 (#1) (W once) Typographical errors often show up as unique variable nam +es. If you had a good reason for having a unique name, then just menti +on it again somehow to suppress the message. The our declaration is provided for this purpose. NOTE: This warning detects symbols that have been used only once s +o $c, @c, %c, *c, &c, sub c{}, c(), and c (the filehandle or format) are con +sidered the same; if a program uses $c only once but also uses any of the +others it will not trigger this warning.

    warnings are useful, but adding strict is better. Read this if you want to cut your development time in half! explains how/why to use them.

Re^3: use of $sub
by toolic (Bishop) on Oct 19, 2012 at 14:38 UTC
    smdr is inside a quoted string of text. You have to ask the original author what he meant by smdr.

    not get the warning?
    Like I said, you need to assign a value to $SUB, or just delete the variable if you don't need it.