[Perl] merge DB problem

Ido Trivizki ido at hotmail.com
Wed Oct 23 06:51:45 PDT 2002


The unary + is there because otherwise the list in parens would look like
the parameter list for map...
A more readable way would be to use the map{BLOCK} LIST syntax...
----- Original Message -----
From: <Yossi.Itzkovich at lightscapenet.com>
To: "Ido Trivizki" <ido at hotmail.com>
Sent: Wednesday, October 23, 2002 5:00 AM
Subject: Re: [Perl] merge DB problem


>
> Thanks for the reply. and it even works !
>
> But why is that "+"  in map ?
>
> Yossi
>
>
>
>                       "Ido Trivizki"
>                       <ido at hotmail.com         To:      <perl at perl.org.il>
>                       >                        cc:
>                       Sent by:                 Subject: Re: [Perl] merge
DB problem
>                       perl-admin at perl.
>                       org.il
>
>
>                       10/22/2002 16:15
>                       Please respond
>                       to perl

>
>
>
>
>
>
> my @file1=('a','b','c');
> my @file2=('a','c','d');
>
> my %file2=map +($file2[$_],$_),0..$#file2;
> for(grep {not exists $file2{$file1[$_]}} 0..$#file1){
>     if($_ and exists $file2{$file1[$_-1]}){
>         splice @file2,$file2{$file1[$_-1]}+1,0,$file1[$_]
>  }elsif($_!=$#file1 and exists $file2{$file1[$_+1]}){
>   splice @file2,$file2{$file1[$_+1]},0,$file1[$_];
>  }else{push @file2,$file1[$_]}
> }
>
> Or something...
> HTH;)
>
>
> ----- Original Message -----
> From: <Yossi.Itzkovich at lightscapenet.com>
> To: <perl at perl.org.il>
> Sent: Tuesday, October 22, 2002 1:49 PM
> Subject: [Perl] merge DB problem
>
>
> >
> > Hi,
> >
> > I have two files with many records with the format  of :
> >
> > Name N
> > valLine#1
> > valLine#2
> > ...
> > valLine#N
> >
> >
> > N indicates how many following lines this records has.
> >
> > I need to merge 2 such files, which is prety simple using 2 hashes,  but
> I
> > want to add records from file1 (that are missing in file2) in the same
> > order/position to file2.
> >
> > For example:
> >
> > File1 is:
> > a 2
> > aa
> > aa
> > b 1
> > bb
> > c 1
> > cc
> >
> > File 2 is:
> > a 2
> > aa
> > aa
> > c 1
> > cc
> > d 1
> > dd
> >
> >
> > I want record "b" from file 1 to be added after record "a".  How can I
> > change the original solution (using 2 hashes and merge and checking
> > existance of keys) to suit this one too? I need a simple solution as
> > possible.
> >
> > Thanks
> >
> > Yossi
> >
> >
> >
> >
> > _______________________________________________
> > Perl mailing list
> > Perl at perl.org.il
> > http://www.perl.org.il/cgi/listinfo/perl
> >
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://www.perl.org.il/cgi/listinfo/perl
>



More information about the Perl mailing list