when i axsess a value from an hash it dose nothing

Discussion in 'Perl Misc' started by atbusbook@aol.com, May 7, 2006.

  1. Guest

    %foo = {i=>1,b=>2};
    print $foo{i};

    its output == ""
     
    , May 7, 2006
    #1
    1. Advertising

  2. David Squire Guest

    wrote:
    > %foo = {i=>1,b=>2};
    > print $foo{i};
    >
    > its output == ""
    >


    You've used the wrong sort of brackets:

    >perl -e '%foo = (i => 1,b => 2); print $foo{i}'

    1

    DS
     
    David Squire, May 7, 2006
    #2
    1. Advertising

  3. David Squire Guest

    David Squire wrote:
    > wrote:
    >> %foo = {i=>1,b=>2};
    >> print $foo{i};
    >>
    >> its output == ""
    >>

    >
    > You've used the wrong sort of brackets:
    >
    > >perl -e '%foo = (i => 1,b => 2); print $foo{i}'

    > 1


    Further clarification: {} returns a reference to a hash, so this works:

    >perl -e '$foo = {i => 1,b => 2}; print $$foo{i}'

    1

    DS
     
    David Squire, May 7, 2006
    #3
  4. Matt Garrish Guest

    <> wrote in message
    news:...
    > %foo = {i=>1,b=>2};


    That's not how you declare a hash. Please ask perl to help you before you
    ask others to do so:

    use strict;
    use warnings;
    my %foo = {i=>1,b=>2};
    my %bar = (i=>1,b=>2);

    ------
    Output:
    Reference found where even-sized list expected at - line 3.

    Matt
     
    Matt Garrish, May 7, 2006
    #4
  5. Guest

    thanks
     
    , May 7, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. al
    Replies:
    3
    Views:
    2,698
  2. Car
    Replies:
    3
    Views:
    3,414
    Richard Bos
    Feb 28, 2008
  3. rp
    Replies:
    1
    Views:
    556
    red floyd
    Nov 10, 2011
  4. Une bévue
    Replies:
    5
    Views:
    155
    Une bévue
    Aug 10, 2006
  5. Devin Jeanpierre
    Replies:
    2
    Views:
    494
    Devin Jeanpierre
    Feb 14, 2012
Loading...

Share This Page