×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Unable to uniqe my array

Unable to uniqe my array

Unable to uniqe my array

(OP)
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";
}

RE: Unable to uniqe my array

Hi

Quote (jwholey)

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 :

Quote (jwholey)

@get_restore_vol_list1 = "$splitit[7]\n";]
Why are you setting an array to a single scalar ?

Maybe you intended to push ? In that case, supposing your Perl version is at least 5.10.1, I would change the 2nd foreach like this :

CODE --> ( fragment )

foreach my $line (@get_restore_vol_list) {
  @splitit = split (/ /, $line);
  chomp $splitit[7];
  push @get_restore_vol_list1, $splitit[7] unless $splitit[7] ~~ @get_restore_vol_list1;
} 

Feherke.
feherke.ga

RE: Unable to uniqe my array

(OP)
Feherke... you're right... beautiful. Thanks!

RE: Unable to uniqe my array

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close