in reply to Alternative to Substr?

Including your code would make it easier to answer your question. But I have to assume your using a regex, not substr, if you reference $`. However, if you are using a regex, $` contains the part of the string before the matched text, not after. Also, $` incurs a performance hit.

I think you want to do something like this:

$match #what you want to match $string # the string to extract from if($string =~ /$match(.+)/){ ... do something with $1 ... }

This assumes that $match only occurs once in the string, and that you want everthing after that point.

TheEnigma

Replies are listed 'Best First'.
Re^2: Alternative to Substr?
by tachyon (Chancellor) on Sep 29, 2004 at 12:17 UTC

    This assumes that $match only occurs once in the string

    No it does not. Perl will take the first match.

    and that you want everthing after that point.

    Your RE won't deliver the rest of the string in a very common circumstance as . does not match a newline until you add /s

      Both very good points. But like I said, I had to make some assumptions, not knowing what his data looks like or what he wants to extract from it.

      If $match did occur more than once, I don't know which one he wants to use; maybe he wants to use all of them. That would require a change to my code. So I assumed the simplest scenario. Same with your second point, I was assuming simple lines of text with a newline only at the end.

      TheEnigma