# MacOSX.com free perl script assoc.



## xoot (May 14, 2002)

Here is how this works:

1) You make a perl script.
2) You distribute it freely within this thread.

Please attach your scripts as text files, and explain how they work.

And, most of all, have fun!


----------



## nkuvu (May 14, 2002)

You want all of my Perl scripts, or just the ones I think might be useful to others?


----------



## earector (May 14, 2002)

Wow, what a great idea! I can't wait to see what comes of it.


----------



## xoot (May 14, 2002)

> _Originally posted by nkuvu _
> *You want all of my Perl scripts, or just the ones I think might be useful to others? *



All, but not too much.


----------



## nkuvu (May 14, 2002)

I'll have to take a look at them -- some of them may be considered to be proprietary, since I wrote almost all of them for work.  But if I can edit out any super secret stuff (  ) I'll post them.  Give me some time and I'll get at least something up here...


----------



## xoot (May 14, 2002)

My reverse text script (just out of the blue).

Use it to reverse your text. 

I did this script because I was competing with ksuther's ReverseText program (and because I didn't want to risk installing it on my system).

Note about this thread: You can also modify other people's programs to incorporate more features, or fix bugs.


----------



## BlingBling 3k12 (May 14, 2002)

exactly how the hell do i make that work? 

i know nothing about coding


----------



## nkuvu (May 14, 2002)

Save into a text file (MacOSX.com download will make it attachment.php).  I use .pl extensions, but it really doesn't matter.

Execute chmod +x _filename_.

Type ./_filename_, or perl _filename_.

Enjoy.


----------



## nkuvu (May 14, 2002)

Here's a really basic one.  Comments are in the script.  More to come later...


----------



## BlingBling 3k12 (May 14, 2002)

> _Originally posted by nkuvu _
> *Save into a text file (MacOSX.com download will make it attachment.php).  I use .pl extensions, but it really doesn't matter.
> 
> Execute chmod +x filename.
> ...



 LOL!!!!!!!!!!!!!!!!!

i'm on Windows XP... exactly how do i do such advanced operations?!  LOL!


----------



## nkuvu (May 14, 2002)

Sorry, I forgot.   

You don't have Perl built in to the system, I'd suggest going to http://www.activestate.com and downloading their Perl version.  The exact link is http://downloads.activestate.com/ActivePerl/Windows/5.6/ActivePerl-5.6.1.631-MSWin32-x86.msi

I gave you the link to skip the registration garbage, but that's optional anyway.  It's about an 8MB download, but free.

Double click on that to install (Duh  ).  Once it is all done, do everything I already mentioned, but skip the chmod step.  If you have your file associations set properly, you can just type in the filename at a command prompt.  Even if you don't have file associations set up, you can type perl _filename_ to run the script.

For file associations, I usually set it to Edit as default.  Then I  can double click on my Perl scripts and edit them (with your favorite text editor (I can send recommendations if you want)).  If you don't change this yourself, the file is automatically run via the Perl interpreter (like running perl filename).  The problem with that is that the command prompt window doesn't stick around unless it needs input, so most scripts are pretty useless.  I use the command prompt method myself...

If you want further explanation of any of this, feel free to ask -- I've kind of glossed over a lot of detail that I think you can figure out on your own.


----------



## nkuvu (May 14, 2002)

Here's another script, slightly more complicated than my previous one.    Drive mapping is for Windows only -- there isn't a point for OS X.  Keep in mind that these scripts were written for work, which is on a Windows machine using ActiveState Perl.


----------



## simX (May 14, 2002)

Of course, you could just get a Mac and Mac OS X, and then install ksuther's text service, which allows you to reverse a piece of text in any Cocoa application, !taht ekil tsuj

.od ot ysae ytterp s'tI

!desrever eb lliw txet eht dna [-dnammoC sserp ,yawyna em rof ,neht dna ,txet eht thgilhgih tsuJ


----------



## ksuther (May 14, 2002)

This is what they have been talking about: http://homepage.mac.com/ksuther/reversetext.tar.gz

Have fun 
Install in Library/Services, and log out and in. In any cocoa app just to command-shift-r or select it from the services menu. Enjoy 

I'll post some of my old perl scripts later


----------



## nkuvu (May 14, 2002)

Doh!  Darn Windows text!

The scripts posted need to have their line endings converted to run on OS X.


----------



## nkuvu (May 14, 2002)

*sigh*  And each script should have the shebang (#!/usr/bin/perl) added to the first line to be able to be called by ./_filename_.

But they will work (after line end conversion) with perl _filename_ just fine.

Here's another simple one.


----------



## nkuvu (May 15, 2002)

> _Originally posted by simX _
> *Of course, you could just get a Mac and Mac OS X, and then install ksuther's text service, which allows you to reverse a piece of text in any Cocoa application, !taht ekil tsuj*


While I appreciate the input (I wouldn't have known about the sevice otherwise), I think you're either *A.* missing the point or *B.* being less than serious.

If the only thing you can think of to do with Perl is reverse text, then go check out the service.


----------



## xoot (May 15, 2002)

I'm trying to create a perl reverse text *server*. You send stuff there and it reverses the text. Cool, huh?

The uncool thing is that i don't know how to program a perl server (insert flame or angry shouting here). Anyone know any web sites that could give a few pointers on this?


----------



## blb (May 15, 2002)

> _Originally posted by xoot _
> *I'm trying to create a perl reverse text server. You send stuff there and it reverses the text. Cool, huh?
> 
> The uncool thing is that i don't know how to program a perl server (insert flame or angry shouting here). Anyone know any web sites that could give a few pointers on this?  *



Easiest way is to modify your script to take the string from stdin and send the reversed text to stdout.  This way you can have it run from inetd without having to worry about networking code.


----------



## xoot (May 15, 2002)

Thanx!

The only question left: How do you run it from inetd?

Attached is the script (designed for inetd).


----------



## blb (May 16, 2002)

To set it up for inetd, first put the script someplace publically-readable (but not writable) like /usr/local/bin or something.
Then we need to setup the _reverse_ service.  On other *nix, you would add a line to /etc/services, but this is Darwin/OS X, which uses NetInfo, so instead we must run

```
sudo niutil -create / /services/reverse
sudo niutil -createprop / /services/reverse port 9876
sudo niutil -createprop / /services/reverse protocol tcp
```
This creates an entry in NetInfo's services directory called _reverse_ (change if you prefer it called something else); it has two properties:  port (9876, again, change if you want a different port), and protocol (tcp).

Now we need to tell inetd about reverse:

edit /etc/inetd.conf (with pico, vi, whichever you prefer)
add the line

```
reverse stream  tcp     nowait  nobody  /usr/local/bin/reverse.pl reverse.pl
```
then save it
run

```
kill -1 `cat /var/run/inetd.pid`
```

Change the path and scriptname in step 2 if they are different.  After this, you should be able to

```
$ telnet localhost 9876
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
this is the reverse server
revres esrever eht si siht
Connection closed by foreign host.
```
One thing to note is be sure you save the script with Unix-type linebreaks; the attachment wasn't.

For those curious, see *man inetd* for information on the line added to inetd.conf (note the user used is _nobody_ which is a security feature as this particular server shouldn't need any serious access).


----------



## dricci (May 16, 2002)

Perl sucks. Can it be PHP or AppleScript, or even Basic?


----------



## xoot (May 16, 2002)

Thank you! It really is an internet super-server!

Cool, now you can run any perl script via inetd! I'll even try a C app.

Dricci: Look at the title of this thread. Create your own assoc.


----------

