Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: perl script for adding information to c file.

by choroba (Chancellor)
on Oct 10, 2011 at 08:55 UTC ( #930559=note: print w/replies, xml ) Need Help??

in reply to perl script for adding information to c file.

  1. You are searching for strings in this (or similar) form:
    ":&temperature \n"
    Such a string in not present in your data.
  2. Also, you are reverting %data back and forth. That's probably not what you need.
  3. I tried to clear your code and make it run:
    #!/usr/bin/perl use warnings; use strict; my $code = *DATA; my %data = (24 => 'temperature', 25 => 'pressure', 26 => 'humidity', ); my %nums = ( 24 => ": information1\n", 25 => ": information2 \n", 26 => ": information3 \n", ); %data = reverse %data; my $test_string = '(' . join("|", keys %data) . ')' ; while (<$code>){ if (/$test_string/) { chomp; $_ .= $nums{$data{$1}}; } print; } __DATA__ /*! ********************************************************************** +******* * * $b Description: Pressure Valve high ********************************************************************** +******/ #include "ccode.h" /********************************************************************* +*******/ /* Local function prototypes (static): */ void main_10ms(void) { temperature ( i need to add infomation before string that found) if {..... ...... if{........ ..... }else {...... } } humidity( i need to add infomation before string that found) if {..... ...... if{........ ..... }else {...... } }
  4. Do you really need two hashes? Having just one with the information like temperature => 'information1' would be much easier.
Update: Restructured.

Replies are listed 'Best First'.
Re^2: perl script for adding information to c file.
by veerubiji (Sexton) on Oct 10, 2011 at 11:51 UTC

    Hi choroba, Its working but i have one problem with this script, it adding information how many times sting found in c file. But i need to add only once.for example if temperature string found three times in c file, so it adding same information three times. if string found add information at once is enoghf. no need to add same information so many times(how many times string presents).because in my file i have repeated strings so its aadding same information several times. how can i rectify this.

      how can i rectify this.

      Modify program to use hash "%seen" to keep track of substitutions already made

      See perlfaq6

        Hi, if u dont mind can you tel how can i use that function in my code. because i read that you sended link but i cant found any such function, how to use that function.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://930559]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2016-10-01 22:49 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (9 votes). Check out past polls.