Q&A

Q1: What's the difference between the undefined value and undef?
A1: Not a whole lot. The undefined value is what gets put in variables, or in array or hash value locations when there isn't an actual value—if you use one without initializing it, or if you add elements to an array past the boundaries of that array. If you want to explicitly use the undefined value, for example, to undefine a variable or to include that value in an array, you use the undef function. Because of the close relationship between the undefined value and undef, it's very common to see undef used to mean the undefined value (as in “the last three elements of that array are undef”). In real code, if you use undef anywhere you want an undefined value, you won't go wrong. ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.