Offer Kaye wrote:
On Wed, 23 Mar 2005 17:41:31 -0800, Perl wrote:

Hi.

I would like to search a scalar variable and have the output to another
scalar. For example:

$test = "This is some test data";

I want another scalar, $regex to hold the output of a regular expression
lookup against $test.

So something like this:

$regex =~ /test/ running against $test. Is this possible somehow?




Simply assign the result of the match to a variable:
my $re_result = $test =~ m/test/;
Always be careful to do this in list context. In scalar context, you only get the number of matches, not the matches themselves.

See perlop for details and perlretut for more detailed examples.


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to