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

  • SEARCH
  • Home
  • 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 7021929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:30:51+00:00 2026-05-27T23:30:51+00:00

Where is the uninitialised value in the below code ? #!/usr/bin/perl use warnings; my

  • 0

Where is the uninitialised value in the below code?

#!/usr/bin/perl
use warnings;

my @sites = (undef, "a", "b");
my $sitecount = 1;
my $url;

while (($url = $sites[$sitecount]) ne undef) {
   $sitecount++;
}

Output:

Use of uninitialized value in string ne at t.pl line 6.
Use of uninitialized value in string ne at t.pl line 6.
Use of uninitialized value in string ne at t.pl line 6.
Use of uninitialized value in string ne at t.pl line 6.
  • 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-05-27T23:30:51+00:00Added an answer on May 27, 2026 at 11:30 pm

    You can’t use undef in a string comparison without a warning.

    if ("a" ne undef) { ... }
    

    will raise a warning. If you want to test if a variable is defined or not, use:

    if (defined $var) { ... }
    

    Comments about the original question:

    That’s a strange way to iterate over an array. The more usual way of doing this would be:

    foreach my $url (@sites) { ... }
    

    and drop the $sitecount variable completely, and don’t overwrite $url in the loop body. Also drop the undef value in that array. If you don’t want to remove that undef for some reason (or expect undefined values to be inserted in there), you could do:

    foreach my $url (@sites) {
      next unless defined $url;
      ...
    }
    

    If you do want to test for undefined with your form of loop construct, you’d need:

    while (defined $sites[$sitecount]) {
      my $url = $sites[$sitecount];
      ...
      $sitecount++;
    }
    

    to avoid the warnings, but beware of autovivification, and that loop would stop short if you have undefs mixed in between other live values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here are the errors: $ perl ftper.pl Use of uninitialized value $id in hash
What's wrong with the code below ? When run, I get: Use of uninitialized
In the code sample below, I would expect the output to be as follows,
I have a strange problem in matching a pattern. Consider the Perl code below
Valgrind is showing an uninitialised value of size 8 error. And occasionally, the below
I am getting this warning: Use of uninitialized value in eval \string\ at myscript.pl
I am cleaning my Perl code for production release and came across a weird
Here is some simple Perl to count the number of times a value occurs
i need to reproduce with the code below something like: myformdata[languages1] myformdata[languages2] myformdata[languages3] But
Possible Duplicate: How an uninitialised variable gets a garbage value? So when an undefined

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.