Tuesday, December 2, 2008

Perl and the Array..

Ok this is not going to be much fun for the average person but I found it helpful. Figured I would put it out here for everyone to ponder.. much like the meaning of life, why are we here, how my belly button fills with lint. The REALLY important stuff.

I was working on a small script ( I really do not call it a program). In this script, I needed to find the most recent log file on a Linux box and do something with it. How I accomplished this was a rather cumbersome Perl script but here goes:

1. I was able to sort the data by using "ls -c". This put the newest log file on top.
2. The I was able to pipe that data into an array. If you are not familiar with an array, it stores information in separate entries kind of like of a database.
3. Since I wanted the first entry in the array I was able to pull it using the following code:

@item_wanted = $array_i_am_using[0];

Then I can print the array item out if needed etc.

Hope this helps someone.

I might be reading this later in the future :)

No comments: