> 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/
