Solved

Perl variable match from end of variable

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

632 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