Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi samira_saber. First things first: Please edit your reply to add code tags around your code! Please see Markup in the Monastery and Writeup Formatting Tips; also see How do I change/delete my post? for general node-editing etiquette.

Some comments (in no particular order):

  • ... it is not working ...
    This is almost useless as a problem description. What is "it"? Is it the code you have posted? How 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 "... before that i read the variable from the text file and print it and it worked." I don't understand this statement, especially in the context of your statement that "it" is not working.)
  • The code in your reply does not have the lines
        use warnings;
        use strict;
    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 warnings and strict. Use of these modules (called pragmas by convention) is referred to as "enabling warnings and strictures."
  • Your code statement
        my $filename_in = "";
    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 requires at least one command line argument (assumed to be the file name) to be present when the script is invoked; the statement
        die "usage: perl $0 \n" unless @ARGV;
    enforces this (see perlvar for info on the  @ARGV array).
  • ... i omitted the line for the $sol.
    In my original code, the my variable  $sol1 holds the string to be substituted in the  s/// substitution operation.
        s{ (SOL) [^\n*] }{$1 $sol1}xmsg;
    I don't understand the point of the substitution operation without something to substitute. Further, if strictures had been enabled (again, see strict), the code would not even compile without this variable being defined and in scope. Even without strictures enabled, warnings would have complained (a run-time warning, not a fatal error) if an undeclared variable having an undefined value had been used — if warnings had been enabled.
  • ... it is not working ... I down know why ...
    This is always useful: Basic debugging checklist.

I hope these comments will be helpful. If you have any questions, please don't hesitate to ask.

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

In reply to Re^2: sed command with variable in perl by AnomalousMonk
in thread sed command with variable in perl by samira_saber

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2022-05-17 17:14 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (68 votes). Check out past polls.