Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Here's what happens in your script:

The input file is read line by line by the foreach loop. Each iteration through the loop reads and processes the current line, which is stored in the $_variable.

chomp makes sure there's no newline character at the end of your $_; The following line removes leading whitespace (^ means match at the beginning and \s is a special character that stands for 1 white space and // before g is 'nothing' so -replace white space with nothing). I'm not sure I understand why the g at the end as it stands for 'global' but your regexp specifically says 'beginning of $_' (by the use of ^)

The next line replaces the occurrence of a dot with _. You don't seem to have any dots in your input so I'm guessing that must be used on other input files or must have been copied from elsewhere without any adjustment.

Next, your 'if' tries to find if your current line $_ contains the string 'SA120'. If it does you go inside the block if not I'm guessing you move on to the next iteration of your foreach loop (the end of that loop is missing in your published code)

If you find the string, you split it where the = symbol shows up, which means you get the numeric value at the right in the second "half" of the string and the text to the left of = in the first "half". Then you split the first half again, where a colon is. This is where your problem occurs. your $TEMP_ARRAY_21 is something like "Prct Dirty Cache Pages". You don't need that you need:

$SA120 = $TEMP_ARRAY_1[1];
You already got your numeric value after the first split so remove the second split (does nothing (good) for you) and update the assignment so your $SA120 gets the second half of the FIRST (and not only) split.

Hope this helps!


In reply to Re: Yet another question about reading in data from a file for use in another file by RaduH
in thread Yet another question about reading in data from a file for use in another file by wruehl

Title:
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 How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (8)
As of 2024-04-18 11:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found