Solved

Perl variable match from end of variable

Posted on 2015-01-07
2
82 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
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

734 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