Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to uniqe my array

Status
Not open for further replies.

jwholey

Technical User
May 8, 2001
4
0
0
US
Having problems "uniquing" an array. Everything works except where I attempt to uniqe the output at very bottom of script. I've tried dozens of variations. fyi... can't use modules, can't use (cmd).

#!/usr/bin/perl

$id=id;
$pass=password;

$tsmsrv_cmd0="select volume_name,access from volumes";
$tsmsrv_cmd1="upd vol";
$tsmsrv_cmd2="q actlog begind=-8 endd=today msgno=1420";


foreach my $arg (@ARGV) { # Capturing command line Variables

$instance=$ARGV[0]; # This will be the TCPSERVERADDRESS
$node_namee=$ARGV[1]; # This will be the TCPPORT

}

open(LOGIN3, "dsmadmc -se=$instance -id=$id -pass=$pass -datao=yes -tabd $tsmsrv_cmd2|") || die "open: $!";
@get_restore_vol_list=<LOGIN3>;
close(LOGIN3);
foreach my $line (@get_restore_vol_list) {
@splitit = split (/ /, $line);
@get_restore_vol_list1 = "$splitit[7]\n";
chomp(@get_restore_vol_list1);
######################

%hash = map {$_, 1} @get_restore_vol_list1;
@unique = keys %hash;
print "@unique\n";
}
 
Hi

jwholey said:
Everything works except where I attempt to uniqe the output at very bottom of script.
Looks good. Tested it. Works for me. I mean, strictly the 3 lines of duplicate removal.

But the problem is probably earlier, in this line :
jwholey said:
[tt]@get_restore_vol_list1 = "$splitit[7]\n";][/tt]
Why are you setting an array to a single scalar ?

Maybe you intended to [tt]push[/tt] ? In that case, supposing your Perl version is at least 5.10.1, I would change the 2[sup]nd[/sup] [tt]foreach[/tt] like this :
Code:
[b]foreach[/b] [b]my[/b] $line (@get_restore_vol_list) {
  @splitit = [b]split[/b] (/ /, $line);
  [b]chomp[/b] $splitit[7];
  [b]push[/b] @get_restore_vol_list1, $splitit[7] [b]unless[/b] $splitit[7] ~~ @get_restore_vol_list1;
}


Feherke.
feherke.ga
 
Feherke... you're right... beautiful. Thanks!
 
Also what's the purpose of this?

Code:
foreach my $arg (@ARGV) { # Capturing command line Variables

 $instance=$ARGV[0]; # This will be the TCPSERVERADDRESS
 $node_namee=$ARGV[1]; # This will be the TCPPORT

 }

You seem to loop the ARGV collection placing each item into $arg, and then don't use it? It appears to be a superfluous use of a loop?



"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top