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

Shawn Hartsock hartsock at acm.org
Mon Aug 17 09:27:31 EDT 2009


Try this:

$query_string = undef;               #declare query string variable

while (@words){
        $query_string = $database_command . pop(@words) . $query_string;
 }

On Sun, Aug 16, 2009 at 7:51 PM, Joseph Mack NA3T<jmack at wm7d.net> wrote:
> Scott's code is working for my database queries now. Thanks that's a big
> relief.
>
> I assemble my query string iteratively
>
> my $database_command = magic strings to talk to database
> my @words = parseline($user_input);     #parsed input from user my
> $query_string;               #declare query string variable
>
> while (@words){
>        $query_string = $database_command . pop(@words) . $query_string;
> }
>
> Then I send $query string to the database.
>
> However on the first pass through the loop I get the warning "$query_string
> uninitialised". I can stop this message by initialising the variable to ' '
> when I declare it (this extra blank doesn't affect the query) but it seems a
> kludge. Initialising it to '' apparently is not initialising it, as I still
> get the message. Is there a better way to not get the message?
>
> 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!
> --
> TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG FAQ  : http://www.trilug.org/wiki/Frequently_Asked_Questions
>



-- 
/** Shawn.Hartsock http://hartsock.blogspot.com */



More information about the TriLUG mailing list