#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |