Ok, I have a list of about 250 'profiles', all in a single plain text file. They appear in this format:

FIlE: Users.txt------------------------------ jblow::1337:21::::Joe Blow:/Network/Servers/schoolserv.domain/Volumes/ +UserFiles/Users/jblow::/bin/bash::<home_dir><url>afp\://same.ip.here/ +User%20Files</url><path>jblow</path></home_dir>:<?xml version="1.0" e +ncoding="UTF-8"?>\ <dict>\ <key>kAPOPRequired</key>\ <string>APOPNotRequired</string>\ <key>kAltMailStoreLoc</key>\ <string></string>\ <key>kAttributeVersion</key>\ <string>Apple Mail 1.0</string>\ <key>kAutoForwardValue</key>\ <string></string>\ <key>kIMAPLoginState</key>\ <string>IMAPAllowed</string>\ <key>kMailAccountLocation</key>\ <string>142.176.189.139</string>\ <key>kMailAccountState</key>\ <string>Enabled</string>\ <key>kPOP3LoginState</key>\ <string>POP3Allowed</string>\ <key>kUserDiskQuota</key>\ <string>0</string>\ </dict>\ ::<?xml version="1.0" encoding="UTF-8"?>\ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http\:/ +/www.apple.com/DTDs/PropertyList-1.0.dtd">\ <plist version="1.0">\ <dict>\ <key>simultaneous_login_enabled</key>\ <true/>\ </dict>\ </plist>\ --------------------EOF-Section-----------------------

This is the exact same for every user, except the very first line:

jblow::1337:21::::Joe Blow:/Network/Servers/schoolserv.domain/Volumes/ +UserFiles/Users/jblow::/bin/bash::<home_dir><url>afp\://same.ip.here/ +User%20Files</url><path>jblow</path></home_dir>:<?xml version="1.0" e +ncoding="UTF-8"?>\
which of course changes for each user.

What I need to create, is a function that opens the file, and sets each line to a part of an array (yes, it will be a huge arary). It will then only search for the lines containing the unique user data, and not bother with the rest. Then, it will extract

shortname (jblow)
and
long name (Joe Blow)
and it will create a hash (say %finishedusers), with shortname->longname (or longname->shortname, it really doenst matter)

Any ideas? I have written some code for it, but I'm really not sure how to proceed:

#!/usr/bin/perl -w use strict; use warnings; @numarray= open (NUMLONG, "<$oldfile") or die "Error opening $oldfile +: $!"; @shortarray = open (SHORTLONG, "<$newfile") or die "Error opening $new +file : $!"; sub sessionclean { my $x = 0 foreach $key (@shortarray) if ($key =~ /\:{2}\d+\:{4}/) { } else { # ignore } } }


(You can ignore the reference to oldfile, thats for another part of the script.

In reply to Pattern Matching Question by gsr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.