Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Perl Scripting | hashes



ravi333raj
New User

Aug 2, 2015, 9:08 PM


Views: 9850
Perl Scripting | hashes

I have an input file which looks like below -

=IP1
abc[0]
abc[1]
abc[2]
=IP2
def[4]
def[8]
def[9]

I need to get the output in the below format-

=IP1
abc[0-2]
=IP2
def[4,8-9]

Can anyone help to achieve the above using hashes


Laurent_R
Veteran / Moderator

Aug 4, 2015, 1:02 PM


Views: 9815
Re: [ravi333raj] Perl Scripting | hashes

Hmm, you don't give enough information. I could suggest a very simple solution (almost a one-liner) or a far more complex one, depending on what more input data looks like.

Is "=IP" always a separator between different sections? If so, are the "sections" always containing the same root (i.e. first three letters) values? Would the following output:

Code
=IP1 
abc[0,1,2]
=IP2
def[4,8,9]

be acceptable (it would be far easier)?