Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: perl script for adding information to c file.

by choroba (Bishop)
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]
[marto]: This won't take till Summer to complete I hope ;)
[Discipulus]: i hope too, vacuum cleaner permitting, 2-3 afternoon to build. Or is the 1:1 serie? ;=)
[Tanktalus]: Sure, no one is active for hours and hours in the cb, so I go to upgrade the db, and then someone is active. Sheesh :)
[Discipulus]: anyway poppins probably died with the last night cold. But is not normal to see them in dec. they must pop in April
NodeReaper eyes the thorns in the side
Discipulus : the party puller!
[Discipulus]: I was trying to solve this but i'm not. my regex-fu is stuck at primary school

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2017-12-18 21:35 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (498 votes). Check out past polls.