Re: comparing kit names

[email protected] (perl_learner)
Newsgroups perl.beginners
Organization http://groups.google.com
Message-ID <9e90d110-428c-4f54-b7f3-c1b1945fc30a@t12g2000prg.googlegroups.com>
On May 6, 10:08 am, [email protected] (Gunnar Hjalmarsson) wrote:
> perl_learner wrote:
> > On May 5, 3:26 am, [email protected] (Gunnar Hjalmarsson) wrote:
>
> >>      my @kits = qw( aaa.t.z aaa_d.t.z bbb.t.z bbb_d.t.z
> >>                    ccc.t.z ccc_d.t.z ddd.t.z eee.t.z );
>
> >>      my %hash = map {
> >>          ( my $tmp = $_) =~ s/_d(\.t\.z)$/$1/; $tmp => 1
> >>      } grep /_d\.t\.z$/, @kits;
>
> >>      foreach my $kit ( grep !/_d\.t\.z$/, @kits ) {
> >>          print "$kit\n" unless $hash{$kit};
> >>      }
>
> > Thanks for your reply. It works out if I use qw option. However I have
> > bigger list. I am sending my program, it provides me both *_d.t.Z as
> > well as *Z list. Not doing the comparison.
>
> You should never ask for help on a list with fixing buggy code if you
> haven't first asked Perl for help.
>
>      use strict;
>      use warnings;
>
> > $KIT_LOCATION="/lnx/dep/packages";
> > $KIT_LIST=`ls $KIT_LOCATION/*.t.Z`;
> > #print $KIT_LIST;
> > $KIT_LIST=~ s/$KIT_LOCATION\///g;
> > #print $KIT_LIST;
> > my @kits = $KIT_LIST;
>
> How many elements do you think there are in @kits?
>
>      my @kits = split ' ', $KIT_LIST;
>
> > chomp ($kits);
>
> ---------^
>
> > #print "@kits";###prints out both .Z and _d.t.Z
>
> >      my %hash = map {
> >         ( my $tmp = $_) =~ s/_d(\.t\.Z)$/$1/; $tmp => 1
> >      } grep /_d\.t\.Z$/, @kits;
>
> >         #print "@kits\n"; #prints out both .Z and _d.t.Z
>
> >      foreach my $kit ( grep !/_d\.t\.Z$/, @kits ) {
> >          #print "$kit\n" unless $hash{$kit}; #prints out both .Z and
> > _d.t.Z
> >      }
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl- Hide quoted text -
>
> - Show quoted text -

Gunner,
Thanks a lot for telling me to use
>      use strict;
>      use warnings;
These helped me a lot. I had to declare both variables $KIT_LOCATION,
$KIT_LIST correctly by putting "my" before them.

Also with little change, "my @kits = split '  ', $KIT_LIST; ## added
an extra space to split"

I am getting the desired output.

I have

> How many elements do you think there are in @kits?

I have ~100 elements @kits. Why did you ask this question? Is it going
to be an issue if the numebr of elements get bigger? Do you have any
more suggestion.

Again, thanks a lot :)

Regards,
Shahriar
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.