My Second, first japh
jfredett
created: 2006-08-09 10:45:02
It appears that the first time I posted this, it did not go through, I think I missed hitting some button. Anyway; This is one of my first Japhs I've ever tried. One of my CS-geek friends told me that it might not work on all systems. But I know it works on WinXP. I thought it was pretty clever for my second day in. It's probably not, but anyway...
$Just = $0; open(JAPH, $Just); @another = split(/\s/, ); $Perl = ""; $hacker =",";
$Perl =join(" ", (substr($another[0],1)),(substr($another[5],1)),(substr($another[9],1)),(substr($another[12],1))); 
close(JAPH); print ($Perl . $hacker);
The only thing I'd like to really do, is figure out how to remove the readability in the function names and stuff. I tried looking at B::Deparse, which was mentioned in one of these nodes. But I don't think thats what will do it for me... ~~Joe
Re: My Second, first japh
created: 2006-08-10 03:40:02

First of all, welcome to the OC [id://565838].

Not every JAPH has to be obfuscated and I like where you are going with this. I think some perlism would improve it though. Removing parens and the close statement ( perl doesn't need them.)

$Just = 'foo'; open(JAPH, $Just); @another = split(/\s/, ); $Perl = ""; $h
acker =",";
$Perl =join " ",(substr $another[0],1),(substr $another[5],1),(substr $another[9
],1),(substr $another[12],1);
print $Perl . $hacker;

I had to put in the 'foo' cause I'm on unix. Now, adding a subroutine.
$Just = 'foo'; open(JAPH, $Just); @another = split(/\s/, ); $Perl = ""; $h
acker =","; sub Just { substr shift, 1 };
$Perl =join " ", Just($another[0]), Just($another[5]), Just($another[9]), Just (
$another[12]);
print $Perl . $hacker;
Kind of has a stutter now doesn't it? Continuing on boldly. Playing with whitespace:
$Just = 'foo'; open JAPH, $Just; @another = split /\s/, ; $Perl = ""; $hac
ker =","; sub
Just {  substr shift, 1 };   $Perl = join " ", Just ($another[0]), Just($
another [6]),  Just($another [11]),  Just ($another [14]); print $
Perl    .$
hacker,
There, that's better. Not there yet. I would like it to be shorter but it's late here.

s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}
Re^2: My Second, first japh
created: 2006-08-10 21:59:39
so- let me make sure I'm getting all of this. Perl is alot to learn all at once... :)
1) just curious, but does $0 == 'foo' on unix? that is to say will 'foo' will open the source file? or is that just a dummy var because unix doesn't have that capability?
2) I take it that perl doesn't require parens, so open J, $k == open(J, $k); I also infer from what you said (and wrote) that no parens is the norm for built in calls, but use parens for user defined function calls.
EDIT: Reading your post again, its terribly obvious that perl doesnt require parens, it's so obvious mostly because you said so, in smallish black print... so yah, question answered. mostly. /EDIT
3) I like the sound of the Just($another x) calls, the repitition makes that final line of $Perl . $hacker work even better than before.

Hopefully my newb isn't showing too much. But I definitely learned something. Thanks!

~~Joe
Re^3: My Second, first japh
created: 2006-08-11 00:12:23
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/, ; $Perl = " ";  $hacker = ","; sub Just { substr shift , 1 };
$Perl = join $Perl, Just ($another[0]), Just ($another[5]), Just ($another[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/, ; $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
Re^4: My Second, first japh
created: 2006-08-11 15:39:33

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/, ; $ 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,  ; $ 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}
Re^3: My Second, first japh
created: 2006-08-11 13:41:42

No [id://565838], 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}
Re^4: My Second, first japh
created: 2006-08-11 19:27:15
That little postcard thing was terribly cool, I've got to say-- Thanks for helping, I learned alot.
~~Joe

perlmonks.org content © perlmonks.org and jfredett, starbolin

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03