Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # package name must be the same as the file name.
- # So this package is called ices, and the file name must be ices.pm
- # Also, the package name should be the same as the Module definition
- # in the ices.conf file: <Module>ices</Module>
- package ices_PL;
- use strict;
- my $LineCount = 0; #Number of Lines in Big Playlist File
- my $Random; #Random path to play from Big Playlist File.
- # Export ices_get_next function.
- require Exporter;
- our @ISA = qw(Exporter);
- our @EXPORT = qw(ices_get_next ices_init ices_shutdown);
- sub ices_init {
- print "Perl subsystem Initializing:\n";
- return 1;
- }
- sub ices_shutdown {
- return 1;
- }
- sub ices_get_next {
- my $buffer;
- my $LINE;
- my @lines;
- $LineCount = 0;
- #count number of lines in Big playlist
- open (MYFILE, '/home/acidrain/Desktop/playlist.txt');
- while (sysread MYFILE, $buffer, 4096) {
- $LineCount += ($buffer =~ tr/\n//);
- }
- close (MYFILE);
- #/DONE COUNTING
- open (MYFILE, '/home/acidrain/Desktop/playlist.txt');
- $Random = int(rand($LineCount)); #make it whole integer
- print "The Random Line#: " . $Random . "\n";
- @lines = <MYFILE>;
- $LINE = $lines[$Random];
- print "The Path: " . $LINE ."\n";
- close (MYFILE);
- return "$LINE";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement