-7

I have a txt file like this..

Heading1
Configparameter1  
Configparameter2  
..  
ConfigparameterN  
Input variable1  
Input variable2  
..  
Input variableN  
Output variable1 
.
.  
Output variableN  

Heading2
Configparameter1  
Configparameter2  
..  
ConfigparameterN  
Input variable1  
Input variable2  
..  
Input variableN  
Output variable1  
.  .  
Output variableN  

HeadingN
Configparameter1  
Configparameter2  
..  
ConfigparameterN  
Input variable1  
Input variable2  
..  
Input variableN  
Output variable1  
.
.  
Output variableN 

I don't know how to search for this at Google so I am asking here... please help with perl script to form like below structure.. Thanks a lot

'Heading1' => {    
    'Configparameters' => [  
        Configparameter1  
        Configparameter2  
        .  
        .  
        ConfigparameterN  
    ],  
    'Input variables' => [  
        Input variable1  
            Input variable2  
            .  
            .  
            Input variableN  
    ],  
    'Output variables' => [  
        Output variable1  
        Output variable2  
        .  
        .  
        Output variableN  
    ],  
},  
'Heading2' => {  
    'Configparameters' => [  
        Configparameter1  
        Configparameter2  
        .  
        .  
        ConfigparameterN  
    ],  
    'Input variables' => [  
        Input variable1  
        Input variable2  
        .  
        .  
        Input variableN  
    ],  
    'Output variables' => [  
        Output variable1   
        Output variable2  
        .  
        .  
        Output variableN  
    ],  
},  
'HeadingN' => {
    'Configparameters' => [  
        Configparameter1  
        Configparameter2  
        .  
        .  
        ConfigparameterN  
    ],  
    'Input variables' => [  
        Input variable1  
        Input variable2  
        .  
        .  
        Input variableN  
    ],  
    'Output variables' => [  
        Output variable1  
        Output variable2  
        .  
        .  
        Output variableN  
    ],  
}, 
Ωmega
  • 42,614
  • 34
  • 134
  • 203
Neha
  • 49
  • 1
  • 9
  • 5
    This isn't a place to have your script written for you. Search for perl `open` on how to open and read your file. You'll probably need some regexes to figure out what's a heading and what's a variable. – Cfreak Apr 04 '12 at 13:39
  • see http://stackoverflow.com/questions/2014862/how-can-i-access-ini-files-from-perl, would tell you how to read the **configuration files**. – Nikhil Jain Apr 04 '12 at 14:21

1 Answers1

3

So, what are you looking for?

  • Do you know any Perl at all? Or,
  • Do you know Perl:
    • And, you need help setting up a complex data structure like this?
    • Or, you don't know how to parse the input file?

If you don't know Perl, get the book Learning Perl and go through it step-by-step. It's one of the best beginning programming books I've seen written for any programming language. This is much better than asking for people to write scripts for you.

If you know Perl and simply aren't sure how to setup such a data structure, or how'd you parse it. Ask, and we'll help.

It would also be helpful if you could better describe what you want to do and what your input file actually looks like. For example, how do I know that something's a heading vs. a output variable vs. an input variable vs. a configuration? There's nothing in your description that helps us with that. You don't have to give us real data, but we need better directions.

I've voted to close this question for now because it's really not a question and it's not clear what you want. Take a look at the FAQ to understand what type of questions StackOverflow is for. If you want help with this question, edit it, and give us a better understanding of exactly what you need and what you want to achieve in the end. This will prevent your question from being closed.

There is a lot of Perl tutorials built into Perl itself via the perldoc command. However, you can also find these tutorials in the Perldoc webpage. Go through some of these. The first one is an excellent tutorial on Perl references and what you need in order to create such elaborate data structures.

Have you even tried to code this yourself? People are much more willing to help if they see some of the code you've done. It proves that you've attempted to look at the problem, and at least understand some of the difficulty you're having. It also gives us a better idea of your Perl coding skills, and where we can help you.

And, one more thing: Learn the syntax used in this Wiki. I've edited your question to show your code as code and your text file. I did this by indenting everything by four spaces. This tells the Wiki formatting language that this is formatted code.

Community
  • 1
  • 1
David W.
  • 105,218
  • 39
  • 216
  • 337