Solved

Perl variable match from end of variable

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Check file date before getting folder path 1 64
add a syntax to a csv file 8 98
File Find regex problem 4 60
Vb script to unzip a files and rename the files 12 97
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

895 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

14 Experts available now in Live!

Get 1:1 Help Now