I played w/ the whitespace some more, and also did a neat thing with the $Perl variable. Here's the code:
$Just = $0; open JAPH,$Just; @another = split /\s/, <JAPH>; $Perl = "
+"; $hacker = ","; sub Just { substr shift , 1 };
$Perl = join $Perl, Just ($another[0]), Just ($another[5]), Just ($ano
+ther[10]), Just ($another[15]); print $Perl . $hacker,
I set the $Perl variable to a whitespace, which makes it so you can fit the whole thing on just two lines. Then I played with the whitespace enough so that the words for "Just another Perl Hacker," are on spaces of multiple 5. Since now its a simple loop. Here's a shorter version:
$Just = $0; open JAPH,$Just; @another = split /\s/, <JAPH>; $Perl = "
+"; $hacker =",";sub Just {substr shift,1};
for($hack = 15; $hack > -1 ; $hack -= 5){$hacker = Just($another[$hack
+]) . $Perl . $hacker};$hacker =~ s/\s,/,/s;
print Just $Perl.$hacker,
254 characters. not bad, right? I think thats in the canonical limits.
Japhs are fun :-)
~Joe | [reply] [d/l] [select] |
Actually, on my previous reply where I said $scalar I should have said @array. An array is just a list.
You've done some good work there. Again, I've made some changes. Not that they are better, it's just a matter of taste.
Using an array slice you don't need the loop. Of course the loop may be more obfuscating. It all depends on whether you want size or complexity.
$ Just =$0;open JAPH, $Just;@ another =split /\s/, <JAPH>; $ Perl =" "
+; $ hacker =",";
sub Just{}; $hacker=join' ',@another[1,5,10,15],$hacker;
print Just.$Perl.$hacker,
Slurp the whole thing in so we can break the first line wherever we want and make a little postcard.
$/='';$ Just =$0;open JAPH, $Just;@ another =split
/\s+/s, <JAPH>; $ Perl = " "; $ hacker =","; sub Just{}
;$hacker =join' ', @another[1, 5,10,15] , $hacker; print
Just.$Perl.$hacker,
206 characters
s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s
|-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,,
$|=1,select$,,$,,$,,1e-1;print;redo}
| [reply] [d/l] [select] |
No jfredett, nothing fancy with the 'foo' which is just the name of file in which I saved the script. On unix, $0 just returns 'perl' not the path of the running script like on Windose. So I'm just doing a direct 'open' on my script to read the source.
Parens in perl is a list operator. They say package these item up as a list. If you already have a list, say in a $scalar or returned from a function call, then using parens is redundent. Arguments to function call also are passed as a list so when you say "print $a, $b" perl knows you mean "pass a list consisting of $a followed by $b". And will try very hard to make sense of your code. But perl would get confused if we used this inside another list such as "join ' ', print $a, $b , $some_other_stuff". How would perl know if $some_other_stuff went with "join" or "print"? So sometime we have to use parens to be clear to perl what we mean. But I look at a lot of the code here on perlmonks you'll see that for simple statements parens are often not used.
We all learn perl in smallish bites so hang in there.
s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s
|-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,,
$|=1,select$,,$,,$,,1e-1;print;redo}
| [reply] [d/l] |
That little postcard thing was terribly cool, I've got to say-- Thanks for helping, I learned alot.
~~Joe
| [reply] |