Given the code below, I'd like to perform the join, only if the variable hasn't already been joined.

When I dump the hash that this script creates, the inner hash, "tapes" can have duplicate values. I'll post some output to illustrate. I want only unique (in this case) tape id's to be included.

#!/opt/openv/perl/bin/perl -w use strict; use Data::Dumper; use NBUX; my %images = bpimagelist(); #print Dumper(\%images); #exit; my (%status); foreach my $key (sort keys %images) { my ($tapes, $img); my $client = $images{$key}->{'client'}; my $sched_type = $images{$key}->{'schedule_type'}; my $sched_name = $images{$key}->{'sched_label'}; my $policy = $images{$key}->{'policy'}; my $kb = $images{$key}->{'kbytes'}; foreach my $key2 (sort keys %{$images{$key}}) { if ($key2 =~ /copy_\d_frag_\d_id/) { $img = $images{$key}{$key2}; $tapes = (join (' ', $img, $tapes)); $status{$client}{$policy}{'tapes'} = $tapes; } } } #print Dumper(\%status); #exit;
Here's some example output that I'm trying to avoid:
$VAR1 = { 'bondsrv1' => { 'acis_misc_os' => { 'tapes' => 'OK0238 OK0238 ' + } }, }

In reply to Join unless $var has already been joined? by blink

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.