Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

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

Hello milanpwc,

From the documentation exists:

A hash or array element can be true only if it's defined and defined o +nly if it exists, but the reverse doesn't necessarily hold true.

So why you are expecting to be true on not defined elements (not existing elements)?

Is it more clear or still confusing?

Also take notice from documentation:

exists may also be called on array elements, but its behavior is much +less obvious and is strongly tied to the use of delete on arrays. WARNING: Calling exists on array values is strongly discouraged. The n +otion of deleting or checking the existence of Perl array elements is + not conceptually coherent, and can lead to surprising behavior.

Update: I think I understand why you are confused. You are not assigning to all elements in the array the value 2. Only to one element. See below:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @array; $array[3] = 2; print Dumper \@array; __END__ $ perl test.pl $VAR1 = [ undef, undef, undef, 2 ];

BR / Thanos

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Difference between exists and defined by thanos1983
in thread Difference between exists and defined by milanpwc

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 meditating upon the Monastery: (4)
As of 2024-04-25 17:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found