I have some alumni data from which I need to extract useful info. To that end I'm trying to go from the native (pseudo)XML file to a key/value hash.
Before stripping out the excess XML tags the @info array has the full record of one person, a sample of which is in Listing 1. Listing 2 is printed by the code segment shown and the error message is below that.
I've preloaded %data hash just to be sure I can see if there are any changes in the hash.
I'd like to know what the error means, but the real question is how to transform an array into a hash.
The nature of this data is that the keys will all be unique.
(code being tested on a Win98 PC using Active State version 5.005_03)

########### Code Segment ############## my %data = (one => 1, two => 2, three => 3); : # XML stripped off here : print @info; # Prints Listing 2 print %data; # bottom of listing 2 %data = @info =~ /(\w+)\s*(\w+)/g; # Line that gives error print %data; # Prints nothing ####################################### ### Listing 1 ### <Position> Stdnt</Position> <GradYear> 1987</GradYear> <WebPage> http://</WebPage> <E-mail> SomeAddr@abc.com</E-mail> <Comments> Needs highschool yearbooks</Comments> ### Listing 2 ### Position Stdnt GradYear 1987 WebPage http:// Email SomeAddr@abc.com Comments Needs highschool yearbooks three3two2one1 ### Error message ### Applying pattern match to @array will act on scalar(@array) at e.pl li +ne 29

Due to the embedded spaces in some of the data, a better approach might be to strip the XML and create the hash in the same step, but not till I can get through this problem.

Update: Thank you Zaxo, saintmike and ysth. I'm still recovering from the first bout of flu I've had in 20 years and not thinking clearly. I'll put this to use in a few days. Again, thanks!

-Theo-      (so many nodes and so little time ... )


In reply to Putting an array into a hash by Theo

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.