http://qs321.pair.com?node_id=657065


in reply to Yet another question about reading in data from a file for use in another file

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!