Solved

Perl variable match from end of variable

Posted on 2015-01-07
2
77 Views
Last Modified: 2015-01-07
Hi

I have a variable that has multiple values of the same thing in it.

Example:      $A = "prog aaaa sss -d vvv -t fff prog bbbb rrrr -d vvv -t fff";

I need to get just assign each set of "prog" sections its own variable.

Example:    $B =  "prog aaaa sss -d vvv -t fff";
                    $C = "prog bbbb rrrr -d vvv -t fff";

I could use split but there could be other values in the string.

Thanks
0
Comment
Question by:mikeysmailbox1
2 Comments
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
Comment Utility
You have to either find a unique sequence or fixed length to divide the string on.

If you have a unique sequence, split works fine:
@var = split m{\s+(?=prog\b)}, $A;

Open in new window


If prog could appear within the text then you need to get more clever:
@var = split m{\s+(?=prog\s+string_or_regex_that_will_uniquely_id_section_head)}, $A;

Open in new window

0
 

Author Closing Comment

by:mikeysmailbox1
Comment Utility
Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now