Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract part of a long string in Perl based on identifiable literal

Status
Not open for further replies.

canguro

Programmer
Sep 15, 2002
57
US
Hello,

As a newbie in Perl I am curious if anyone might know if the following can be done:

1. I have a long string, perhaps typically on the order
of 2000 bytes. There is a definite literal (let's
call it 'literal1') which occurs once in the string
but I can not be sure in which position.

2. I wish to extract all data in that string beginning
from the position where 'literal1' starts all the way
to the end of the string and put it in some scalar
variable. Is this possible? With the power of Perl
I imagine it is, but I am not sure how to proceed.

Any help would be greatly appreciated, and "Thank you in advance!" to all people answering my question.

Joe
 
my ($substring) = ($bigstring =~ /($literal.*)$/);

where $bigstring, is your really big string, $literal is the pattern you want to search and $substring is the portion of the text in $bigstring from $literal onwards that you want to store.

Barbie
Leader of Birmingham Perl Mongers
 
Barbie,

Thank you for your suggestion. It worked out very well.

Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top