> 
> I was just trying to match a string and save it in a single statement
> as follows:
> 
> $extracted = "cp xyz";
> $state_var = $extracted =~ m/cp\s+(.*)/;
> print "$state_var $1 \n";
> 
> The output is: 1 xyz
> 
> So the assignment to $state_var does not work. Is this an incorrect way.
> 

The correct way is ever so close to that

#!/usr/bin/perl
use strict;
use warnings;

my $extracted = "cp xyz";
my ($state_var) = $extracted =~ m/cp\s+(.*)/;
print "$state_var\n";

--L


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


Reply via email to