Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Perl variable match from end of variable

Posted on 2015-01-07
2
Medium Priority
?
84 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 26

Accepted Solution

by:
wilcoxon earned 2000 total points
ID: 40536559
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
 
LVL 1

Author Closing Comment

by:mikeysmailbox1
ID: 40536603
Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Six Sigma Control Plans

730 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