View Single Post
Old 05-05-2007, 05:31 PM   #8 (permalink)
robot_parade
Junkie
 
Location: San Antonio, TX
Well. First things first.

Add:


use warnings;
use strict;


Right below the #!/usr/bin/perl line in your script. Do this for all your perl scripts, great or small. Tell your professor I told him to do this as well.

Also, I noticed that $j is never used. Weird, but whatever.

Anyway, the test I decided to use was /\w\w/ - ie 'does the supposed URL contain 2 'word' characters (a-z, plus dash) this rules out a single dash, and a bunch of other possible bogus data.

As an aside, apparently tfproject's software doesn't properly escape '>' and '<' - so you need to change them to '>' and '<' respectively when you post code, even inside a 'code' block - this is what caused the 'while' line to not show up correctly.

Code:
#!/usr/bin/perl

use warnings;
use strict;

my $id = 0;
my $i = 0;
my $j = 0;
my $q = "";

open (IN, "test");
open (OUT, ">testresult");

while (<IN>){
  chomp;
  my @a = split /\t/;

  if ($id == $a[0]) {
    if ($a[1] =~ /\w\w/) {
      $q = $q . "; $a[1]";
      $i++;
    }
  }
  else {
    $j++;
    print OUT "$id\t$q\t$i\n";
    $id = $a[0];
    $q = $a[1];
    $i = 1;
  }

}
close(IN);
close(OUT);
Oh, and as far as your error running the script goes - sounds like perl is missing from /usr/bin/perl - try running 'which perl' and see if it's available. Also try 'perl -v' to make sure it really runs. If it isn't there, install it. Or install a real distro. Ubuntu sux. (I kid. ;-))
robot_parade is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43