Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Golf: Embedded In Order

by boo_radley (Parson)
on Apr 27, 2001 at 21:05 UTC ( #76170=note: print w/ replies, xml ) Need Help??


in reply to Golf: Embedded In Order

42 chars in the sub.

use strict; my $s = "abcdefghijklmnopqrstuvwxyz"; my $t = "for"; print x($s,$t),"\n"; $t="perl"; print x($s,$t),"\n"; sub x{ my($s,$t)=@_; eval"\$s=~tr/$t//cd"; $s eq$t; }
update
one less:
sub x{ eval"\$_[0]=~tr/$_[1]//cd";$_[0]eq$_[1]; }


Comment on Re: Golf: Embedded In Order
Select or Download Code
Re: Re: Golf: Embedded In Order
by MeowChow (Vicar) on Apr 27, 2001 at 22:07 UTC
    Interesting method, but it doesn't properly handle:
    my $s = "abcfoforrxyz"; my $t = "for";
    There are also serious escaping issues with the interpolated code inside the eval :)
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://76170]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2015-07-04 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls