Advertisement
Guest User

Untitled

a guest
Mar 17th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.23 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # package name must be the same as the file name.
  3. # So this package is called ices, and the file name must be ices.pm
  4. # Also, the package name should be the same as the Module definition
  5. # in the ices.conf file: <Module>ices</Module>
  6. package ices_PL;
  7.  
  8. use strict;
  9.  
  10. my $LineCount = 0; #Number of Lines in Big Playlist File
  11. my $Random; #Random path to play from Big Playlist File.
  12.  
  13.  
  14. # Export ices_get_next function.
  15. require Exporter;
  16. our @ISA = qw(Exporter);
  17. our @EXPORT = qw(ices_get_next ices_init ices_shutdown);
  18.  
  19. sub ices_init {
  20.     print "Perl subsystem Initializing:\n";
  21.     return 1;
  22. }
  23.  
  24. sub ices_shutdown {
  25.     return 1;
  26. }
  27.  
  28.  
  29. sub ices_get_next {
  30. my $buffer;
  31. my $LINE;
  32. my @lines;
  33. $LineCount = 0;
  34.     #count number of lines in Big playlist
  35.     open (MYFILE, '/home/acidrain/Desktop/playlist.txt');
  36.         while (sysread MYFILE, $buffer, 4096) {
  37.         $LineCount += ($buffer =~ tr/\n//);
  38.         }
  39.     close (MYFILE);
  40.     #/DONE COUNTING
  41.  
  42.     open (MYFILE, '/home/acidrain/Desktop/playlist.txt');
  43.     $Random = int(rand($LineCount)); #make it whole integer
  44.     print "The Random Line#: " . $Random . "\n";
  45.  
  46.     @lines = <MYFILE>;
  47.     $LINE = $lines[$Random];
  48.     print "The Path: " . $LINE ."\n";
  49.     close (MYFILE);
  50.  
  51.     return "$LINE";
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement