Else try This..
#!/usr/local/bin/perl
use strict;
my $string = "Theres more than 1 way to do it";
if ($string =~ /\w+$/){
print "Hooray! pattern found\n";
print $&;
}
Use the inbuilt perl variables..
$` prints the pre matching part, $& gives the matched variale and $' gives the
post matching pa
Michael Alipio <[EMAIL PROTECTED]> asked:
> #!/usr/local/bin/perl
> use strict;
>
> my $string = "Theres more than 1 way to do it"; if ($string
> =~ /\w+$/){ print "Hooray! pattern found"; print $1; }
>
> My goal is to print the last word.
> However, it only prints "Hooray! pattern found";
>
>
> #!/usr/local/bin/perl
> use strict;
>
> my $string = "Theres more than 1 way to do it"; if ($string
> =~ /\w+$/){ print "Hooray! pattern found"; print $1; }
You need to wrap the bit you wish to extract in (paremphasis) and it'll be put
into $1. If you do two (wraps), you'll get $1 and $2, and