Home: Perl Programming Help: Beginner:
\K in perl not working



kunwar
New User

Mar 22, 2011, 3:40 AM


Views: 3904
\K in perl not working

Hi All,
I have just started learning perl and was working on my one-liners tips and tricks.

Instead of using the below command :
perl -lape 's/(^From:).*/$1 Nelson Elhage <nelhage\@ksplice.com>/'

i tried using the \k command using the below command but it gave no results:

perl -lape 's/^From:\K.*/ Nelson Elhage <nelhage\@ksplice.com>/'


Is there some problem with the perl version on my unix box. Please find some of details of the platform i am using:

Code
 
> uname -a
HP-UX hpxi017 B.11.23 U ia64 1433056900 unlimited-user license

> perl -v i

This is perl, v5.8.8 built for IA64.ARCHREV_0-thread-multi
(with 33 registered patches, see perl -V for more detail)


Sorry if it is a very basic question Smile
Regds,
KunwarSmile


BillKSmith
Veteran

Mar 22, 2011, 6:11 AM


Views: 3896
Re: [kunwar] \K in perl not working

I have searched all of perlre and perlreref for documentation on \K or \k and cannot find it. I doubt that there is such a 'command' in perl 5.8.8. Sorry if I have overlooked something. BTW, all the special characters in regular expressions are case sensitive.
Good Luck,
Bill


kunwar
New User

Mar 22, 2011, 7:35 AM


Views: 3891
Re: [BillKSmith] \K in perl not working

Hi Bill, Thanks for replying .

I was practicing the one-liners given on the below link:

http://blog.ksplice.com/2010/05/top-10-perl-one-liner-tricks/

See the Trick #7: \K for the doubt which i am asking.
Looking at the comments which author has received on this , it seems that there does exist such a option.


Karazam
User

Mar 22, 2011, 8:06 AM


Views: 3888
Re: [kunwar] \K in perl not working

The \K seems to have been introduced in Perl 5.10.0. It is not available in 5.8.8, as Bill said.
http://perldoc.perl.org