Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Removing Duplicates from a multiline entry

by karlgoethebier (Curate)
on Feb 28, 2013 at 09:07 UTC ( #1021026=note: print w/ replies, xml ) Need Help??


in reply to Removing Duplicates from a multiline entry

Assuming that the first found product entry is valid (is it?), i would do it like this:

Update: I don't know how often i posted this wrong/useless M$dog shebop/shebang... #!/c:/perl/bin/perl.exe

#!c:/perl/bin/perl.exe use strict; use warnings; $/ = ""; my $file = shift; open my $fh, "<", $file || die $!; my @records = <$fh>; close $fh; my %records; for (@records) { $_ =~ m/(Product \d+)(.+)/s; my $product_id = $1; next if exists $records{$product_id}; $records{"$product_id"} = $2; } for (sort keys %records) { print qq($_ $records{$_}); } __END__ Product 1 ------------------------------------------------------------------ storeId = 1001 phoneNumber = (111) 111-1111 availbilityCode = 1 stockStatus = Limited stock distance = 9.12 city = some city fullStreet = some address Product 2 ------------------------------------------------------------------ storeId = 2117 phoneNumber = (111) 111-1111 availbilityCode = 2 stockStatus = In stock distance = 7.49 city = some city fullStreet = some address Product 3 ------------------------------------------------------------------ storeId = 2123 phoneNumber = (111) 111-1111 availbilityCode = 1 stockStatus = Limited stock distance = 8.83 city = some city fullStreet = some address

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»


Comment on Re: Removing Duplicates from a multiline entry
Download Code
Re^2: Removing Duplicates from a multiline entry
by diamondsandperls (Beadle) on Mar 01, 2013 at 01:39 UTC
    This is partly my fault I have tried all the examples none are working I do need to keep the first entry but every entry after that is a duplicate do not print this entry. so the last example has what i am looking for there could be like 10 duplicate entries or more but i just need one of each to print if there is only one entry then great print this entry then go to the next one but detect if an entry has been processed i suppose. Thanks to everyone who has helped thus far

      In other words: it's working now?

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1021026]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (14)
As of 2014-09-16 20:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (47 votes), past polls