Professional Web Applications Themes

!$state - PERL Beginners

All, If: $state={}; Then, what is: !$state...

  1. #1

    Default !$state




    Then, what is:

    David Guest

  2. #2

    Default RE: !$state

    $state evaluates as true (I think that's what you're asking).


    $state = {};

    print "\$state is true: $state\n";
    print "\$state is false";


    $state is true because it's not empty.
    It's a reference to a hash that is empty.

    -----Original Message-----
    From: David Arnold [mailto:com]
    Sent: Thursday, July 15, 2004 7:24 PM
    To: org
    Subject: !$state




    Then, what is:


    Tim Guest

  3. #3

    Default Re: !$state

    Hi Team,
    Tested code that prints a value for !$state when $state is initialized
    with my $state = ();

    #set $state to () to find out what !$state is
    use strict;
    use warnings;

    my $state =();

    print "\!\$state is:\t", !$state, "\n\n\n";

    print "\$state is:", $state, "\n\n\n";

    #end tested code

    so to investigate this further, I want to look at what perl takes as
    "Truth". I want to nail down for my own benefit the differences between
    uninitialized, undef, initialized as a reference to an empty hash or
    array or whatever. How these compare with the return value of undef()
    Quick, to the Fine Manual!

    perldoc perldoc tells me all about formatting and gives me the actually
    useful switches for the purposes of finding doentation:
    -f if I want doentation on a function
    -q to 'grep' the perl faqs

    How do I get an index or a table of contents? How do I find out how to search the perldocs for
    "control structures"

    I've tried:
    perldoc perldoc
    perldoc -f if
    perldoc -q control
    perldoc -q index
    perldoc -q contents
    perldoc -q perldoc

    perldoc perltoot
    gets me what looks like a nice OO tutorial, but how would I know it is
    there unless I'd seen it in a post on a website someplace.

    Thanks in advance.

    Tim Johnson said: 

    Kind regards,
    Hal Ashburner
    Harald Guest

  4. #4

    Default Finding perl doentation (was: Re: !$state)

    Harald Richard Ashburner wrote: 

    The best way to find stuff is to browse everything. Don't try to learn
    everything at once. Just browse and remember where everything is. As a
    programmer, I've found this is the biggest key. There is too much to
    know. The best you can do is *become* an index. You don't have to learn
    everything (but do try); it's enough to be able to jump straight to the
    info that you need.

    Which is what you were asking anyway, so...

    The "beginning" of the perl doentation is:

    perldoc perl

    Here you'll find a list of all the pods and a brief one line synopsis of
    what is contained in each. For more detail try:

    perldoc perltoc

    which contains a full table of contents for all the pods included with perl.


    As far as searching, you have several options.

    One is to use grep to search the pod. First find out where the main pod
    files are installed on your system:

    perldoc -l perl
    => /usr/share/perl/5.8/pod/perl.pod

    The run grep on all the pod files (perl*.pod). For example, here is a
    query I recently ran:

    grep 'while.\+defined.\+<.*>' /usr/share/perl/5.8/pod/perl*.pod

    looking for occurences of while (defined($var = <FH>)) and similar.

    Another good solution, is to install the great 'perlindex' tool from
    cpan <>. This is a very nice tool
    for searching all pod for perl and all installed manuals.

    Finally, there is where you can browse or search
    doentation for the last couple of versions of perl.

    Randy Guest

  5. #5

    Default Re: Finding perl doentation

    Randy W. Sims wrote:

    A couple of other (obious) web searches I omitted are:

    Randy Guest

  6. #6

    Default Re: !$state

    Tim Johnson said: 
    Nah, didn't say that. I just didn't know how to search the docs. 'perldoc
    perl' suggested by Randy has sorted me right out. I don't believe
    ActivePerl is available for my OS, at least I didn't find it with
    apt-cache search.

    A quick line in 'perldoc perldoc' suggesting 'perldoc perl' will tell you
    what is available would do the trick nicely from my point of view. But
    that's not to say my point of view is the most important, there may well
    be a good reason for it not to be there. And yes, I should have thought
    of trying 'man perl' but I'm thick ;)
    Kind regards,
    Hal Ashburner
    Harald Guest

  7. #7

    Default RE: !$state

    David Arnold wrote: 

    Now state is a reference to an anonymous HASH

    This is '' (i.e. "false"), because the ! operator returns 1 ("true") only
    for the values '', 0, and undef. Any reference will be "true" in this test,
    even a reference to a false value.


    $foo = \0;

    !$foo is false, because $foo is a reference
    !$$foo is true, because the scalar $foo refers to is false

    Make sense?
    Bob Guest

  8. #8

    Default Re: !$state

    >>>>> "Tim" == Tim Johnson <com> writes:

    Tim> "$state = ()" assigns the value of an empty list to the scalar $state, so it would evaluate to false.

    No, it doesn't. It evaluates () in a scalar context, which returns a
    scalar undef. Hence, same as "$state = undef". Right conclusion,
    wrong reasoning.

    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <com> <URL:>
    Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
    See for onsite and open-enrollment Perl training!
    Randal Guest

  9. #9

    Default RE: !$state

    Thank you, yes. That is an important distinction.

    -----Original Message-----
    From: Randal L. Schwartz [mailto:com]
    Sent: Fri 7/16/2004 7:17 AM
    To: org
    Subject: Re: !$state

    >>>>> "Tim" == Tim Johnson <com> writes:

    Tim> "$state = ()" assigns the value of an empty list to the scalar $state, so it would evaluate to false.

    No, it doesn't. It evaluates () in a scalar context, which returns a
    scalar undef. Hence, same as "$state = undef". Right conclusion,
    wrong reasoning.


    Tim Guest

Similar Threads

  1. Do I use a state?
    By spacehog in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: April 21st, 04:01 PM
  2. Down State CSS
    By Jansolo in forum Macromedia Dynamic HTML
    Replies: 0
    Last Post: July 13th, 09:50 AM
  3. 3d state
    By Hilmar Hermens in forum Macromedia Director 3D
    Replies: 0
    Last Post: June 13th, 09:03 AM
  4. state of the art
    By christian kuendig in forum ASP.NET Web Services
    Replies: 0
    Last Post: May 22nd, 10:44 PM
  5. Setting a default state for Multi-State buttons
    By Taylor3d in forum Macromedia Director Lingo
    Replies: 1
    Last Post: July 14th, 01:29 AM


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139