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

Shawn Hartsock hartsock at acm.org
Mon Aug 17 10:19:16 EDT 2009


Ignore my last post. I didn't have enough coffee in me.

You should be fine with...

  $query_string = '';

... that's not kludgy. It's just the way things are. It wouldn't
matter what programming language you are using. Now, you could
alternatively do a "prime the pump" line or two above the loop,
popping off the first @words element then dropping into the loop but
that's probably not any more aesthetically pleasing.

On Mon, Aug 17, 2009 at 9:27 AM, Shawn Hartsock<hartsock at acm.org> wrote:
> 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 */
>



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



More information about the TriLUG mailing list