Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:02:27+00:00 2026-06-06T22:02:27+00:00

Compare using perl -w -Mstrict : # case Alpha print $c; … # case

  • 0

Compare using perl -w -Mstrict:

# case Alpha
print $c;

…

# case Bravo
if (0) {
  my $c = 1;
}

print $c;

…

# case Charlie
my $c = 1 if 0;
print $c;

Alpha and Bravo both complain about the global symbol not having an explicit package name, which is to be expected. But Charlie does not give the same warning, only that the value is uninitialized, which smells a lot like:

# case Delta
my $c;
print $c;

What exactly is going on under the hood? (Even though something like this should never be written for production code)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:02:29+00:00Added an answer on June 6, 2026 at 10:02 pm

    You can think of a my declaration as having an action at compile-time and at run-time. At compile-time, a my declaration tells the compiler to make a note that a symbol exists and will be available until the end of the current lexical scope. An assignment or other use of the symbol in that declaration will take place at run-time.

    So your example

    my $c = 1 if 0;
    

    is like

    my $c;         # compile-time declaration, initialized to undef
    $c = 1 if 0;   # runtime -- as written has no effect
    

    Note that this compile-time/run-time distinction allows you to write code like this.

    my $DEBUG;    # lexical scope variable declared at compile-time
    BEGIN {
        $DEBUG = $ENV{MY_DEBUG};   # statement executed at compile-time
    };
    

    Now can you guess what the output of this program is?

    my $c = 3;
    BEGIN {
        print "\$c is $c\n";
        $c = 4;
    }
    print "\$c is $c\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I compare two hashes in Perl without using Data::Compare?
I'm using the Perl mod XML::SemanticDiff which can compare two XML documents. I want
I'm currently using this compare options to sort a list of strings: [self compare:aString
I have been using SQL Compare by Redgate at my company and was very
I'm currently benchmarking partitioned tables with SQL Server 2005 to compare them to using
I'm using NUnit v2.5 to compare strings that contain composite Unicode characters. Although comparison
I'm using strcmp to compare character arrays in c++, but I get the following
Using VB6 I want to compare the system date, if the exe should not
We are using a query that uses coalesce to compare potentially null values. I
I am thinking of using BigDecimal to compare two currency values rounded to 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.