I'm trying to extract certain lines out of some text:

employee[1] = new employee_element(15,"Bob","Smith","Sales");\n

And pop them into an array of arrays of that include the employee info and the index of "employee[x]" that it was found with in the text block. I know to use $1 and $2 to get the matching text but I don't know how to use "map" to get it.

The above line text would become an array that looks like:
[ 1, 15,"Bob","Smith","Sales" ]

Below is my try at making it work but I can't figure it out.
#!/usr/bin/perl -w use strict; use Data::Dumper; my $data = qq( Stuff here junk text <tr><td class='menutext' align='center'><input typ employee[1] = new employee_element(15,"Bob","Smith","Human Resources") +; employee[2] = new employee_element(03,"Harry","Jones","Coordinato"); employee[3] = new employee_element(23,"Janet","Davies","Development"); employee[4] = new employee_element(95,"James","McAvery","Communication +s"); more junk text ); # Question: How do I transform the above chunk of text into what I w +ant? # I need to get out the employee_element info and put it # into an array of arrays as seen below. The employee[x] identifier # needs to also be the first part of the array. I know to use # $1 for the match, but I don't know how to apply it to this. # Here is my attempt to map out the employees info into an array my @employees_my_try; push @employees_my_try, ( map { $_ =~ m/^employee\[(.*)\] = new employee_element\((.*)\);$/g } split "\n", $data ); print Dumper \@employees_my_try; # End result, store each employee info into an array of arrays with # employees index also listed. my @employees = [ [ 1, 15,"Bob","Smith","Human Resources" ], [ 2, 03,"Harry","Jones","Coordinato" ], [ 3, 23,"Janet","Davies","Development" ], [ 4, 95,"James","McAvery","Communications" ] ]; print Dumper @employees;

In reply to Parsing and Matching Text with Map by awohld

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.