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 11 of 11 Topic 11027 of 12002
Post > Topic >>

Re: comparing kit names

by rahman77@[EMAIL PROTECTED] (Perl_learner) May 9, 2008 at 10:48 AM

On May 8, 9:09=A0am, nore...@[EMAIL PROTECTED]
 (Gunnar Hjalmarsson) wrote:
> perl_learner wrote:
> > On May 7, 4:55 am, nore...@[EMAIL PROTECTED]
 (Gunnar Hjalmarsson) wrote:
> >> perl_learner wrote:
> >>> On May 6, 10:08 am, nore...@[EMAIL PROTECTED]
 (Gunnar Hjalmarsson) wrote:
> >>>> perl_learner wrote:
> >>>>> my @[EMAIL PROTECTED]
 =3D $KIT_LIST;
> >>>> How many elements do you think there are in @[EMAIL PROTECTED]
> >>> I have ~100 elements @[EMAIL PROTECTED]
 Why did you ask this question?
> >> Because when you just said
>
> >> =A0 =A0 =A0my @[EMAIL PROTECTED]
 =3D $KIT_LIST;
>
> >> you had only one element in @[EMAIL PROTECTED]
>
> >>>> =A0 =A0 =A0my @[EMAIL PROTECTED]
 =3D split ' ', $KIT_LIST;
> >>> Also with little change, "my @[EMAIL PROTECTED]
 =3D split ' =A0', $KIT_LIST; ##
add=
ed
> >>> an extra space to split"
> >>> I am getting the desired output.
> >> The extra space should not make a difference, since split(' ') is a
> >> special case that splits on all kinds of whitespace.
>
> >> =A0 =A0 =A0perldoc -f split
>
> >> --
> >> Gunnar Hjalmarsson
> >> Email:http://www.gunnar.cc/cgi-bin/contact.pl
>
> >>>> =A0 =A0 =A0my @[EMAIL PROTECTED]
 =3D split ' =A0', $KIT_LIST;
>
> > The extra space had make a difference.....
> > Without extra space I was getting:
>
> > a a a . t . z a a a _ d . t . z b b b . t . z b b b _ d . t . z c c
> > c . t . z c c c _ d . t . z d d d . t . z e e e . t . z
>
> > With extra space I get the correct output: 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
>
> Now it's getting confusing. "Extra" space - compared to what?
>
> The correct format of this special split is
>
> =A0 =A0 =A0split ' ', EXPR
>
> i.e. two quote characters with _one_ space character between them.
>
> That's what I had initially suggested. When you said you added an extra
> space, you were getting two quote characters with _two_ space characters
> between them. As John pointed out, the latter is no longer the special
> case format, and is simply interpreted by Perl as
>
> =A0 =A0 =A0split / =A0/, EXPR
>
> Maybe, in order to reduce the confusion, could you post the complete
> final version of your code?
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl-
Hide quoted text -
>
> - Show quoted text -

Sorry for any confusion. You are right. The extra space I was
mentioning it was a visual error from my side. Sorry for that.

Thaks a lot.

Here is the complete working code:

use strict;
use warnings;

my $KIT_LOCATION=3D"/lnx/dep/packages/";
my $KIT_LIST=3D`ls $KIT_LOCATION/*.t.Z`;

$KIT_LIST=3D~ s/$KIT_LOCATION\///g;

my @[EMAIL PROTECTED]
 =3D split' ',$KIT_LIST;##putting all kits (both _d and Z) to an
array list, each kit comes up with a space and all kits are in a same
line

#print "@[EMAIL PROTECTED]
";##prints all kits with a space in a single line
(array) or as element
#print "$kits[0]\n";##just for verification, prints first element of
the kits array
#print "$kits[1]\n";##just for verification, prints second element of
the kits array
my %hash =3D map {
        ( my $tmp =3D $_) =3D~ s/_d(\.t\.Z)$/$1/; $tmp =3D> 1
     } grep /_d\.t\.Z$/, @[EMAIL PROTECTED]
     foreach my $kit ( grep !/_d\.t\.Z$/, @[EMAIL PROTECTED]
 ) {
         print "$kit\n" unless $hash{$kit};##prints only the list of Z
kits where their _d kits are missing
     }
 




 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 Tue Oct 14 10:18:47 CDT 2008.