[TriLUG] perl: how to initialise a variable that I want to be NULL

Joseph Mack NA3T jmack at wm7d.net
Mon Aug 17 21:26:05 EDT 2009

Hi Michael, Shawn

> Something else is wrong with your code, that should work. 
> Are you sure single quotes didn't work?

It didn't yesterday, but today it works fine. (Presumably I 
could go back to yesterday afternoon's code to find out why, 
but for the moment, I'll just take working code). This code 
does all the expected things

#! /usr/bin/perl

use strict;
use warnings;

my $query_string = "";
$query_string = "foo " . $query_string; # string is already initialised

$query_string = '';
$query_string = "foo " . $query_string; # string is already initialised

$query_string = "foo " . $query_string; # string not initialised

$query_string = undef;
$query_string = "foo " . $query_string; # string not initialised

> ... that's not kludgy. It's just the way things are. It 
> wouldn't matter what programming language you are using.

Yes, I realised this as soon as I saw the problem. I had 
expected that '' would do as an initialised value (which 
should have worked, but there must have been something wrong 
with my code yesterday). I could also see the logic in '' 
being undef, but if that was the case, then what did I use 
to initialise a string. It turns out that both '' and "" 

Thanks Joe

Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!

More information about the TriLUG mailing list