Re: Perl Hash Comparison and concatenate result from %hash2 comparedto %hash1 into %hash3

> Hello Wernher,

Hi Chris,

> Rob's code could be reconfigured slightly to do so, but requires a
> different approach. I will paste it below.

Ok, thanks.

> One change I made was to make the *values* of %hash1 an array ref as I
> thought this was how the hash was originally constructed. If the value
> for %hash1 was a string as in Rob's hash, the code below could be
> altered slightly to perform the task as well.

Ah yes, to make the values of %hash1 an array does make more sense.

> You said 'But, I plan to add things like "disk size", =A0"disk size
> used" and "disk size free" numeric values next to each partition mount '
> It is good to build up a program in small steps and test as you go,
> but it is also helpful to have a large view of the problem so that you
> won't create data structures that work for the first stages of the
> program but fail to accomodate later alterations. You really kinda
> need to have the big picture at the start.

You are right, thank you very much.

> Chris
>
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> # I changed the value of the hash to an array (ref). Rob had a string
> here
> my %hash1 =3D (
> =A0emcpowera =A0=3D> [qw/sdbd sddg sdfj sdhm/],
> =A0emcpoweraa =3D> [qw/sdae sdch sdek sdgn/],
> =A0emcpowerbc =3D> [qw/sdb sdbe sddh sdfk/],
> =A0emcpowerc =A0=3D> [qw/sdbb sdde sdfh sdhk/],
> =A0emcpowerd =A0=3D> [qw/sdba sddd sdfg sdhj/],
> =A0emcpowerz =A0=3D> [qw/sdba sddd sdfg sdhj/]
> );
>
>
> my %hash2 =3D (
> =A0emcpowera1 =A0=3D> "/dwpdb006",
> =A0emcpoweraa1 =3D> "/dwpdb033",
> =A0emcpowerbc1 =3D> "/s00_11",
> =A0emcpowerbc2 =3D> "/utl_file_dir",
> =A0emcpowerc1 =A0=3D> "/odsdb006",
> =A0emcpowerd1 =A0=3D> "/odsdb005",
> );
>
> my %seen;
> for my $key (sort keys %hash2) {
> =A0 =A0 =A0 =A0(my $k1 =3D $key) =3D~ s/\d+\z//;
> =A0 =A0 =A0 =A0if (my $aref =3D $hash1{ $k1 }) {
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0my $string =3D "$k1 [at] $aref";
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$string =3D ' ' x length($string) if $seen=
{$k1}++;
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0print "$string\t$key $hash2{$key}\n";
> =A0 =A0 =A0 =A0}
> }
>
> delete [at] hash1{ keys %seen };
> print "$_ [at] { $hash1{$_} }\n" for sort keys %hash1;

Chris, thank you so very much for this, it does exactly the way I need it!!=
!

I have learned a great deal of things since I joined this list last
week Friday the 1st.

Kind regards,
Wernher Eksteen

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Wernher Eksteen [ Mo, 04 April 2011 09:03 ] [ ID #2057588 ]

Re: Perl Hash Comparison and concatenate result from %hash2 comparedto %hash1 into %hash3

On Apr 4, 3:03=A0am, wekst... [at] gmail.com (Wernher Eksteen) wrote:
> > Hello Wernher,
>
> Hi Chris,
>
> > Rob's code could be reconfigured slightly to do so, but requires a
> > different approach. =A0I will paste it below.
>
> Ok, thanks.
>
> > One change I made was to make the *values* of %hash1 an array ref as I
> > thought this was how the hash was originally constructed. If the value
> > for %hash1 was a string as in Rob's hash, the code below could be
> > altered slightly to perform the task as well.
>
> Ah yes, to make the values of %hash1 an array does make more sense.

Actually, I had tried following the thread and it it looked like the
code you used from J W Krahn had that information in arrays and not
strings. That is actually why I set it up that way. However, if the
data is in a string form, the code may be a bit clearer as what is
being done is building up strings!

Chris


--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
charley [ Di, 05 April 2011 02:11 ] [ ID #2057634 ]

Re: Perl Hash Comparison and concatenate result from %hash2 comparedto %hash1 into %hash3

On 05/04/2011 01:11, Chris <charley [at] pulsenet.com> wrote:
>
> Actually, I had tried following the thread and it it looked like the
> code you used from J W Krahn had that information in arrays and not
> strings. That is actually why I set it up that way. However, if the
> data is in a string form, the code may be a bit clearer as what is
> being done is building up strings!

Because we have been presented with fragments of the complete problem
there has been no basis to criticize the overall design. You said
yourself

On 04/04/2011 03:18, Chris <charley [at] pulsenet.com> wrote:
>
> It is good to build up a program in small steps and test as you go,
> but it is also helpful to have a large view of the problem so that you
> won't create data structures that work for the first stages of the
> program but fail to accomodate later alterations. You really kinda
> need to have the big picture at the start.

And I am certain that we have a much less than optimum solution to the
complete problem. I wonder if Wernher would consider presenting the
initial requirement here, without reference to implementation specifics,
so that we can see where these pieces of the puzzle fit into the
complete picture.

Rob

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Rob Dixon [ Di, 05 April 2011 03:13 ] [ ID #2057635 ]
Perl » gmane.comp.lang.perl.beginners » Re: Perl Hash Comparison and concatenate result from %hash2 comparedto %hash1 into %hash3

Vorheriges Thema: Excessive wait time after fork
Nächstes Thema: Mix of English and Cyrillic Characters