Re: regex/perl golf: loops
by brx (Pilgrim) on Apr 25, 2012 at 21:38 UTC
|
eval'print"perlmonks rule!\n";'x10
update:
print<<R x10
perlmonks rule!
R
update2:
"perlmonks rule!\n"=~/.*?(??{print;$"})/;
| [reply] [d/l] [select] |
|
|
_:${~$/&~$;&$^}++;print "perl monks rule!\n";goto _ if(${~$/&~$;&$^}<1
+0);
lame, i know :) | [reply] [d/l] |
Re: regex/perl golf: loops
by eyepopslikeamosquito (Archbishop) on Apr 25, 2012 at 21:27 UTC
|
print"perlmonks rule!\n";$}++^9&&do$0
# update: alternative version
print"perlmonks rule!\n";$-++-9&&do$0
# update: not crazy, but shorter
eval'print"perlmonks rule!\n";'x10
# update: inspired by brx
s//perlmonks rule!\n/;s/[print ten times!]/print/eg
| [reply] [d/l] |
Re: regex/perl golf: loops
by trizen (Hermit) on Apr 25, 2012 at 21:16 UTC
|
_:print+"perlmonks rule!\n";
++$-<$]+$]>>$?&&goto+_;
| [reply] [d/l] |
|
|
well that sure is crazy :p crap im still doing mine :p so lame
| [reply] |
Re: regex/perl golf: loops
by tobyink (Canon) on Apr 26, 2012 at 07:53 UTC
|
I've not golfed this, but it's pretty crazy. Tested in Perl 5.10, 5.12 and 5.14, but not sure if the sort algorithm is stable enough to guarantee that it will work in future versions of Perl...
use 5.010;
@r = sort
{ say "perlmonks rule!" and $a }
(map {$_ cmp 1} $[ .. $^F) x $^F;
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
| [reply] [d/l] |
Re: regex/perl golf: loops (10)
by BrowserUk (Patriarch) on Apr 25, 2012 at 20:56 UTC
|
By the normal rules of golf, a score of 10 :)
C:\test>echo perlmonks rule! | perl -pe"$_ x=10"
perlmonks rule!
perlmonks rule!
perlmonks rule!
perlmonks rule!
perlmonks rule!
perlmonks rule!
perlmonks rule!
perlmonks rule!
perlmonks rule!
perlmonks rule!
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
| [reply] [d/l] |
|
|
| [reply] |
|
|
lets say it runs from within a perl file, not from using the console.. just as a normal loop would in the average perl script
| [reply] |
|
|
Re: regex/perl golf: loops
by 2teez (Vicar) on Apr 25, 2012 at 21:27 UTC
|
use warnings;
use strict;
my $cot = 0;
LOOP: {
print "perlmonks rule", $/;
redo LOOP if ++$cot < 10;
}
| [reply] [d/l] |
Re: regex/perl golf: loops
by JavaFan (Canon) on Apr 25, 2012 at 22:32 UTC
|
$ cat xxx
#!/usr/bin/perl -l
BEGIN{close STDERR}print"perlmonks rule!";truncate$0,-1+-s$0;exec$0;##
+#####
$ ./xxx
perlmonks rule!
perlmonks rule!
perlmonks rule!
perlmonks rule!
perlmonks rule!
perlmonks rule!
perlmonks rule!
perlmonks rule!
perlmonks rule!
perlmonks rule!
$
| [reply] [d/l] |
Re: regex/perl golf: loops
by Ratazong (Monsignor) on Apr 26, 2012 at 06:42 UTC
|
No recursive solution till now?! This has to be changed (for the sake of TIMTOWTDI, not golfing):
perlmonksrule(9);
sub perlmonksrule
{
if ($_[0]) { perlmonksrule($_[0]-1); }
$_ = (caller(0))[3];
s/sr/s r/;
print /::(.*)$/,"!\n";
}
update: a more compact version here (without the usage of the function-name):
$a=9;a();sub a{a()if($a--);print"perlmonks rule!\n";}
| [reply] [d/l] [select] |
Re: regex/perl golf: loops
by LanX (Saint) on Apr 26, 2012 at 10:05 UTC
|
> print join ". Perl rules!\n", 1..10, ""
1. Perl rules!
2. Perl rules!
3. Perl rules!
4. Perl rules!
5. Perl rules!
6. Perl rules!
7. Perl rules!
8. Perl rules!
9. Perl rules!
10. Perl rules!
| [reply] [d/l] |
Re: regex/perl golf: loops
by brx (Pilgrim) on Apr 26, 2012 at 13:26 UTC
|
| [reply] [d/l] |