Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Yet another question about reading in data from a file for use in another file

by RaduH (Scribe)
on Dec 14, 2007 at 16:02 UTC ( #657065=note: print w/replies, xml ) Need Help??


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!

  • Comment on Re: Yet another question about reading in data from a file for use in another file
  • Download Code

Replies are listed 'Best First'.
Re^2: Yet another question about reading in data from a file for use in another file
by wruehl (Acolyte) on Dec 14, 2007 at 18:25 UTC
    Thanks, that's exactly what I needed.
    -Bill

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2022-08-20 05:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?