You can do this a few ways. Here are two:
my ($way_1) = $string =~ /(\w+\s{1,}\w+)\s{1,}\w+$/;
my ($way_2) = join(" ",@_[0,1] = split(/ +/,$string));
print "way_1 = $way_1\n";
print "way_2 = $way_2\n";
Out of curiosity, I benchmarked these and the regex is faster than the array
slice. Lucky for me, since I would normally use the regex!
> -----Original Message-----
> From: Hsu, David [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, February 16, 2005 10:26 AM
> To: perl-win32-users
> Subject: Reg. expression help
>
>
> Hi,
> Can someone help me with the syntax of deleting the last word of text
> string.
> i.e. $string = 'my abc 123'
> Like to have only 'my abc'
>
> Thanks,
> David
>
>
> _______________________________________________
> Perl-Win32-Users mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
>
>
> __________________________________________________________
> Message transport security by GatewayDefender.com
> 10:31:08 AM ET - 2/16/2005
>
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs