?
Solved

Manipulating an array

Posted on 2003-02-28
2
Medium Priority
?
246 Views
Last Modified: 2011-04-14
Hello gurus


I have same information many times in an array which I would like to use only once before printing to a file. My array looks like this:
-------------------BEGIN--------------------------

for (@sorted1[0..199]) {
                @parts = split /\s*;\s*/;
                print FILEOUT  "$parts[5], $parts[12],  $parts[10]\n";

------------------END-----------------------------

This gives me next result:

KAR, Tree White,  TR
KAR, Stone Nice ,  YY
ETC, Karr Happo,  YY
ETC, Renne Artma,  EKD
ETC, Malk Johns,  RTT
122, Veikk Jann,  RTT
WSR, Mikka Routul,  TRR
WSR, Wss Easy,  EKD
KKK, Ar Parkk,  KDE
334, Wer Moert,  GH
334, Tim Paav,  DFF


Etc.

Now the tricky part. I need to change this so that it gives me next result:


KAR
Tree White,  TR
Stone Nice ,  YY

ETC
Karr Happo,  YY
Renne Artma,  EKD
Malk Johns,  RTT

122
Veikk Jann,  RTT

WSR
Mikka Routul,  TRR
Wss Easy,  EKD

KKK
Ar PArkk,  KDE

334
Wer Moert,  GH
Tim Paav,  DFF

Etc.

So I like to have first column to one own line when this character string appear first time and after this all the names which belong to this same string.

How I can make it ??

Thanks advance

-JS
0
Comment
Question by:salmjuh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
tomclegg earned 800 total points
ID: 8040476
undef $head;
for (@sorted1[0..199]) {                
  @parts = split /\s*;\s*/;
  if($parts[5] ne $head) {
    $head = $parts[5];
    print FILEOUT "\n$head\n";
  }
  print FILEOUT  "$parts[12], $parts[10]\n";            
}

This also prints an empty line at the top of the file.  Is that OK?
0
 

Author Comment

by:salmjuh
ID: 8040682
Yes. This is GREAT !

Thanks.


-js
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question