#!/usr/bin/perl use strict; use warnings; use Data::Dumper qw(Dumper); use re::engine::RE2; use List::MoreUtils qw(uniq); use Sort::Naturally; #This program reads abstract sentence file and produces output with the following format: # if ($#ARGV != 1) { print "usage: program arguments\n"; } my $inputfile1=$ARGV[0]; my $outputfile = $ARGV[1]; my %hashunique=(); open(RF, "$inputfile1") or die "Can't open < $inputfile1: $!"; open(WF, ">$outputfile"); #open for output $/ = ''; #this sets the delimiter for an empty line while () { my @one = split /\n/ , $_; my ( $indexofdashinarray ) = grep { $one[$_] =~ /\-\-/ } 0..$#one; for (my $i=0;$i<=$#one;$i++) { next if $i==0; next if $one[$i] =~ /^\-\-$/; while ($one[$i] =~ m/(\b)D\*(.*?)\*(.*?)\*D(\b)/g) { unless ($hashunique{"D$2"}) { $hashunique{"D$2"}="$3"; } else { $hashunique{"D$2"}=$hashunique{"D$2"}.'|'."$3"; } } } } foreach my $i (nsort keys %hashunique) { $hashunique{$i} = join ( "\|", uniq split /\|/ , $hashunique{$i}); print WF "$i=>$hashunique{$i}\n"; } close (RF); close (WF);