IceWalkers.com - Linux Software downloads and news
Name : Password :
Linux SoftwareLinux RPMLinux HowtosLink UsAboutAdvertise

Exists

 Perl Doc. Index   Quick jump:  
 
exists
exists EXPR

Given an expression that specifies a hash element or array element, returns true if the specified element in the hash or array has ever been initialized, even if the corresponding value is undefined. The element is not autovivified if it doesn't exist.

    print "Exists\n" 	if exists $hash{$key};
    print "Defined\n" 	if defined $hash{$key};
    print "True\n"      if $hash{$key};
    print "Exists\n" 	if exists $array[$index];
    print "Defined\n" 	if defined $array[$index];
    print "True\n"      if $array[$index];

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

Given an expression that specifies the name of a subroutine, returns true if the specified subroutine has ever been declared, even if it is undefined. Mentioning a subroutine name for exists or defined does not count as declaring it. Note that a subroutine which does not exist may still be callable: its package may have an AUTOLOAD method that makes it spring into existence the first time that it is called -- see perlsub.

    print "Exists\n" 	if exists &subroutine;
    print "Defined\n" 	if defined &subroutine;

Note that the EXPR can be arbitrarily complicated as long as the final operation is a hash or array key lookup or subroutine name:

    if (exists $ref->{A}->{B}->{$key}) 	{ }
    if (exists $hash{A}{B}{$key}) 	{ }
    if (exists $ref->{A}->{B}->[$ix]) 	{ }
    if (exists $hash{A}{B}[$ix]) 	{ }
    if (exists &{$ref->{A}{B}{$key}})   { }

Although the deepest nested array or hash will not spring into existence just because its existence was tested, any intervening ones will. Thus $ref->{"A"} and $ref->{"A"}->{"B"} will spring into existence due to the existence test for the $key element above. This happens anywhere the arrow operator is used, including even:

    undef $ref;
    if (exists $ref->{"Some key"})	{ }
    print $ref; 	    # prints HASH(0x80d3d5c)

This surprising autovivification in what does not at first--or even second--glance appear to be an lvalue context may be fixed in a future release.

See perlref/"Pseudo-hashes: Using an array as a hash" for specifics on how exists() acts when used on a pseudo-hash.

Use of a subroutine call, rather than a subroutine name, as an argument to exists() is an error.

    exists ⊂	# OK
    exists &sub();	# Error
 Perl Doc. Index   Quick jump:  
 
PhpMyAdmin 3.2.4 rc1
Php front-end to MySQL administration
Exim 4.71
Message transfer agent
Opera 10.10
Opera for Linux
ImageMagick 6.5.7.10
ImageMagick image processing studio
DeleGate 9.9.6-pre6
Proxy server which runs on multiple platforms
Inkscape 0.47
Vector graphic editor for SVG
Nano 2.1.99pre2
Emulate Pico while also offering a few enhancements.
Google Chrome Browser 4.0.249.11
Google’s open source browser project
Rhythmbox 0.12.6
Integrated music management application
Tellico 2.1.1
Collection manager for books, music, videos, and bibliographies
Free IT Magazines, White Papers, eBooks, and more !
Oracle Magazine

Contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more.

Vulnerability Management for Dummies

Get all the Facts and See How to Implement a Successful Vulnerability Management Program.

Website Magazine

Has tapped premier talent in the Internet industry for our content and each and every issue will contain practical advice and insights for website owners.

Linux Software Map
Find Linux RPM
Best Rated Linux Software
Most Rated Linux Software
Linux Distributions
Linux Howtos
Quick Survey

Please take our survey and help us improve our website to serve you better.

Thank you.
Linux Software
Linux / IT Resources
Site Resources
Google
Privacy Policy
Contact Us
Submit Software
Advertising info