defined is a verb, to detect whether a scalar has a value.

undef is a noun, to assign a scalar not have a value.

In the code below, some values are true, some false, but all are defined. Then, assigning undef to them means they are no longer defined. Notice that the hash still contains the key a, with no value associated with it; you would need to delete the key to remove the key from the hash.

our ( $s, $t, %h, @a ); $s = 0; $h{a} = ""; $a[1] = 1; print_vals(); print "\nundef-ing values\n"; $s = undef; $h{a} = undef; $a[1] = undef; print_vals(); sub print_vals { print "S " if ( defined $s ); print "T " if ( defined $t ); print "\n"; print "h{a} " if ( defined $h{a} ); print "h{b} " if ( defined $h{b} ); print "\n"; print "a[1] " if ( defined $a[1] ); print "a[0] " if ( defined $a[0] ); print "\n"; }

--
TTTATCGGTCGTTATATAGATGTTTGCA


In reply to Re: Splitting a string, Just want to Keep Half by TomDLux
in thread Splitting a string, Just want to Keep Half by Dru

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.