I want add some information to c file. I have two hash tables one hash table contains information about some strings and numbers to stings like as shown below.

hash table1 (keys)(string nubers) (values)string names 24 temperature 25 pressure 26 humidity

like this i have more strings and regarding numbers. in this hash table keys are numbers and values are string names. i have another hash table which contains string numbers and information.

hash table 2 (keys)(string nubers) (values)string names 24 information 25 information 26 information.

like that i have second hash table. numbers in the both hash tables are same and each string having unique number.there is no repetion in numbers like 1 to 100 numbers. now in my c file i have the sting names like temperature and humidity and pressure..... i have to search that string using these hash tables and i have to add information after the string if i found any string in the c file. i have written code like this but its notworking.

#!/usr/bin/perl use warnings; use strict; open (my $code , "<", 'ccode.c'); my %data = ('24'=>":&temperature \n", '25'=>": &pressure \n", '26'=>": &humidity\n", ); my %nums = ( '24'=>": information1\n", '25'=>": information2 \n", '26'=>": information3 \n", ); my $test_string="(" .join("|", keys %data).")" ; while(<$code>){ if (/$test_string/){ chomp; %data= reverse %data; $_.=$nums{$data{1}}; } print $_ }

if i excute this script it doesnt give any errors and no added information in the c file. it giving original c file as it is.what should i have to change in this code. my c file is lokking like as below.


In reply to perl script for adding information to c file. by veerubiji

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.