CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Regular Expressions:
Extracting data and inputting to a file in certain format


New User

Mar 25, 2013, 1:45 PM

Post #1 of 4 (3087 views)
Extracting data and inputting to a file in certain format Can't Post

Hello Perl Gurus,

I am a Quality Manager for a firm. I need to get this work done asap. Dont know anything about coding except for some VBA scripting...

I would get this task done manually, but it will be pretty time consuming.

Can you'll please help me out?

I have this .hh file which contains some register values and bit fileds...all this is alien to me, I was just given to get this done...

I need some data extracted from the file and output in a .tcl file with a certain indentation and some information, since this file is an input to a certain tool that require modification.

I have attached both files...and the .tcl file is the format in which I want the output. Can someone please help me out with the perl script to automate this procedure??

It will be really helpful if someone can take care of this for me. Its an earnest request guys.

Just an excerpt from the .hh file:

// This file is auto-generated. To modify, change hw_ae_5170.input and re-run the generator script(

#pragma once
#ifndef HW_AE_GEN20_HH
#define HW_AE_GEN20_HH

#include <ke_types.hpp>

namespace AEGen2_0 {

class AEGen20HwClass; //Forward Declaration for AEGen20

// Bitfields for AEGen20 // Address Range:(0x15003000-0x15003080)
typedef data16 Reg00Type;
namespace Reg00 { // (0x15003000-0x15003001,RWM)

static const data16 HEAD_SELECT = 0x000F; // <3:0> - RW
static const data16 HEAD_SELECT_BITNUM = 0; // Offset <3:0> - RW
static const data16 READ_BIAS = 0x03F0; // <9:4> - RW
static const data16 READ_BIAS_BITNUM = 4; // Offset <9:4> - RW
static const data16 GAIN = 0x1C00; // <12:10> - RW
static const data16 GAIN_BITNUM = 10; // Offset <12:10> - RW
static const data16 READER_INPUT_IMPEDANCE = 0xE000; // <15:13> - RW
static const data16 READER_INPUT_IMPEDANCE_BITNUM = 13; // Offset <15:13> - RW
} // Reg00
// Done with AEGen20

} // namespace AEGen2_0

The output file should look like this:

catch {namespace delete Sym}

namespace eval Sym {

set SymList [list [list HEAD_SELECT [list 0 0x000F 0]] \
[list READ_BIAS [list 0 0x03F0 4]] \
[list GAIN [list 0 0x1C00 10]] \
[list READER_INPUT_IMPEDANCE [list 0 0xE000 13]] \
[list WRITE_HEATER [list 1 0x03FF 0]] \
[list WRITER_OUTPUT_IMPEDANCE [list 1 0x0C00 10]] \
[list WRITER_8V [list 1 0x1000 12]] \
[list WRITER_RISE_TIME [list 1 0x6000 13]] \
[list OSD_RANGE [list 1 0x8000 15]] ]

Thank you again for the help and I'm really sorry if this may be the wrong forum!! Like I said, I am not at all familiar with coding practices

(This post was edited by yash1709 on Mar 25, 2013, 1:49 PM)
Attachments: hw_ae_gen10.hh (26.5 KB)
  sym20.tcl (0.80 KB)

Enthusiast / Moderator

Mar 25, 2013, 4:13 PM

Post #2 of 4 (3081 views)
Re: [yash1709] Extracting data and inputting to a file in certain format [In reply to] Can't Post

Hmm, don't take it as an offense, but this forum is really a place to ask help if you are trying to do something in Perl and are encountering problems doing it, it is not a bureau to write free programs for you.

If you want to hire someone to do the work for you, you may look at this page:;

Just an example on how you could do what you want. If you have the following line:

static const data16 HEAD_SELECT = 0x000F; // <3:0> - RW

and want to write:

set SymList [list [list HEAD_SELECT [list 0 0x000F 0]] \

I'll assume that you want to use the 0x000F value of the first line to populate the value un the second line. This could be done with something like this (assuming you input line above is stored in the $line variable):

$head_select = $1 if $line =~ /HEAD_SELECT = (0x\w+);/; 
print "set SymList [list [list HEAD_SELECT [list 0 $head_select 0]] \\\n";

You just have to do something like this for all cases, and you are done. Pretty simple, isn't it?

Or may be it does not look simple at all to you. If it looks like mumbo jumbo to you, then we are back to what I was saying at the beginning: may be you should hire someone to do the job and pay that person. It would probably take me just a few hours to do the work, so it would not necessarily be very expensive (but let me be clear, I am a feelance consultant, but I am emphatically not offering my services to do it, I have enough work to fill my day for the time being).

As an additional comment, I must say that you are very very far from giving enough details on how one should use the data from your input file to derive the data to be inserted in your output file. Just for the sample line that coded above, there are many more things derived from my assumptions on or my understanding of what you need than from your description of what you need. You've got to be much more precise and detailed in your specs or bill of requirements.

So, if you find someone to do the work, you'll have do describe much more precisely what you need. No one can write a program and hope to be right just from the example you gave.

New User

Mar 25, 2013, 5:11 PM

Post #3 of 4 (3076 views)
Re: [Laurent_R] Extracting data and inputting to a file in certain format [In reply to] Can't Post

I am not taking it as an offense. Thanks for letting me know about it though.

Thanks a lot for again helping out though.

I'm sorry but the spec of information that I gave wasn't very clear, let me define it again.

I am a manager now, but have been an engineer earlier. Just not someone who has had a good background with programming.

I was just hoping to get a start to this discussion. I can provide the complete spec though.

However, I am going to put in the effort and try to get this done by myself.

Its going to take a while, but yes, with some guidance as a novice to perl scripting using Regexp (which I just googled)...I should be able to get this done.

Thanks a lot Laurent


May 20, 2013, 11:47 PM

Post #4 of 4 (2772 views)
Re: [yash1709] Extracting data and inputting to a file in certain format [In reply to] Can't Post

It's best if you start doing the program, and when you get stuck, focus your question exactly on the point where you are stuck, not the whole program.

Also, since you said that you don't have much experience in programming, it would be helpful if you make clear wheather the question relates to how to solve a problem in general (i.e. "how do I implement a sorting routine"), or to something particular in Perl (i.e. "I know the algorithm of doing a quicksort, but does Perl offer already some tools to sort my data?").

Finally, whenever you start writing something in Perl, ALWAYS start your program with the following directives:

use strict; 
use warnings FATAL => qw(all);
use diagnostics;

Doing so, will save you a lot of work. Once you get more experienced in Perl programming, you might consider to reduce this to

use strict; 
use warnings;


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives