Question

could you anyone help me with the logic to change/organize log entries

input_array = [
  ["2/6/2014", "13:31:12", "IN", "application1", "user1", "machine1"]
  ["2/6/2014", "13:31:12", "IN", "application2", "user2", "machine2"]
  ["2/6/2014", "13:31:52", "IN", "application3", "user3", "machine3"]
  ["2/6/2014", "13:38:37", "OUT", "application1", "user1", "machine1"]
  ["2/6/2014", "14:46:37", "OUT", "application2", "user2", "machine2"]
  ["2/6/2014", "15:56:37", "OUT", "application3", "user3", "machine3"]
]

How to access individual elements within this array .. such as 2/6/2014 or application1?

when I do input_array[1][4], the desired output is ...

"application1" # and not 6 ... its giving me the 4 character in line 1

appreciate your help!

Was it helpful?

Solution

Perhaps you mean this:

input_line = [
  ["2/6/2014", "13:31:12", "IN", "application1", "user1", "machine1"],
  ["2/6/2014", "13:31:12", "IN", "application2", "user2", "machine2"],
  ["2/6/2014", "13:31:52", "IN", "application3", "user3", "machine3"],
  ["2/6/2014", "13:38:37", "OUT", "application1", "user1", "machine1"],
  ["2/6/2014", "14:46:37", "OUT", "application2", "user2", "machine2"],
  ["2/6/2014", "15:56:37", "OUT", "application3", "user3", "machine3"]]

?

You can then use the syntax input_array[i][j] without issues!

OTHER TIPS

Your proposed code has an error, if you actually defined your array like this:

input_array = [
    ["2/6/2014", "13:31:12", "IN", "application1", "user1", "machine1"],
      ["2/6/2014", "13:31:12", "IN", "application2", "user2", "machine2"],
      ["2/6/2014", "13:31:52", "IN", "application3", "user3", "machine3"],
      ["2/6/2014", "13:38:37", "OUT", "application1", "user1", "machine1"],
      ["2/6/2014", "14:46:37", "OUT", "application2", "user2", "machine2"],
      ["2/6/2014", "15:56:37", "OUT", "application3", "user3", "machine3"]
    ]

You would then be able to access your array like this:

2.0.0p195 :054 > input_array[0][0]
 => "2/6/2014" 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top