PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 27, 2022

[FIXED] Why does my Perl program warn about an uninitialized value?

 April 27, 2022     perl, scripting, warnings     No comments   

Issue

I've written the Perl script below which generates a warning and I can't work out why.

#!/usr/local/bin/perl -w

$status = $ENV{ 'STATUS' };
if ( $status eq "" )
{
    $status = 0;
}
else
{
    $status = 1;
}

It says "Use of uninitialized value in string eq at ./x.pl line 4."

Line 4 is the "if ( $status eq "" )" line, but the variable was initialised...

How can I get rid of this warning?


Solution

$ENV{'STATUS'} may not be defined.

If you run

export STATUS=blah

in the shell before running the Perl script, it will work.

Fix it with

#!/usr/local/bin/perl -w
$status = $ENV{ 'STATUS' };
if (!defined($status) || $status eq "" )
{
    $status = 0;
}
else
{
    $status = 1;
}


Answered By - Charles Ma
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing