Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^3: Assign Output of Regex to Array (newbie)

by davido (Archbishop)
on Sep 25, 2013 at 22:06 UTC ( #1055754=note: print w/replies, xml ) Need Help??

in reply to Re^2: Assign Output of Regex to Array (newbie)
in thread Assign Output of Regex to Array (newbie)

This approach gives you a flat array. If you want to add an element to each line, you have to decide if it's satisfactory to just append the information to existing elements, or whether you really need a multi-dimensional data structure. For example:

@PRC_PRIV_ONLY = ( 'one string', 'two strings', 'three strings', ); foreach my $element ( @PRC_PRIV_ONLY ) { $element .= ' appended data'; }

Or if you need a 2d data structure:

foreach my $element ( @PRC_PRIV_ONLY ) { $element = [ $element, '2nd element' ]; }

That transforms the above into:

@PRC_PRIV_ONLY = ( [ 'one string', '2nd element' ], [ 'two strings', '2nd element' ], [ 'three strings', '2nd element' ], );

...which can be indexed like this: print $PRC_PRIV_ONLY[0][1], "\n"; (prints 2nd element).


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055754]
and one hand claps...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2017-06-26 09:18 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (575 votes). Check out past polls.