I think this problem is a little advanced for someone "very new" to Perl. Do you understand the basic data structures of perl (perldoc perldata)? Do you have a fair understanding of regular expressions (perldoc perlretut)? How about references (perldoc perlreftut)? If you have a pretty good grasp of those concepts, you should be able to take a stab at this problem.

Generally, it's recommended that you use a module to parse XML type data files, but a quick and dirty solution might go like this:

use strict; use warnings; my %info; my $thisuser; while (<DATA>) { my ($var, $val) = /<([^>]+)>([^<]+)/; if ($var eq 'UserID') { $thisuser = $val; } else { $info{$thisuser}{$var} = $val; } } use Data::Dumper; print Dumper(\%info), "\n"; __DATA__ <UserID>46786<UserID> <start>2004-10-21TO09:57:25Z</start> <dev>Some Text</dev> <var1>some string</var1> <var2>some string</var2> <USerID>57864</UserID> <start>2004-10-25TO09:57:25Z</start> <dev>Some Text</dev> <var1>some string</var1> <UserID>46786<UserID> <var3>some string</var3> <var4>some string</var4> <UserID>98766</UserID> <start>2004-10-21TO09:57:25Z</start> <dev>Some Text</dev> <var1>some string</var1> <var2>some string</var2> <var5>some string</var5> <var6>some string</var6> <USerID>57864</UserID> <var4>some string</var4> <var6>some string</var6>

Caution: Contents may have been coded under pressure.

In reply to Re: getting parts of the strings from a file into managable variables by Roy Johnson
in thread Help:getting parts of the strings from a file into managable variables by my_perl

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.