{"id":2425,"date":"2017-12-08T10:14:06","date_gmt":"2017-12-08T10:14:06","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=2425"},"modified":"2025-02-01T23:08:07","modified_gmt":"2025-02-01T23:08:07","slug":"delete-an-element-from-array-based-on-custom-duplicate-value","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/delete-an-element-from-array-based-on-custom-duplicate-value\/","title":{"rendered":"Delete an element from array based on custom duplicate value"},"content":{"rendered":"<p><strong>rajeshkumar created the topic: Delete an element from array based on custom duplicate value<\/strong><\/p>\n<p>Hi, I am looking for some help in one scenario.<\/p>\n<p>Requirement:<\/p>\n<p>Through some validation, I have strored following kinds of value in one array.<\/p>\n<p>@array_name = (&#8220;Rajesh&#8221;,&#8221;Raju&#8221;,&#8221;Ram&#8221;,&#8221;John&#8221;,&#8221;peter&#8221;);<\/p>\n<p>Now I know from some background that &#8220;Rajesh&#8221;, &#8220;Ram&#8221;, &#8220;peter&#8221;, is duplocated entry so i would expect my output to be:<\/p>\n<p>@array_name = (&#8220;Rajesh&#8221;,&#8221;Raju&#8221;,&#8221;John&#8221;);<br \/>\nor<br \/>\n@array_name = (&#8220;Ram&#8221;,&#8221;Raju&#8221;,&#8221;John&#8221;);<br \/>\nor<br \/>\n@array_name = (&#8220;peter&#8221;,&#8221;Raju&#8221;,&#8221;John&#8221;);<\/p>\n<p>I have done example program such as below but it does not satisfy me&#8230;<\/p>\n<p><code>my $spcific_output =\"\";<br \/>\nmy $output =\"\";<\/p>\n<p>foreach my $name (@array_name)<br \/>\n{<br \/>\n\tif($name eq \"Rajesh\" || $name eq \"Ram\" || $name eq \"peter\")<br \/>\n\t{<br \/>\n\t\t$spcific_output = \"Rajesh and Ram and peter\");<br \/>\n\t}<br \/>\n\telse<br \/>\n\t{<br \/>\n\t\t$output .= \"My Name is $name\";<br \/>\n\t}<br \/>\n}<br \/>\n$output .= $spcific_output;<\/code><\/p>\n<p>Any best way to achieve this????<\/p>\n<p>Regards,<br \/>\nRajesh Kumar<br \/>\nTwitt me @<a href=\"http:\/\/twitter.com\/RajeshKumarIn\" target=\"_blank\" rel=\"noopener\"> twitter.com\/RajeshKumarIn<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>rajeshkumar created the topic: Delete an element from array based on custom duplicate value Hi, I am looking for some help in one scenario. Requirement: Through some validation, I have&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[14],"tags":[490],"class_list":["post-2425","post","type-post","status-publish","format-standard","hentry","category-perl","tag-array"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=2425"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2425\/revisions"}],"predecessor-version":[{"id":2426,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2425\/revisions\/2426"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=2425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=2425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=2425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}