Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

The system function undef can be used on the right side of split function or array assignment to skip values that you do not need. For example:

$current_time='14:30:05'
(undef, $min, $sec)=$current_time

In this role it is similar to /dev/null in Unix.

But if used on the right side this function deletes the variable from the symbol table, For example

$line=undef; say "Does not exists" unless(defined($line));

Is this correct understanding?

Edited:

A clarification:

In FAT if you delete a file from the directory it is still present but marked as deleted.

So the fact that that the item still present in symbol table but has a special value does not change the fact that semantically it is deleted and its memory can be now reused.

In other words, if the item in a Perl symbol table has value undef for all practical purposes is it that same as deleted item in FAT and should be treated by interpreter developers in the same way as "not found" item. Implementation is is not flawless though. With the use warnings statement "uninitialized value" warnings are not produced for operations like $i+4 or $i++:

[0]  # cat undef_test.pl
#!usr/bin/perl
use warnings;
use strict;
my ($i,$l,$m);
my $j=$i;
my $k=$l++;
print "m=$m;j=$j,k=$k\n";

[0]  # perl  undef_test.pl
Use of uninitialized value $m in concatenation (.) or string at undef_test.pl line 7.
Use of uninitialized value $j in concatenation (.) or string at undef_test.pl line 7.
m=;j=,k=0

NOTE:

I think undef is not a value, as many here assume, but a function, So
$X=undef;
actually means in Perl:
$X=undef();
and is equivalent to
undef $X;

In reply to Two meanings of undef by likbez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-16 04:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found