Sign in to follow this  
Followers 0
Turmoil

Perl Help

6 posts in this topic

This may be just a question for Nick84 but, I was wondering how you made that random quote display on your site? Any help or ideas would be great.

Also if anyone remembers the first things they made with perl and could give me a little list of things to try to make that would be helpful.

I should really buy a book soon ;)...

0

Share this post


Link to post
Share on other sites

Well this is a script that does the same thing as mine but in a simpler way:

#!/usr/bin/perl -w#!C:\Perl\bin\perl.exe -w###################################quotes file contains different quotes separated by 1 returnprint "Content-type: text/html\n\n";$quotes_file = "quotes.txt":$sep = "\n";open(DAT,"$quotes_file");@DAT = <DAT>;close(DAT);$quotes = join('',@DAT);@quotes = split(/$sep/,$quotes);srand(pid ^ $$); # unix#srand(time ^ $$); # windows$quote = rand(@quotes);$print_quote = $quotes[$quote];print $print_quote;

What else is there for a first script except:

#!/usr/bin/perl -wprint "Content-type: text/html\n\n";print "Hello, world!\n";
0

Share this post


Link to post
Share on other sites

Let me know if you want any more help etc, also what system are you programming on, and how are you running it (command line or webserver)?

0

Share this post


Link to post
Share on other sites

Thanks for the help.

Also I’m running windows... and I guess command line. Basically I’m just fooling around with perl till I get an Idea of something to do with it.

~T

0

Share this post


Link to post
Share on other sites

Of course nick is the authority, but you can check out the perl at the end of my Fat Linux article - it's simple and semi-useful. In fact, feel free to use/add/change the code. I was planning to add a selectable kiosk mode option, so that may be one route.

0

Share this post


Link to post
Share on other sites

First thing i ever wrote(not really) in perl was an irssi/xmms script. I was using xchat for a while and had an xmms script that i wanted to use when i switched to irssi, turns out it doesn't 'just work' :blush:

Here is the orsiginal xchat script ... http://sentience.0catch.com/BoBB/xmms-share.pl ... Its pretty long so i wont cut and paste it here :)

Here is what i ended up with.

# Some info on how to use the script ...

#

# /XMNEXT, /XN : advance to the next track on the playlist

#

# /XMPREV, /XP : go back on track on the playlist

#

# /XMRH : Refresh the playlist variable

#

# /XMPL [] : start playing at the current track or start playing

# track # this can also be used to restart the

# track you are on(i.e. - /xmpl will stop the track, and

# play the track if its allready playing

#

# /XMST : Stops playing the current track

#

# /XMPS : Pauses playing of the current track

#

# /XMSEARCH, /XS : Searches @playlist for a string and outputs anything

# containg that string with its position in the

# playlist. Very very useful.

#

# I DID NOT WRITE THIS CODE. I MERELY PORTED *SOME* OF IT TO IRSSI SO IT

# WOULD WORK. I DONT KNOW PERL AT ALL SO I COULDN'T PORT ALL OF IT. THE

# AUTHOR OF THIS CODE AND THE ORIGINAL XCHAT SCRIPT CAN BE FOUND HERE,

# http://www.akk.org/~zorg/ GIVE CREDIT WHERE CREDIT IS DUE.

use strict;

use vars qw($VERSION %IRSSI);

use Irssi;

$VERSION = '0.01';

%IRSSI = (

authors => 'BoBB, [JuPiLeR]',

contact => 'snoogans@qwest.net, geert@irssi.org',

name => 'irssi-xmms-share',

description => 'This was an xchat script that i just loved written by Zirias and when

i stopped using xchat i decided to try and port it over. I only have some of the basic stu

ff done that was easy as i dont know perl ... yet :) Full credit should go to Zirias as i

hardly did anything. I will try and get contact info for him ASAP.',

license => 'GPL (whichever is current ATM)',

);

use Xmms::Remote ();

use POSIX;

Irssi::print("Loading ...");

Irssi::command_bind('xmnext', 'xmms_next');

Irssi::command_bind('xn', 'xmms_next');

Irssi::command_bind('xmprev', 'xmms_previous');

Irssi::command_bind('xp', 'xmms_previous');

Irssi::command_bind('xmrh', 'xmms_rehash');

Irssi::command_bind('xmpl', 'xmms_play');

Irssi::command_bind('xmst', 'xmms_stop');

Irssi::command_bind('xmps', 'xmms_pause');

Irssi::command_bind('xmsearch', 'xmms_search');

Irssi::command_bind('xs', 'xmms_search');

Irssi::command_bind('xmms', 'xmms_handler');

my @playlist = qw//;

my $length = 0;

my $xmms_remote = Xmms::Remote->new();

my $pl_pos = $xmms_remote->get_playlist_pos;

sub xmms_handler {

my ($data, $server, $channel) = @_;

my $awin = Irssi::active_win();

if ($xmms_remote->is_playing) {

my $title = $xmms_remote->get_playlist_title;

$awin->command("me is listening to ={\c_\cC12 $title \c_\cO}=");

}

return 1;

}

sub getplaylist {

$length = $xmms_remote->get_playlist_length;

for (my $i;$i<$length;$i++) {

my $title = $xmms_remote->get_playlist_title($i);

$title =~ s/(_[^_]*_[^_]*_)|( - )/ <> /;

@playlist = (@playlist,"\cB".($i+1).".\cB ".$title);

}

}

sub xmms_play {

my $num = shift;

if (($num=~/^[0-9]+$/)&&($num>0)&&($num<=$length)) {

$xmms_remote->stop;

$xmms_remote->set_playlist_pos($num-1);

}

$xmms_remote->play;

return 1;

}

sub xmms_search {

my $pattern = shift;

if ($pattern !~ /^$/) {

$pattern =~ s/([\&;\`'\\|"~.<>^\(\)\[\]\{\}\$\n\r])/\$1/g;

$pattern =~ s/\*/.*/g;

$pattern =~ s/\?/./g;

my @result = grep /$pattern/i, @playlist;

my $num = @result;

Irssi::print("\c_$num Results:\c_");

foreach(@result) {

Irssi::print($_);

}

} else {

Irssi::print("\cBUSAGE: /XMSEARCH \cB");

}

return 1;

}

sub xmms_stop {

$xmms_remote->stop;

return 1;

}

sub xmms_pause {

$xmms_remote->pause;

return 1;

}

sub xmms_next {

if ($xmms_remote->is_playing) {

$xmms_remote->playlist_next;

}

return 1;

}

sub xmms_previous {

if ($xmms_remote->is_playing) {

$xmms_remote->playlist_prev;

}

return 1;

}

sub xmms_rehash {

@playlist=qw//;

getplaylist;

Irssi::print("\cB\cC4xmms-share\cO: Playlist re-read.");

return 1;

}

getplaylist;

1;

If anyone actually takes the time to look you'll see i lost quite a bit of functionality due my not knowing a damn thing about perl. Infact i still dont know that much. I should finish porting this thing over and learn me some perl :) Now that i think about it ive never shown anyone this or anything. So if i did something incredibly dumb or something please let me know :)

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0