Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
No such thing as a small change
 
PerlMonks  

Re: perl script for adding information to c file.

by choroba (Abbot)
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.


Comment on Re: perl script for adding information to c file.
Select or Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2014-04-23 22:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (556 votes), past polls