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

Re: Please find out the mistake in substitution function in the code??

by GotToBTru (Prior)
on May 11, 2015 at 15:42 UTC ( [id://1126320]=note: print w/replies, xml ) Need Help??


in reply to Please find out the mistake in substitution function in the code??

Your print OUT if (...) needs something to print.

You should work out how you would do this manually in order to form your algorithm. I would suggest building a hash where the values from file2 are the keys, and the corresponding strings from file3 are the values. Then, for each line in file1, loop over the hash keys and replace with hash value if key is found in line.

Dum Spiro Spero
  • Comment on Re: Please find out the mistake in substitution function in the code??

Replies are listed 'Best First'.
Re^2: Please find out the mistake in substitution function in the code??
by AnomalousMonk (Archbishop) on May 11, 2015 at 17:40 UTC
    Your print OUT if (...) needs something to print.

    print will output the value of  $_ localized in the enclosing  while (<IN1>) { ... } loop.


    Give a man a fish:  <%-(-(-(-<

      I had to look at that again; of course you're right. But only lines for which the substitution is performed will print. I think that is not exactly what is wanted. Perhaps more like:

      while(...) { s/.../.../; print OUT; }

      The lines with recognized codes will be corrected; lines without codes will still be copied to the output.

      Dum Spiro Spero
Re^2: Please find out the mistake in substitution function in the code??
by sumathigokul (Acolyte) on May 12, 2015 at 05:12 UTC

    Hi GotToBTru...

    Since i want to automate this process and nets.txt and enabled_nets.txt files are all generated automatically, every time I will not know the contents of those files, in such case,. how can i make it as hash.... Do you find any mistake in this code??

      Using the arrays you have already loaded:

      %hash = map { $nets[$_] => $enabled_nets[$_] } 0..$#nets;
      Dum Spiro Spero

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-16 19:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found