Warn of Symbolic Refs at "Compile" Time?

Discussion in 'Perl Misc' started by Nathan.Neff@gmail.com, May 27, 2005.

  1. Guest

    Hello,

    Is there a way to be warned of symbolic references when I run
    "perl -c"?

    Example:-----------------------------
    #!/usr/bin/perl
    # This code dies when it comes to print $$var_name.
    # perl -c doesn't say anything.
    # How can I get perl to warn me before I run the script?
    use strict;
    my $YES = "The quick brown fox";
    my $var_name = "YES";
    print "$$var_name";

    #Thanks
    #--Nate
     
    , May 27, 2005
    #1
    1. Advertising

  2. Guest

    wrote:
    > Hello,
    >
    > Is there a way to be warned of symbolic references when I run
    > "perl -c"?
    >
    > Example:-----------------------------
    > #!/usr/bin/perl
    > # This code dies when it comes to print $$var_name.
    > # perl -c doesn't say anything.
    > # How can I get perl to warn me before I run the script?
    > use strict;
    > my $YES = "The quick brown fox";
    > my $var_name = "YES";
    > print "$$var_name";


    No. At the time the last line (with the derefernce) is compiled, the
    compiler doesn't know that $var_name is not going to contain a scalar
    reference.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , May 27, 2005
    #2
    1. Advertising

  3. * schrieb:
    >
    > Is there a way to be warned of symbolic references when I run
    > "perl -c"?


    AFAIK, no. Calling "perl -c" checks the syntax of your script and
    there's no problem within. Your script *compiles* correctly.

    >
    > Example:-----------------------------
    > #!/usr/bin/perl
    > # This code dies when it comes to print $$var_name.
    > # perl -c doesn't say anything.
    > # How can I get perl to warn me before I run the script?
    > use strict;
    > my $YES = "The quick brown fox";
    > my $var_name = "YES";
    > print "$$var_name";


    When printing $$var_name you get a *runtime* error. I would be surprised
    if there is a possibility to detect runtime errors during compile time.

    regards,
    fabian
     
    Fabian Pilkowski, May 27, 2005
    #3
  4. In article <>,
    <> wrote:
    >Hello,
    >
    >Is there a way to be warned of symbolic references when I run
    >"perl -c"?
    >
    >Example:-----------------------------
    >#!/usr/bin/perl
    ># This code dies when it comes to print $$var_name.
    ># perl -c doesn't say anything.
    ># How can I get perl to warn me before I run the script?
    >use strict;
    >my $YES = "The quick brown fox";
    >my $var_name = "YES";
    >print "$$var_name";
    >


    -c will execute BEGIN and CHECK blocks so here's
    something that will work in your specific case:

    perl -ce 'BEGIN{ require "myscript.pl";}'
    Can't use string ("YES") as a SCALAR ref while "strict refs"
    in use at myscript.pl at line 8.
    Compilation failed in require at -e line 1.
    BEGIN failed--compilation aborted at -e line 1.

    hth,
    --
    Charles DeRykus
     
    Charles DeRykus, May 27, 2005
    #4
  5. <> wrote:

    > #!/usr/bin/perl


    > use strict;
    > my $YES = "The quick brown fox";

    ^^
    > my $var_name = "YES";
    > print "$$var_name";



    This with not output

    The quick brown fox

    even if you remove use strict.

    Symbolic references only work for variables that are in the
    symbol table, your $YES variable is not in the symbol table
    (lexical variables never are).


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, May 27, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Nagle
    Replies:
    3
    Views:
    305
    John Nagle
    Feb 25, 2007
  2. Nagaraj
    Replies:
    1
    Views:
    891
    Lionel B
    Mar 1, 2007
  3. Carter
    Replies:
    2
    Views:
    518
    Carter
    Mar 4, 2009
  4. HTML
    Replies:
    1
    Views:
    150
    Teemu Keiski
    Jan 28, 2006
  5. Yakov
    Replies:
    2
    Views:
    100
    Ben Morrow
    Aug 10, 2008
Loading...

Share This Page