10 msgText formatting issues
1 msgre: find path to current file, NOT working dire...
2 msgPassing Creadentials and parameters through htt...
7 msghow to shorten this code ? x occur how many tim...
1 msgCompare String is not match !
3 msgCompile error
5 msgchaining defines
2 msgsed split on pipe
4 msgcsv file question
6 msgWriting side of square

comparing kit names
\ perl_learner (5 May 2008)
. \ Gunnar Hjalmarsson (5 May 2008)
. \ perl_learner (6 May 2008)
. . \ Gunnar Hjalmarsson (6 May 2008)
. \ perl_learner (7 May 2008)
. . \ Gunnar Hjalmarsson (7 May 2008)
. . . \ John W. Krahn (7 May 2008)
. . . . \ Gunnar Hjalmarsson (7 May 2008)
. \ perl_learner (8 May 2008)
. . \ Gunnar Hjalmarsson (8 May 2008)
. \ perl_learner (10 May 2008)

2 msgOT: help crle ruin my solaris :-(
6 msggenerating number ranges using rand function
1 msgquestion on unblocking the signals
5 msghowto simplfy this regex if ($string =~/^$match...
7 msghow to reun perl script on other pc without hav...
14 msghow to simplify this script
10 msgdisplaying inline images in HTML email
15 msganother help on input record separator clarity ...
2 msgPerl Expect help
Subject:Re: comparing kit names
Group:Perl-beginners
From:perl_learner
Date:10 May 2008


 
On May 8, 9:09 am, nore... (Gunnar Hjalmarsson) wrote:
> perl_learner wrote:
> > On May 7, 4:55 am, nore... (Gunnar Hjalmarsson) wrote:
> >> perl_learner wrote:
> >>> On May 6, 10:08 am, nore... (Gunnar Hjalmarsson) wrote:
> >>>> perl_learner wrote:
> >>>>> my @kits = $KIT_LIST;
> >>>> How many elements do you think there are in @kits?
> >>> I have ~100 elements @kits. Why did you ask this question?
> >> Because when you just said
>
> >>      my @kits = $KIT_LIST;
>
> >> you had only one element in @kits.
>
> >>>>      my @kits = split ' ', $KIT_LIST;
> >>> Also with little change, "my @kits = split '  ', $KIT_LIST; ## added
> >>> 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.
>
> >>      perldoc -f split
>
> >> --
> >> Gunnar Hjalmarsson
> >> Email:http://www.gunnar.cc/cgi-bin/contact.pl
>
> >>>>      my @kits = split '  ', $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
>
>      split ' ', 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
>
>      split /  /, 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="/lnx/dep/packages/";
my $KIT_LIST=`ls $KIT_LOCATION/*.t.Z`;

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

my @kits = 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 "@kits\n\n";##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 = 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};##prints only the list of Z
kits where their _d kits are missing
}


--
To unsubscribe, e-mail: beginners-unsubscribe
For additional commands, e-mail: beginners-help
http://learn.perl.org/




© 2004-2008 readlist.com