> I suggest you reduce your tab size from eight characters, which leave
> your code spread out and less readable. Four or two is more usual
> nowadays.

Thank you, I will do so from now on.

> Meaningful variable names are also important. Using $i as the key to
> %hash1 and $b as the key to %hash2 is a very bad idea: both have
> different conventional uses and $b is a special variable used internally
> by Perl.

Thanks you, I will add more descriptive names in future. I didn't know $b
is a special internal variable used by Perl.

> Long chains of concatenated strings can be improved visually by
> interpolation:
>
>  push @matched, "$i $hash1{$i} $b $hash2{$b}\n";
>
> or formatting:
>
>  push @matched, sprintf "%s %s %s %s\n", $i, $hash1{$i}, $b, $hash2{$b};

Wow, thanks!

> As for an improved version, your main purpose seems to be to combine
> data that belongs under the same /emcpower.*/ prefix. The program below
> does this by modifying %hash1, rather than building two new arrays as
> yours does. If this is unacceptable then come back to us.

This is acceptable, thank you!

> The program iterates over the records in %hash2, removes the decimals
> from the end of the key, and uses the result to select the record in
> %hash1 that should be appended to.

Thank you, I definitely still need to familiarize myself better with
hashes and I
am working on getting there. From the likes of you and others in this
list I will
achieve this goal much quicker than just by myself.

> HTH,

Yes, it does very much, thank you!

> Rob
>
>
>
> use strict;
> use warnings;
>
> my %hash1 = (
>  emcpowera  => "sdbd sddg sdfj sdhm",
>  emcpoweraa => "sdae sdch sdek sdgn",
>  emcpowerbc => "sdb sdbe sddh sdfk",
>  emcpowerc  => "sdbb sdde sdfh sdhk",
>  emcpowerd  => "sdba sddd sdfg sdhj",
>  emcpowerz  => "sdba sddd sdfg sdhj",
> );
>
> my %hash2 = (
>  emcpowera1  => "/dwpdb006",
>  emcpoweraa1 => "/dwpdb033",
>  emcpowerbc1 => "/s00_11",
>  emcpowerbc2 => "/utl_file_dir",
>  emcpowerc1  => "/odsdb006",
>  emcpowerd1  => "/odsdb005",
> );
>
> for my $key2 (keys %hash2) {
>  (my $key1 = $key2) =~ s/\d+\z//;
>  if ($hash1{$key1}) {
>    $hash1{$key1} = "$hash1{$key1} $key2 $hash2{$key2}";
>  }
> }
>
> foreach my $key1 (sort keys %hash1) {
>  print "$key1 $hash1{$key1}\n";
> }
>
> **OUTPUT**
>
> emcpowera sdbd sddg sdfj sdhm emcpowera1 /dwpdb006
> emcpoweraa sdae sdch sdek sdgn emcpoweraa1 /dwpdb033
> emcpowerbc sdb sdbe sddh sdfk emcpowerbc1 /s00_11 emcpowerbc2 /utl_file_dir
> emcpowerc sdbb sdde sdfh sdhk emcpowerc1 /odsdb006
> emcpowerd sdba sddd sdfg sdhj emcpowerd1 /odsdb005
> emcpowerz sdba sddd sdfg sdhj
>
>

This is really totally awesome, thank you so very much!

I really like what you have done with this line, it's very cool!

emcpowerbc sdb sdbe sddh sdfk emcpowerbc1 /s00_11 emcpowerbc2 /utl_file_dir

But, I plan to add things like "disk size",  "disk size used" and
"disk size free" numeric values
next to each partition mount ( emcpowerbc1 /s00_11 ) and (emcpowerbc2
/utl_file_dir) in this case,
so I would prefer to have it like this instead:

emcpowerbc sdb sdbe sddh sdfk emcpowerbc1 /s00_11
                                               emcpowerbc2 /utl_file_dir

or

emcpowerbc sdb sdbe sddh sdfk emcpowerbc1 /s00_11
emcpowerbc sdb sdbe sddh sdfk emcpowerbc2 /utl_file_dir

Could you please show me how to change your excellent code to achieve
either one of these instead?

Many thanks!
Wernher

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


Reply via email to