mIRC Home    About    Download    Register    News    Help

Print Thread
mIRC syntax to Perl syntax #109581 30/01/05 11:20 PM
Joined: Jan 2005
Posts: 37
S
Scratch Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Jan 2005
Posts: 37
This may be a little off topic, but I would appreciate anyone who codes in Perl, to convert the following mIRC alias into Perl syntax/code. I would greatly appreciate this.

Code:
 
alias test {
  if ($isfile(test.txt)) { goto process }
  :process

  var %fl = $lines(test.txt)

  if (%fl >= 1) { 

    var %rline = $rand(1,%fl)

    echo -a $read(test.txt,%rline)

    write $+(-dl,%rline) test.txt

    goto process  
  }
}




Explanation about what the code is doing:

I have a text file called 'test.txt'. This text file has data on each line. The above code reads a random line from the text file, echoes the data, then it removes the line in the text file containing the data. Then the process restarts again untill the text file is empty.

I need a Perl script that will do exactly the same thing as above.

Re: mIRC syntax to Perl syntax #109582 31/01/05 02:39 AM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Code:
#!/usr/bin/perl
#
# Filename: shuffle.pl
#
# Usage: ./shuffle FILENAME
#
# Description: shuffles FILENAME and prints to stdout
use strict;

shuffle($ARGV[0]);

sub shuffle($) {
  my(@lines, $r);
  if (!-e $_[0]) { return; }
  open(FILE, $_[0]);
  @lines = <FILE>;
  while ($#lines) {
    $r = int(rand($#lines));
    print $lines[$r];
    splice(@lines, $r, 1);
  }
  close(FILE);
}


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"