Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

modify slice in array and write back to file 1

Status
Not open for further replies.

LinguaFranca

Technical User
Jan 4, 2005
18
NL
Hope my question isn't too stupid but I just cannot get it working.

I have a database output like this:

Code:
# ---------------------------------------------
# 
# Exported Dictionaries: 
# 
#    C:\TRANSIT.WIN\DB\CODA\INTELL
# 
# Date of Export: 10.01.2005
# 
# Format of Export: (ansi)
# 
#    Concept Number;[];Hdr->Datasource e-Procurement/e-Billing/e-Invoice Matching;Hdr->Datasource CODA-Intelligence;Hdr->OLE;Hdr->Entered By;Hdr->Date of Entry;Hdr->Last Update By;Hdr->Date of Last Update;Hdr->Datasource Workflow;Hdr->Subject Area;Hdr->Datasource Financials;Hdr->Datasource e-Finance;Hdr->Datasource e-Assets;
#    Concept Number;[Language];Term;Definition;Index;Abbr./Acronym;Alternatives;Synonyms;Introduced as of version;Remarks;Hotkey;Irregular Plural;Cross-Reference;Part of Speech;Gender;Context;Source;Status;Entered By;Date of Entry;Last Update By;Date of Last Update;User 1;Valid upto/incl.;Validated by;Additional Status;Former Term;
# 
# ---------------------------------------------

1; []; ; companyparameters.res; ; ; ; CAL; 11.11.2004; ; CODA-Intelligence; ; ; ; 
1; [ENG]; 'From' cannot be empty.; ; ; ; ; ; v10.1; ; ; ; ; ; ; ; ; confirmed; ; ; CAL; 11.11.2004; ; ; ; ; ; 

2; []; ; cpkpi.res; ; ; ; CAL; 11.11.2004; ; CODA-Intelligence; ; ; ; 
2; [ENG]; 'From' date or period is after 'To' date or period.; ; ; ; ; ; v10.1; ; ; ; ; ; ; ; ; confirmed; ; ; CAL; 11.11.2004; ; ; ; ; ; 

3; []; ; companyparameters.res; ; ; ; CAL; 11.11.2004; ; CODA-Intelligence; ; ; ; 
3; [ENG]; 'Group' cannot be empty.; ; ; ; ; ; v10.1; ; ; ; ; ; ; ; ; confirmed; ; ; CAL; 11.11.2004; ; ; ; ; ;

and I need to modify a slice of data within these lines:
Code:
1; []; ; companyparameters.res; ; ; ; CAL; 11.11.2004; ; CODA-Intelligence; ; ; ; 
2; []; ; cpkpi.res; ; ; ; CAL; 11.11.2004; ; CODA-Intelligence; ; ; ; 
3; []; ; companyparameters.res; ; ; ; CAL; 11.11.2004; ; CODA-Intelligence; ; ; ; 
5; []; ; kpiwizard.res; ; ; ; CAL; 11.11.2004; ; CODA-Intelligence; ; ; ; 
6; []; ; genericlists.res, genericlists.res; ; ; ; CAL; 11.11.2004; ; CODA-Intelligence; ; ; ; 
7; []; ; dimensioncostcentre.res, dimensioncustomer.res, dimensionemployee.res, dimensiongeneral.res, dimensionnominal.res, dimensionproduct.res, dimensionproject.res, dimensionsubaccount.res, dimensionsupplier.res, eventviewer.res, dimensioncostcentre.res, dimensioncustomer.res, dimensionemployee.res, dimensiongeneral.res, dimensionnominal.res, dimensionproduct.res, dimensionproject.res, dimensionsubaccount.res, dimensionsupplier.res, eventviewer.res, dimensioncostcentre.res, dimensioncustomer.res, dimensionemployee.res, dimensiongeneral.res, dimensionnominal.res, dimensionproduct.res, dimensionproject.res, dimensionsubaccount.res, dimensionsupplier.res, eventviewer.res, dimensioncostcentre.res, dimensioncustomer.res, dimensionemployee.res, dimensiongeneral.res, dimensionnominal.res, dimensionproduct.res, dimensionproject.res, dimensionsubaccount.res, dimensionsupplier.res, eventviewer.res, dimensioncostcentre.res, dimensioncustomer.res, dimensionemployee.res, dimensiongeneral.res, dimensionnominal.res, dimensionprod; ; ; ; CAL; 11.11.2004; ; CODA-Intelligence; ; ; ;

I'll have to uniquely sort all filenames in $files[3] of the lines pointed out above. When done I need the original output but then with the revised sorted data in it.

How do I define this? Up to now it only outputs the slice with the manipulated data. And my $_ only contains the first line of my input data file.

Here's what I have so far:
Code:
#!usr/bin/perl

use warnings;
use locale;
use strict;

open TERMSTAR, "INTELL.ANS" or die;
open OUTPUT, ">intell.output.ans" or die;

while (<TERMSTAR>) {
	chomp;
	
	#grab all header lines from export file
	my @headers=grep /^[0-9]+; \[\]/, <TERMSTAR>; 
	
	#grab 4th slice of a header line
	foreach my $fields (@headers){
          my @files = split(/\; /, $fields);
					my @filelist = split (/, /, $files[3]);
										
					#uniq sort on filenames of slice 4
						my %seen=();
						foreach (@filelist) {
						$seen{$_}=1;
						}
						my @uniqfilenames = sort keys %seen;
						print OUTPUT join (", ", @uniqfilenames), "\n";
						
	}	
}							
close OUTPUT;
close TERMSTAR;
exit;

Not sure whether I am clear enough. Hope one of you guys can help.
 
This should give you a direction to go in:

Code:
while (<DATA>) {
    if (/\d+;\s*\[];/) {
        my @record = split(/;/, $_);
        my %files;
        map {$files{$_}++} split(',', $record[3]);
        $record[3] = join(',', sort keys %files);
        print join(';', @record);
    }
}
 
Thanks for your quick response. I am sorry for not having answered earlier but I had a very urgent project to set up.
I have a follow up question and will ask you when I have time again to work on my script. Thanks again.
 
Ha, you put me on the right track. It worked. Thanks you very much for helping me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top