Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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).


Comment on Re^3: Assign Output of Regex to Array (newbie)
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055754]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2015-12-01 23:11 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (29 votes), past polls