Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: string initialization error

by perlancar (Hermit)
on Dec 21, 2018 at 14:25 UTC ( [id://1227568]=note: print w/replies, xml ) Need Help??


in reply to string initialization error

It looks like you set $page to "" and then possibly set it to undef in the following line if there is no query parameter named "page". By the time perl compares $page to 'main', it's getting an undef value.

You probably meant something like: my $page = $query->param("page") // '';

or: my $page = $query->param("page") || '';

Replies are listed 'Best First'.
Re^2: string initialization error
by haukex (Archbishop) on Dec 21, 2018 at 15:44 UTC
    or: my $page = $query->param("page") || '';

    Caveat: That will also assign '' to $page if $query->param("page") returns 0 or "0" (the same applies to hippo's answer).

    TIMTOWTDI: Another alternative to the code from the OP may be (at least on Perl v5.12 and up):

    sub loadPage { my $page = $query->param("page"); if ( length($page) && $page eq 'main' ) { loadMainPage(); return 1; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1227568]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-24 09:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found