Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Re: comparing k...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 11 Topic 11027 of 11531
Post > Topic >>

Re: comparing kit names

by rahman77@[EMAIL PROTECTED] (Perl_learner) May 6, 2008 at 10:07 PM

On May 6, 10:08=A0am, nore...@[EMAIL PROTECTED]
 (Gunnar Hjalmarsson) wrote:
> perl_learner wrote:
> > On May 5, 3:26 am, nore...@[EMAIL PROTECTED]
 (Gunnar Hjalmarsson) wrote:
>
> >> =A0 =A0 =A0my @[EMAIL PROTECTED]
 =3D qw( aaa.t.z aaa_d.t.z bbb.t.z bbb_d.t.z
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ccc.t.z ccc_d.t.z ddd.t.z
eee.t.=
z );
>
> >> =A0 =A0 =A0my %hash =3D map {
> >> =A0 =A0 =A0 =A0 =A0( my $tmp =3D $_) =3D~ s/_d(\.t\.z)$/$1/; $tmp
=3D> =
1
> >> =A0 =A0 =A0} grep /_d\.t\.z$/, @[EMAIL PROTECTED]
>
> >> =A0 =A0 =A0foreach my $kit ( grep !/_d\.t\.z$/, @[EMAIL PROTECTED]
 ) {
> >> =A0 =A0 =A0 =A0 =A0print "$kit\n" unless $hash{$kit};
> >> =A0 =A0 =A0}
>
> > 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.
>
> =A0 =A0 =A0use strict;
> =A0 =A0 =A0use warnings;
>
> > $KIT_LOCATION=3D"/lnx/dep/packages";
> > $KIT_LIST=3D`ls $KIT_LOCATION/*.t.Z`;
> > #print $KIT_LIST;
> > $KIT_LIST=3D~ s/$KIT_LOCATION\///g;
> > #print $KIT_LIST;
> > my @[EMAIL PROTECTED]
 =3D $KIT_LIST;
>
> How many elements do you think there are in @[EMAIL PROTECTED]
>
> =A0 =A0 =A0my @[EMAIL PROTECTED]
 =3D split ' ', $KIT_LIST;
>
> > chomp ($kits);
>
> ---------^
>
> > #print "@[EMAIL PROTECTED]
";###prints out both .Z and _d.t.Z
>
> > =A0 =A0 =A0my %hash =3D map {
> > =A0 =A0 =A0 =A0 ( my $tmp =3D $_) =3D~ s/_d(\.t\.Z)$/$1/; $tmp =3D> 1
> > =A0 =A0 =A0} grep /_d\.t\.Z$/, @[EMAIL PROTECTED]
>
> > =A0 =A0 =A0 =A0 #print "@[EMAIL PROTECTED]
"; #prints out both .Z and _d.t.Z
>
> > =A0 =A0 =A0foreach my $kit ( grep !/_d\.t\.Z$/, @[EMAIL PROTECTED]
 ) {
> > =A0 =A0 =A0 =A0 =A0#print "$kit\n" unless $hash{$kit}; #prints out
both =
..Z and
> > _d.t.Z
> > =A0 =A0 =A0}
>
> --
> 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 @[EMAIL PROTECTED]
 =3D 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 @[EMAIL PROTECTED]
 have ~100 elements @[EMAIL PROTECTED]
 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
 




 11 Posts in Topic:
comparing kit names
rahman77@[EMAIL PROTECTED  2008-05-05 01:10:52 
Re: comparing kit names
noreply@[EMAIL PROTECTED]  2008-05-05 12:26:04 
Re: comparing kit names
rahman77@[EMAIL PROTECTED  2008-05-05 16:34:43 
Re: comparing kit names
noreply@[EMAIL PROTECTED]  2008-05-06 19:08:14 
Re: comparing kit names
rahman77@[EMAIL PROTECTED  2008-05-06 22:07:06 
Re: comparing kit names
noreply@[EMAIL PROTECTED]  2008-05-07 13:55:08 
Re: comparing kit names
krahnj@[EMAIL PROTECTED]   2008-05-07 09:01:54 
Re: comparing kit names
noreply@[EMAIL PROTECTED]  2008-05-07 22:08:39 
Re: comparing kit names
rahman77@[EMAIL PROTECTED  2008-05-07 08:30:23 
Re: comparing kit names
noreply@[EMAIL PROTECTED]  2008-05-08 18:09:45 
Re: comparing kit names
rahman77@[EMAIL PROTECTED  2008-05-09 10:48:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 19:10:04 CDT 2008.