in reply to How to reference to array keys?

Hey everybody thanks for the responses.

Not_a_Number,
Well the expected output I haven't really gotten there yet. That's why I wanted to know how to reference to those elements, so later on I could easily pull out the correct data I may need.

jwkrahn,
Does it matter if I'm not using a foreach statement? Because I didn't use any foreach statements in the code... Though I do understand the whole thing about adding/removing elements inside a loop because if you splice something in one place then later on if you loop through you would get a uninitialized variable, or something like that.

jethro,
Yea your right about naming the variables that. They are only like that because the code I posted started out as only a test script for using the "map" function. I really just wanted to see how it works, but then it just grew, and grew and grew. But I do plan on changing them.

Cristoforo,
As far as I know I believe the data does have those spaces on the blank lines. So I guess what your saying, like jwkrahn is trying to say I think is, to remove stuff, or better term exclude stuff, as you read in the file instead of afterwards? I would like to give a try to what you posted, but do you think you could explain the lines in the code between the curly braces, that you posted, where it reads in the <DATA>? I'm kinda new to this so it would really help. And for the "record_id", that piece of data will be the same for the person who has the lock and for the person waiting for that record/file.

Marshall,
This is what the end objective should be... The final script will end up being probably a cron job or something along those lines. When the script runs it will find any "locked" files and email to us a small "log" type file with the more pertinent data. Like who has the lock, what file is locked, how long has it been locked, who is waiting for the file, etc...
Yes, you are right. It does make more sense to get rid of/ignore that stuff, as I read the file in. That would probably eliminate most of the lines of code.
Also, thanks for your code, I will give that a try. My original thought was to use hashes. But I have very little experience using hashes and didn't even know where to begin, so that's why I went with an array.


I want to thank you all for posting, and giving me your suggestions. But I am curious, and it was in the original post. What is the purpose of the "map" function on an array. Does using that allow me to access an element within an element in the array?

There is alot here to take in from all your posts. So it may take me a while to get through all your suggestions. I will post back as soon as I get a little further with this stuff from your posts.


Thanks again,
Matt


Replies are listed 'Best First'.
Re^2: How to reference to array keys?
by Marshall (Canon) on Jul 27, 2011 at 20:50 UTC
    RE: What is the purpose of the "map" function on an array?

    In this code:

    @array = map { my ($file, $recordID, $M, $owner, $pid, $userID, $tty, +$time, $month, $day, $locker) }= split;
    The map does absolutely nothing useful at all! I'm actually not quite sure that it even works at all.
    Anyway it is not needed here.
    @array = my ($file, $recordID, $M, $owner, $pid, $userID, $tty, $time, + $month, $day, $locker) = split;
    map{} is most often used for data transformation. Read map. @output = map{some code}@input; is a typical usage. Each element of @input enters the map as $_. Some processing is done. The return value which passes to the left into @output is whatever the last line of the map code evaluates to. There is no need for a "return" statement.