Creating a 2D perl array to store data

Discussion in 'Perl' started by teknokid1, Nov 17, 2011.

  1. teknokid1

    teknokid1 New Member

    Nov 9, 2011
    Likes Received:
    Trophy Points:
    Respected All,

    Kindly help me out.

    I have got file listings in a directory like this:

    -rw-r--r-- 1 root root 115149 2011-11-17 07:15 file1.stat.log
    -rw-r--r-- 1 root root 115149 2011-11-18 08:15 file2.stat.log
    -rw-r--r-- 1 root root 115149 2011-11-19 09:15 file3.stat.log
    -rw-r--r-- 1 root root 115149 2011-11-20 10:15 file4.stat.log
    -rw-r--r-- 1 root root 115149 2011-11-21 11:15 file5.stat.log

    I am storing this output in the @data array as mentioned below:

    foreach $_(`ls -lrt *stat*`)
    @data = split " ", $_;

    Now, I want to create a 2D array of 5x3 dimensions, Let's say output[][] in perl, to store the
    desired information.This column of 2D array's output[][] will be filled by @data array's 6th,7th and 8th columns.
    I want to use referances.


    output[][] =
    data[6] data[7] data[8]
    data[6] data[7] data[8]
    data[6] data[7] data[8]
    data[6] data[7] data[8]
    data[6] data[7] data[8]

    The desired info will be

    output[][] =

    2011-11-17 07:15 file1.stat.log
    2011-11-18 08:15 file2.stat.log
    2011-11-19 09:15 file3.stat.log
    2011-11-20 10:15 file4.stat.log
    2011-11-21 11:15 file5.stat.log

    I want to create a function for this and want to return this 2D array output[][] as the result.

    Please help me out.
    I shall be very thankful to you.

    Warm Regards,

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice