Is there any context in which a string containing ONLY whitespace tests false?
Here's the situation:
The HTML output page of a script prints, "Hello, $name!" to greet the visitor.
First the script imports the user's info file that contains their name, among other things, via require.
If the user file does not contain a $name variable, as in the case of first-time visitors, & the output page will say, "Hello, Guest!".
require $user_file_path;
$name = $nick_name || "$salutation $last_name";
$name ||= 'Guest';
The problem is in the case that there's no $nick_name, $salutation, or $last_name variables.
So $name gets assigned " " in the second line, and line 3 can't change it to 'Guest' because " " tests true.
The output page ends up reading, "Hello, !"
I know I could use a regexp or any number of other ways to get rid of that pesky whitespace string, but I'm a stubborn guy who doesn't want to add an extra line of code in there.
What I want is a module or something that I can import which will make it so any string containing only whitespace tests false. I've never written a module and I don't even know if what I want is possible to do, so I need some friendly guideance.
Many thanks!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.