This discussion is archived
4 Replies Latest reply: Nov 15, 2012 10:49 AM by Kristen G RSS

Perl manipulator Cloning

Shreyas Ram R Newbie
Currently Being Moderated
Hi friends

I am trying to clone the records present in the application using perl manipulator.
To the cloned records,I need to add a new property which is a combination of 2 properties,product id and group name.Product id is an existing property and group name is a new property to be created and should be added to the cloned records as well as existing set of records.
I am trying to use the following code in get_records() of perl manipulator but the records are being removed once processed by baseline update.
Can,anyone please help me on this?
Here is the code am using.Please correct if there is anything wrong.I am not much sure of the syntax.

EX:
Records before:
product_id:123
Sku_id:456
Cat_id:888

Records after passing through perl manipulator:

product_id:123
Sku_id:456
Cat_id:888
group_name:A
product_key:123_A

product_id:123
Sku_id:456
Cat_id:888
group_name:B
product_key:123_B

product_id:123
Sku_id:456
Cat_id:888
group_name:C
product_key:123_C

product_id:123
Sku_id:456
Cat_id:888
group_name:D
product_key:123_D

product_id:123
Sku_id:456
Cat_id:888
group_name:X
product_key:123_X

my @recs;
foreach my $src ( $this->record_sources ) {
my @productData = $src->get_records($key);
foreach my $rec ( @productData ) {
foreach my $groupnames(A,B,C,D,E,X){
# clone the record
# add product_key property to the cloned record
# push the cloned record into @recs
# Psudo code starts

my $clone = $rec->clone;
my $productId = grep { $clone ->name eq 'product_id' } @{ $clone->pvals };
my $groupName= grep { $clone ->name eq 'group_name' } @{ $clone->pvals };
my $productkey = $properties{"product_id"}."_".$properties{"group_name"};
my $pval = new EDF::PVal("product_key", $productId."_".$groupName);
$rec->add_pvals($pval);

# Psudo code ends
}

}
}
return @recs;

Edited by: Shreyas Ram R on Nov 10, 2012 10:33 PM

Edited by: Shreyas Ram R on Nov 10, 2012 10:37 PM

Edited by: Shreyas Ram R on Nov 10, 2012 10:38 PM
  • 1. Re: Perl manipulator Cloning
    PravinChikhale Explorer
    Currently Being Moderated
    Which property are you using as a record spec for existing and newly created record?

    --Pravin                                                                                                                                                                                               
  • 2. Re: Perl manipulator Cloning
    Shreyas Ram R Newbie
    Currently Being Moderated
    Hi Pavan

    Thanks for your response.
    We are not using any Record Spec in our application because we are not using partial updates and using only baseline process.

    Regards
    Shreyas
  • 3. Re: Perl manipulator Cloning
    Michael Peel Journeyer
    Currently Being Moderated
    I'd do this a different way. If you are cloning all records in a feed, then read the records in twice - once as normal, then another set of record adapter(s). The second set goes into an XML manipulator, and this modifies the properties (see the XML reference within Developer Studio, it looks quite complicated but is actually very easy once you get your head around an XML being used as a pseudo programming language). Finally, both sets of data go into a switch join (Record Assembler > Join Type = Switch).

    Reason for this approach is it'll be a lot faster than using a perl manipulator to create these duplicates, and a lot cleaner too. Thinking about it, you may be able to read in the data once, then send it to two separate record caches, manipulate the second cache, then feed both into the switch join. Not 100% sure if that is supported, but definitely worth trying first.

    Oh, and add a record spec - always a good idea, not least because it'll give you persistence of a unique id for record lookups (R=XYZ).

    Michael
  • 4. Re: Perl manipulator Cloning
    Kristen G Explorer
    Currently Being Moderated
    You can also look at CAS (Content Acquisition System) and the manipulator examples as another option

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points