[26190] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8379 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 1 11:05:29 2005

Date: Thu, 1 Sep 2005 08:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 1 Sep 2005     Volume: 10 Number: 8379

Today's topics:
        how to get tomorrow date using Date::CALC  <not_valid2@yahoo.com>
        values of hash of hash <ngoc@yahoo.com>
    Re: values of hash of hash <mpapec@nohome.com>
    Re: values of hash of hash <ngoc@yahoo.com>
    Re: values of hash of hash (Anno Siegel)
    Re: values of hash of hash xhoster@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 1 Sep 2005 07:19:42 -0500
From: "Bob" <not_valid2@yahoo.com>
Subject: how to get tomorrow date using Date::CALC 
Message-Id: <4316f203$0$63625$8046368a@newsreader.iphouse.net>

want to take a date and return tomorrow's date..
How to convert  $tomorrow back to  YY-MM-DD  format?
What is the inverse of     Date_to_Days ?


 .. perl2.pl ---------------------------
use strict;   use warnings;   use Date::Calc qw(:all);

my ($yr2, $mon2, $day2, $tomorrow);   my ($year, $month, $day);
$yr2 = 2005;   $mon2 = 3;   $day2 = 20;

print ("    date- year: $yr2   month: $mon2    day:$day2 \n");
$tomorrow = Date_to_Days($yr2,$mon2,$day2) + 1;
print ("tomorrow: $tomorrow \n");

($year,$month,$day) = Today([$tomorrow]);
print ("tommorow- year: $year   month: $month    day:$day \n");
------------------------------------------------------------------

  output  ------------------------------------
D:\edu\lrn\perl\date>perl date2.pl
    date- year: 2005   month: 3    day:20
tomorrow: 732026
tommorow- year: 2005   month: 9    day:1





------------------------------

Date: Thu, 01 Sep 2005 11:27:32 +0200
From: ngoc <ngoc@yahoo.com>
Subject: values of hash of hash
Message-Id: <4316d68c$1@news.broadpark.no>

I have
$hash{1}{2}{3} = 7;
$hash{1}{4}{5} = 6;
I want to get 7 and 6 without using three for loop and keys function
How can I do it?


------------------------------

Date: Thu, 01 Sep 2005 12:43:51 +0200
From: Matija Papec <mpapec@nohome.com>
Subject: Re: values of hash of hash
Message-Id: <4rmdh1t62rk309bhs4p09itd6b71hte3aj@4ax.com>

On Thu, 01 Sep 2005 11:27:32 +0200, ngoc <ngoc@yahoo.com> wrote:

>I have
>$hash{1}{2}{3} = 7;
>$hash{1}{4}{5} = 6;
>I want to get 7 and 6 without using three for loop and keys function
>How can I do it?

use Data::Dumper;
my $s = Dumper \%hash;
my @numbers = $s =~ /([76])/g;

:)

btw, is there a reason for using a hash? perhaps you could be better
with arrays (all you keys are numeric).




------------------------------

Date: Thu, 01 Sep 2005 12:15:34 +0200
From: ngoc <ngoc@yahoo.com>
Subject: Re: values of hash of hash
Message-Id: <4316e1ce$1@news.broadpark.no>

My nummeric key is example only. My real application has keys that mix 
of text and number.
My problem is, I have to compare data from two projects and find out 
duplicated data. Two projects presented as two hash. If first level key 
is different (using exist function), put the whole data attached to it 
in an array. Currently, I have to access level 2, level 3 keys before 
getting it's real value. It is not advanced computing. So I want to 
access all values without using keys. Using "values %hash" just gives me 
next level hash.

Matija Papec wrote:
> On Thu, 01 Sep 2005 11:27:32 +0200, ngoc <ngoc@yahoo.com> wrote:
> 
> 
>>I have
>>$hash{1}{2}{3} = 7;
>>$hash{1}{4}{5} = 6;
>>I want to get 7 and 6 without using three for loop and keys function
>>How can I do it?
> 
> 
> use Data::Dumper;
> my $s = Dumper \%hash;
> my @numbers = $s =~ /([76])/g;
> 
> :)
> 
> btw, is there a reason for using a hash? perhaps you could be better
> with arrays (all you keys are numeric).
> 
> 


------------------------------

Date: 1 Sep 2005 11:48:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: values of hash of hash
Message-Id: <df6ppk$n82$1@mamenchi.zrz.TU-Berlin.DE>

ngoc  <ngoc@yahoo.com> wrote in comp.lang.perl.misc:
> Matija Papec wrote:
> > On Thu, 01 Sep 2005 11:27:32 +0200, ngoc <ngoc@yahoo.com> wrote:

[Top posting rearranged.  Please don't do that]

> >>I have
> >>$hash{1}{2}{3} = 7;
> >>$hash{1}{4}{5} = 6;
> >>I want to get 7 and 6 without using three for loop and keys function
> >>How can I do it?

[...]

> > btw, is there a reason for using a hash? perhaps you could be better
> > with arrays (all you keys are numeric).
> > 
> > 


> My nummeric key is example only. My real application has keys that mix 
> of text and number.
> My problem is, I have to compare data from two projects and find out 
> duplicated data. Two projects presented as two hash. If first level key 
> is different (using exist function), put the whole data attached to it 
> in an array. Currently, I have to access level 2, level 3 keys before 
> getting it's real value. It is not advanced computing. So I want to 
> access all values without using keys. Using "values %hash" just gives me 
> next level hash.

So iterate "values":

    my %hash;
    $hash{1}{2}{3} = 7;
    $hash{1}{4}{5} = 6;

    for ( values % hash ) {
        for ( values %$_ ) {
            for ( values %$_ ) {
                print "$_\n";
            }
        }
    }

That prints 7 and 6 in some order.  No key access involved.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


------------------------------

Date: 01 Sep 2005 15:04:41 GMT
From: xhoster@gmail.com
Subject: Re: values of hash of hash
Message-Id: <20050901110441.550$6s@newsreader.com>

ngoc <ngoc@yahoo.com> wrote:
> I have
> $hash{1}{2}{3} = 7;
> $hash{1}{4}{5} = 6;
> I want to get 7 and 6 without using three for loop and keys function
> How can I do it?

Have you considered not creating the uselessly nested hashes in the first
place, but rather sticking the data into a more appropriate structure?

Since you, for completely unknown reasons, don't want to use foreach loops
or the keys function, it would help tremendously if you would list all the
other features you irrationally wish to avoid.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8379
***************************************


home help back first fref pref prev next nref lref last post