Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.6 / 3....
  • Linux Kernel 3.0.82 LTS...
  • KDE Software Compilatio...
  • PulseAudio 4.0
  • Wireshark 1.10.0
  • NetworkManager 0.9.8.2
  • LibreOffice 3.6.6 / 4.0...
  • SystemRescueCd 3.7.0
  • Linux Kernel 3.10 RC6
  • Ubuntu Tweak 0.8.5
  • Home > Linux > Programming > Perl Modules

    Tie::MmapArray 0.04

    Download button

    No screenshots available
    Downloads: 210  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Andrew Ford | More programs
    Perl Artistic License / FREE
    March 22nd, 2010, 07:50 GMT
    ROOT / Programming / Perl Modules

     Read user reviews (0)  Refer to a friend  Subscribe

    Tie::MmapArray description

    mmap a file as a tied array

    Tie::MmapArray is a Perl module that lets you use mmap to map in a file as a perl array rather than reading the file into dynamically allocated memory. It depends on your operating system supporting UNIX or POSIX.1b mmap, of course. (Code to use the equivalent functions on Win32 platforms has been contributed but has not been tested yet.)

    The type of array elements is defined by the template argument or option. This is a Perl pack()-style template, which defaults to "i". The template may be an array reference, in which case the elements are defined by pairs of name and template for each element. A template string may define multiple fields, in which case that element is regarded as an array of fields (which need not be of the same type).

    The following example shows the utmp file on Linux mapped to an array:

     tie @utmp, 'Tie::MmapArray', '/var/log/utmp',
     { mode => "rw",
     template => [ ut_type => 's',
     ut_pid => 'i', # pid_t
     ut_line => 'a12',
     ut_id => 'a4',
     ut_user => 'a32',
     ut_host => 'a256',
     ut_exit => [ # struct exit_status
     e_termination => 's',
     e_exit => 's' ],
     ut_session => 'l',
     ut_tv => [ # struct timeval
     tv_sec => 'l',
     tv_usec => 'l' ],
     ut_addr_v6 => 'l4',
     pad => 'a20' ] };


    This can be scanned as follows:

     for (my $i = 0; $i < @utmp; $i++) {
     printf("pid: %d, user: %s\n",
     $utmp[$i]->{ut_pid}, $utmp[$i]->{ut_user});
     }


    The following subset of pack() template letters is supported:

    i

     signed integer (default)
    I

     unsigned integer
    c

     signed character (one byte integer)
    c

     unsigned character (one byte integer)
    s

     signed short integer
    S

     unsigned short integer
    n

     unsigned short integer in network byte order
    l

     signed long integer
    L

     unsigned long integer
    N

     unsigned long integer in network byte order
    f

     float
    d

     double
    aN

     fixed-length, null-padded ASCII string of length N
    AN

     fixed-length, space-padded ASCII string of length N
    ZN

     fixed-length, null-terminated ASCII string of length N

    The size of the array is defined by the nels option. If this is zero then it is calculated as the file size divided by the element size.

    If the file size is smaller than the size required for the requested elements then a single zero byte will be written to the final byte of the requested size. This seems to prevent the module dying with a segmentation or bus error if memory is accessed beyond the end of the file and generally results in a file with holes (unallocated blocks). Precise details of the behaviour of the module are subject to change.

    SYNOPSIS

     use Tie::MmapArray;

     tie @array, 'Tie::MmapArray', $filename;
     tie @array, 'Tie::MmapArray', $filename, $template;
     tie @array, 'Tie::MmapArray', $filename, { template => $template,
     nels => 0,
     mode => "rw",
     shared => 1,
     offset => 0 };

     $len = (tied @array)->record_size;



    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    map files | tied array | Perl module | Perl | tie | array

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM