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

Anderson Silva afsilva at gmail.com
Sun Aug 16 20:05:51 EDT 2009


I was pretty sure this worked... have you tried it with double quotes?
my $query_string = "";

You can also use the defined() function to see if it is defined or not.

AS



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
>



-- 
http://www.the-silvas.com



More information about the TriLUG mailing list