in reply to why can't compare a variable with undef directly?
When you 'compare variables', you compare their values. undef means that there is no useful value to compare.
Still, it's a warning, not an error. Look at the following example. It's not something very useful, but it shows that if you really want to, you CAN compare undef.
#!/usr/bin/perl use warnings; use v5.14; { no warnings 'uninitialized'; if ('ssd' ne undef) { say "The strings are not equal"; } } { no warnings 'uninitialized'; if ('' eq undef) { say "The strings seem equal"; } }
Output:
The strings are not equal The strings seem equal
Edit: updated for clarity, added the example
- Luke
|
|---|