Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2016-10-24 12:54 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (305 votes). Check out past polls.