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

Re: use of $sub

by toolic (Bishop)
on Oct 19, 2012 at 14:08 UTC ( #999933=note: print w/replies, xml ) Need Help??

in reply to use of $sub

The string $SUB only shows up in that code once. You probably get a warning message like:
Name "main::SUB" used only once: possible typo
Generally, variables are expected to be assigned a value before they are used. Use diagnostics to get more information.
Also wondering what "smdr" in the error message refers to.
What error message? You should post the exact error message you are receiving, as well as at least a snippet of the relevant code.

Replies are listed 'Best First'.
Re^2: use of $sub
by JimLS (Novice) on Oct 19, 2012 at 14:20 UTC
    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 "$".


      I expect that just adding something like this:

      sub PREVENT_USELESS_WARNING { my $t = $sub }

      or similar shenanigans would do fine.


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

      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.

      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".
      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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999933]
[erix]: average between 1 and 20
[erix]: ( median troll aka 'the bird' )

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2018-06-21 16:30 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.