FAQ
Hi there,

What is the easiest way to store the first key of a hash to a scalar
variable?

Cheers,

Noah

Search Discussions

  • Wagner, David --- Senior Programmer Analyst --- WGO at Sep 10, 2008 at 8:13 pm

    -----Original Message-----
    From: Noah
    Sent: Wednesday, September 10, 2008 13:10
    To: Perl Beginners
    Subject: store first key of a hash to scalar

    Hi there,

    What is the easiest way to store the first key of a hash to a scalar
    variable?
    Perl handles the arrangement of the keys so it is efficient for
    Perl. What are you after? What was the data you brought in or ..... I
    know there are modules that will keep the data as it came in, but need
    more info to be able to assist.

    Wags ;)
    David R Wagner
    Senior Programmer Analyst
    FedEx Freight
    1.408.323.4225x2224 TEL
    1.408.323.4449 FAX
    http://fedex.com/us

    Cheers,

    Noah

    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    http://learn.perl.org/

    **********************************************************************
    This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited.
    **********************************************************************
  • John W. Krahn at Sep 10, 2008 at 8:19 pm

    Noah wrote:
    Hi there, Hello,
    What is the easiest way to store the first key of a hash to a scalar
    variable?
    A hash doesn't have a "first" key. Which key do you really want?


    John
    --
    Perl isn't a toolbox, but a small machine shop where you
    can special-order certain sorts of tools at low cost and
    in short order. -- Larry Wall
  • Noah at Sep 10, 2008 at 8:23 pm
    okay that basically answers my question. I will have to figure out to
    define a key that is the root key.


    John W. Krahn wrote:
    Noah wrote:
    Hi there, Hello,
    What is the easiest way to store the first key of a hash to a scalar
    variable?
    A hash doesn't have a "first" key. Which key do you really want?


    John
  • Wagner, David --- Senior Programmer Analyst --- WGO at Sep 10, 2008 at 8:51 pm

    -----Original Message-----
    From: Noah
    Sent: Wednesday, September 10, 2008 13:23
    To: John W. Krahn
    Cc: Perl Beginners
    Subject: Re: store first key of a hash to scalar

    okay that basically answers my question. I will have to
    figure out to
    define a key that is the root key.
    You can have various key combinations: $hash->{key1}{key2}.....
    where key1 could be the root portion and key2 a subset,
    etc

    Just remember you need to be able to get your head around what
    you do. You can even have arrays associated with the hash data, so it
    can be very complex, but make sure that you know what you are after or
    be able to ask the questions that will give you a good understanding of
    what you need.

    Wags ;)
    David R Wagner
    Senior Programmer Analyst
    FedEx Freight
    1.408.323.4225x2224 TEL
    1.408.323.4449 FAX
    http://fedex.com/us

    John W. Krahn wrote:
    Noah wrote:
    Hi there, Hello,
    What is the easiest way to store the first key of a hash
    to a scalar
    variable?
    A hash doesn't have a "first" key. Which key do you really want?


    John
    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    http://learn.perl.org/

    **********************************************************************
    This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited.
    **********************************************************************
  • Mr. Shawn H. Corey at Sep 10, 2008 at 10:12 pm

    On Wed, 2008-09-10 at 13:23 -0700, Noah wrote:
    okay that basically answers my question. I will have to figure out to
    define a key that is the root key.


    John W. Krahn wrote:
    Noah wrote:
    Hi there, Hello,
    What is the easiest way to store the first key of a hash to a scalar
    variable?
    A hash doesn't have a "first" key. Which key do you really want?


    John
    Hashes don't have root keys either; all keys are equal in a hash. And
    all their values are equal too.


    --
    Just my 0.00000002 million dollars worth,
    Shawn

    "Where there's duct tape, there's hope."
    Cross Time Cafe

    "Perl is the duct tape of the Internet."
    Hassan Schroeder, Sun's first webmaster
  • Rob Dixon at Sep 10, 2008 at 9:05 pm

    Noah wrote:
    John W. Krahn wrote:
    Noah wrote:
    What is the easiest way to store the first key of a hash to a scalar
    variable?
    A hash doesn't have a "first" key. Which key do you really want?
    okay that basically answers my question. I will have to figure out to
    define a key that is the root key.
    Describe your data Noah. What are you trying to do?

    Rob
  • Noah at Sep 10, 2008 at 11:28 pm
    Hi there,

    could somebody please suggest some other ways to simplify the reading
    and perhaps make the following process quicker?


    print CHANGE "what 1\n" unless ( grep (/what\s1/, @lines ) );
    print CHANGE "what 2\n" unless ( grep (/what\s2/, @lines ) );
    print CHANGE "what 3\n" unless ( grep (/what\s3/, @lines ) );
    print CHANGE "what 4\n" unless ( grep (/what\s4/, @lines ) );
    print CHANGE "what 5\n" unless ( grep (/what\s5/, @lines ) );
    print CHANGE "what 6\n" unless ( grep (/what\s6/, @lines ) );
    print CHANGE "what 7\n" unless ( grep (/what\s7/, @lines ) );

    Cheers,

    Noah
  • Wagner, David --- Senior Programmer Analyst --- WGO at Sep 10, 2008 at 11:37 pm

    -----Original Message-----
    From: Noah
    Sent: Wednesday, September 10, 2008 16:28
    To: Perl Beginners
    Subject: matching lines in array - other ways to code

    Hi there,

    could somebody please suggest some other ways to simplify the reading
    and perhaps make the following process quicker?


    print CHANGE "what 1\n" unless ( grep (/what\s1/, @lines ) );
    print CHANGE "what 2\n" unless ( grep (/what\s2/, @lines ) );
    print CHANGE "what 3\n" unless ( grep (/what\s3/, @lines ) );
    print CHANGE "what 4\n" unless ( grep (/what\s4/, @lines ) );
    print CHANGE "what 5\n" unless ( grep (/what\s5/, @lines ) );
    print CHANGE "what 6\n" unless ( grep (/what\s6/, @lines ) );
    print CHANGE "what 7\n" unless ( grep (/what\s7/, @lines ) );
    print CHANGE "what $1\n" unless ( grep (/what\s([1-7])/, @lines
    ) );

    Wags ;)
    David R Wagner
    Senior Programmer Analyst
    FedEx Freight
    1.408.323.4225x2224 TEL
    1.408.323.4449 FAX
    http://fedex.com/us


    Cheers,

    Noah

    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    http://learn.perl.org/

    **********************************************************************
    This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited.
    **********************************************************************
  • Noah at Sep 10, 2008 at 11:55 pm

    Wagner, David --- Senior Programmer Analyst --- WGO wrote:
    -----Original Message-----
    From: Noah
    Sent: Wednesday, September 10, 2008 16:28
    To: Perl Beginners
    Subject: matching lines in array - other ways to code

    Hi there,

    could somebody please suggest some other ways to simplify the reading
    and perhaps make the following process quicker?


    print CHANGE "what 1\n" unless ( grep (/what\s1/, @lines ) );
    print CHANGE "what 2\n" unless ( grep (/what\s2/, @lines ) );
    print CHANGE "what 3\n" unless ( grep (/what\s3/, @lines ) );
    print CHANGE "what 4\n" unless ( grep (/what\s4/, @lines ) );
    print CHANGE "what 5\n" unless ( grep (/what\s5/, @lines ) );
    print CHANGE "what 6\n" unless ( grep (/what\s6/, @lines ) );
    print CHANGE "what 7\n" unless ( grep (/what\s7/, @lines ) );
    print CHANGE "what $1\n" unless ( grep (/what\s([1-7])/, @lines
    ) );

    okay poor example. what about this?

    print CHANGE "not sure\n" unless ( grep (/not\ssure/, @lines ) );
    print CHANGE "could be\n" unless ( grep (/could\sbe/, @lines ) );
    print CHANGE "this line\n" unless ( grep (/this\sline/, @lines ) );
    print CHANGE "okay what\n" unless ( grep (/okay\swhat/, @lines ) );
    print CHANGE "daft punk\n" unless ( grep (/daft\spunk/, @lines ) );
    print CHANGE "no way\n" unless ( grep (/no\sway/, @lines ) );
    print CHANGE "wish there\n" unless ( grep (/wish\sthere/, @lines ) );
  • Paul Johnson at Sep 10, 2008 at 11:56 pm

    On Wed, Sep 10, 2008 at 06:37:31PM -0500, Wagner, David --- Senior Programmer Analyst --- WGO wrote:
    From: Noah

    could somebody please suggest some other ways to simplify the reading
    and perhaps make the following process quicker?


    print CHANGE "what 1\n" unless ( grep (/what\s1/, @lines ) );
    print CHANGE "what 2\n" unless ( grep (/what\s2/, @lines ) );
    print CHANGE "what 3\n" unless ( grep (/what\s3/, @lines ) );
    print CHANGE "what 4\n" unless ( grep (/what\s4/, @lines ) );
    print CHANGE "what 5\n" unless ( grep (/what\s5/, @lines ) );
    print CHANGE "what 6\n" unless ( grep (/what\s6/, @lines ) );
    print CHANGE "what 7\n" unless ( grep (/what\s7/, @lines ) );
    print CHANGE "what $1\n" unless ( grep (/what\s([1-7])/, @lines
    ) );
    Not really.

    my @what;
    /what\s([1-7])/ && $what[$1]++ for @lines;
    $what[$_] || print CHANGE "what $_\n" for 1 .. 7;

    --
    Paul Johnson - paul@pjcj.net
    http://www.pjcj.net
  • Noah at Sep 11, 2008 at 1:14 am
    Hi there,

    could somebody please suggest some other ways to simplify the reading
    and perhaps make the following process quicker? I have a better example
    now.

    print CHANGE "not sure\n" unless ( grep (/not\ssure/, @lines ) );
    print CHANGE "could be\n" unless ( grep (/could\sbe/, @lines ) );
    print CHANGE "this line\n" unless ( grep (/this\sline/, @lines ) );
    print CHANGE "okay what\n" unless ( grep (/okay\swhat/, @lines ) );
    print CHANGE "daft punk\n" unless ( grep (/daft\spunk/, @lines ) );
    print CHANGE "no way\n" unless ( grep (/no\sway/, @lines ) );
    print CHANGE "wish there\n" unless ( grep (/wish\sthere/, @lines ) );

    Cheers,

    Noah
  • Mr. Shawn H. Corey at Sep 11, 2008 at 2:15 am

    On Wed, 2008-09-10 at 18:14 -0700, Noah wrote:
    Hi there,

    could somebody please suggest some other ways to simplify the reading
    and perhaps make the following process quicker? I have a better example
    now.

    print CHANGE "not sure\n" unless ( grep (/not\ssure/, @lines ) );
    print CHANGE "could be\n" unless ( grep (/could\sbe/, @lines ) );
    print CHANGE "this line\n" unless ( grep (/this\sline/, @lines ) );
    print CHANGE "okay what\n" unless ( grep (/okay\swhat/, @lines ) );
    print CHANGE "daft punk\n" unless ( grep (/daft\spunk/, @lines ) );
    print CHANGE "no way\n" unless ( grep (/no\sway/, @lines ) );
    print CHANGE "wish there\n" unless ( grep (/wish\sthere/, @lines ) );
    my @list = (
    {
    re => qr/not\ssure/,
    msg => 'not sure',
    },
    {
    re => qr/could\sbe/,
    msg => 'could be',
    },
    # etc.
    );

    for my $item ( @list ){
    print CHANGE "$item->{msg}\n" unless( grep( /$item->{re}/, @lines ) );
    }



    --
    Just my 0.00000002 million dollars worth,
    Shawn

    "Where there's duct tape, there's hope."
    Cross Time Cafe

    "Perl is the duct tape of the Internet."
    Hassan Schroeder, Sun's first webmaster

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedSep 10, '08 at 8:09p
activeSep 11, '08 at 2:15a
posts13
users6
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase