473,626 Members | 3,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Removing Duplicate Headings

1 New Member
Im somewhat stuck on a project im working on and im pretty new to Perl, so i hope some perl heads can help me out here:)

I have an array that looks somewhat like this:

heading 1
data2keep
data2keep
data2keep
heading 1
data2keep
data2keep
heading 2
data2keep
data2keep
data2keep
data2keep
heading 2
data2keep
data2keep
heading 3
data2keep
data2keep
data2keep
.
.
Now as you see, headings occur several times even tho they are identical. (This due to page shifts in a SAP file export)
I want only one ocurance of each heading.

So, the result should look like:

heading 1
data2keep
data2keep
data2keep
data2keep
data2keep
heading 2
data2keep
data2keep
data2keep
data2keep
data2keep
data2keep
heading 3
data2keep
data2keep
data2keep
So far i have this code, but it just identifies the linenumbers of where a new "block" starts:
Expand|Select|Wrap|Line Numbers
  1. foreach (@data) {
  2.     if ($_ =~ m/heading/) {
  3.         $_{$_}++;
  4.         unless($_{$_} > 1) {
  5.             push(@block,"\t$i\t $_\n");
  6.         }
  7.     }
  8.     $i++;
  9. }
  10.  
So, i need some function to do splice on those headers i dont want.
Hope anyone can help.
Aug 23 '07 #1
3 1150
kevin24
4 New Member
Hi

Welcome to perl scripts!

If your particularly looking to splice a function, then see perl slice function in "tizag.com" which i suggest a good learning online site...

See if that helps you..

Best regards,

Kevin..
Aug 24 '07 #2
numberwhun
3,509 Recognized Expert Moderator Specialist
Not to be nit-picky, but please do not top post (post on top of others postings).

there?
is
now
backwards,
discussion
a
read
to
trying
like
nothing
is
there
Because

Regards,

Jeff
Aug 24 '07 #3
KevinADC
4,059 Recognized Expert Specialist
One of probably many ways to do what you want using a hash of arrays to store the data and another array to maintain heading order:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. chomp(my @data = <DATA>);
  4. my @order = ();
  5. my %HoA = ();
  6. my $heading;
  7. foreach my $line (@data) {
  8.    if ($line =~ m/^heading/) {
  9.       $heading = $line;
  10.       if (!exists $HoA{$line}) {
  11.          push @order,$line;
  12.       }
  13.    }
  14.    else {
  15.       push @{$HoA{$heading}},$line;
  16.    }
  17. }
  18.  
  19. foreach my $line (@order){
  20.    print $line,"\n",join("\n",@{$HoA{$line}}),"\n";
  21. }
  22.  
  23. __DATA__
  24. heading 1
  25. data2keep-1
  26. data2keep-1
  27. data2keep-1
  28. heading 1
  29. data2keep-1
  30. data2keep-1
  31. heading 2
  32. data2keep-2
  33. data2keep-2
  34. data2keep-2
  35. data2keep-2
  36. heading 2
  37. data2keep-2
  38. data2keep-2
  39. heading 3
  40. data2keep-3
  41. data2keep-3
  42. data2keep-3
Aug 24 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
17939
by: Rad | last post by:
I have a table . It has a nullable column called AccountNumber, which is of varchar type. The AccountNumber is alpha-numeric. I want to take data from this table and process it for my application. Before doing that I would like to filter out duplicate AccountNumbers. I get most of the duplicates filtered out by using this query: select * from customers where AccountNumber NOT IN (select AccountNumber from customers where AccountNumber...
7
3565
by: Ellen Manning | last post by:
I've got an A2K report showing students and their costs. Student info is in the main report and costs are in a subreport for each student. The user inputs the program desired then only those students in that program are printed. I want the subreports headings to print only for the first student on the page. Is there a way to suppress printing of the headings on subsequent students on that page? I tried the following in both the...
9
5084
by: vbportal | last post by:
Hi, I would like to add BitArrays to an ArrayList and then remove any duplicates - can someone please help me forward. I seem to have (at leaset ;-) )2 problems/lack of understanding (see test code below): (a)When adding BitArrays to the ArrayList and then looping through the ArrayList I seem to access only the latest added BitArray and I'm not exactly clear on best way to access each BItArray in the ArrayList (b)When I try to remove...
1
3477
by: gaikokujinkyofusho | last post by:
Hi, I have been enjoying being able to subscribe to RSS (http://kinja.com/user/thedigestibleaggie) for awhile and have come up with a fairly nice list of feeds but I have run into an annoying (though not critical) problem, duplicate stories. Apparently there is overlap with some of the sites I subscribe to so I get duplicate stories. Does anyone know of some sort of filter (software or online service) that can remove duplicate stories? Any...
12
20787
by: joestevens232 | last post by:
Hello Im having problems figuring out how to remove the duplicate entries in an array...Write a program that accepts a sequence of integers (some of which may repeat) as input into an array. Write a function that processes the array so that any duplicate values are eliminated. Write an output function that prints out the values of the array. You can assume that there are no more than 20 integers in the input. But there may be less. Zero...
1
2257
by: PerumalSamy | last post by:
Hi I am having table with more 13 lakhs records. I am having duplicate records in it. i need to remove that. I wrote the following query SELECT *
7
2825
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds to support cloning: Public Class RefClass Public tcp As TcpClient Public name As String End Class Public Class RefClassList Inherits List(Of RefClass) Implements ICloneable
3
7505
by: Clownboat | last post by:
I've just written a CSS/HTML flyout menu as an addition to an existing system (EQdkp Plus, to be specific). The menu is generated by a couple PHP functions. The output is an unordered list as in this pseudocode: <div class="menu"> <ul> <li>Entry <ul> <li>Submenu Entry</li> </ul> </li> </ul> </div>
7
3594
by: Anthony97 | last post by:
I'm working on removing duplicate records from a table in sql. I've tried using select distinct, and I've grouped by but I'm still running into some issues. Attached is a sample of the output table.
0
8196
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8701
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6122
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5571
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2623
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.