Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Like dws, I'm surprised this would run; it doesn't for me under 5.6.1. Your declaration of %p almost has the syntax for a hash slice, except that you can't do that in a my declaration. Something like my %p; @p{ 'eyes', 'hair', 'etc' } = (); would be legitimate, if unusual.

As for why do_head doesn't do what you think, I believe you're misunderstanding the behavior of undef in an array. undef in an array or hash doesn't just disappear, it's still something. This is notably different from its behavior in a list (which is not an array!). For instance, see the behavior of this snippet:

@a = ( ); @c = ( undef ); die "a" if @a; die "b" if ( undef, undef ); die "c" if @c

Particularly, it dies with 'c', not 'a' or 'b'. In a boolean context--like an if statement--an array takes the value of its length, not its members. In my example, this is 1, which is a true value. Likewise, your three undefs give @data a true value. So, your list of undefs is in fact true when assigned to an array. You were probably expecting the behavior of a list, which in a boolean context evaluates to its last element (e.g., die "d" if ( 1, undef ); die "e" if ( undef, 1 ); dies with 'e'). The solution, if you wish to keep the behavior of printing when the elements are defined, can be found in dws' post.

In reply to Re: Testing array of hash values by athomason
in thread Testing array of hash values by legLess

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2022-01-27 06:08 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (70 votes). Check out past polls.