note
AnomalousMonk
<p>
Hi [samira_saber]. First things first: <i>Please edit your [id://1197458|reply] to add code tags</I> around your code! Please see [id://674668] and [id://17558]; also see [id://17557] for general node-editing etiquette.
</P>
<p>
Some comments (in no particular order):
<ul>
<li>
<blockquote><i>
... it is not working ...
</I></BLOCKQUOTE>
This is almost useless as a problem description. <i>What</I> is "it"? Is it the code you have posted? <i>How</I> does it not work? Is there an error or warning message or messages? Under what conditions of input, etc., etc.? (Later in your reply you write <i>"... before that i read the variable from the text file and print it and it worked."</I> I don't understand this statement, especially in the context of your statement that "it" is <i>not</I> working.)
</LI>
<li>
The code in your [id://1197458|reply] does not have the lines <br>
<c> use warnings;</c> <br>
<c> use strict;</c> <br>
at the start of the source code. These provide very important support and protection for a novice Perler — and for elder Monks as well; I rarely write write a Perl program without using them. See [doc://warnings] and [doc://strict]. Use of these modules (called pragmas by convention) is referred to as "enabling warnings and strictures."
</LI>
<li>
Your code statement <br>
<c> my $filename_in = "topol1.top";</c> <br>
means you are hard-coding the input file name, whereas I was taking the file name from a command line argument. Indeed, the code still <i>requires</I> at least one command line argument (assumed to be the file name) to be present when the script is invoked; the statement <br>
<c> die "usage: perl $0 file.name \n" unless @ARGV;</c> <br>
enforces this (see [doc://perlvar] for info on the <c> @ARGV </C> array).
</LI>
<li>
<blockquote><i>
... i omitted the line for the $sol.
</I></BLOCKQUOTE>
In my original code, the [doc://my] variable <c> $sol1 </C> holds the string to be substituted in the <c> s/// </C> substitution operation.<br>
<c> s{ (SOL) [^\n*] }{$1 $sol1}xmsg;</c> <br>
I don't understand the point of the substitution operation without something to substitute. Further, if strictures had been enabled (again, see [doc://strict]), the code would not even compile without this variable being defined and in scope. Even without strictures enabled, [doc://warnings] would have complained (a run-time warning, not a fatal error) if an undeclared variable having an undefined value had been used — if [doc://warnings] had been enabled.
</LI>
<li>
<blockquote><i>
... it is not working ... I down know why ...
</I></BLOCKQUOTE>
This is always useful: [id://745674].
</LI>
</UL>
</P>
<p>
I hope these comments will be helpful. If you have any questions, please don't hesitate to ask.
</P>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-634253">
<hr><p>Give a man a fish<b>:</B> <c> <%-{-{-{-<</C></P>
</div></div>
1197380
1197458