reading from text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Limeburner72
    New Member
    • Sep 2006
    • 11

    reading from text file

    Hi,
    here is the code:

    use warnings;
    open(FILEHANDLE ,"school.txt ") or die"Couldn't open file:$!";
    while ($line = <STDIN>)
    {
    while ($line =~ s/(\w+)(.*)/$2/)
    {
    $word = $1;
    $wordHash{$word }++;
    }
    }
    while (($word, $count) = each(%wordHash) )
    {
    $wordHash[$i] = "$word\t$count" ;
    $i++;
    print ("$word\n");
    }
    close(FILEHANDL E);
  • Rykus
    New Member
    • Sep 2006
    • 5

    #2
    Originally posted by Limeburner72
    Hi,
    here is the code:

    use warnings;
    open(FILEHANDLE ,"school.txt ") or die"Couldn't open file:$!";
    while ($line = <STDIN>)
    {
    while ($line =~ s/(\w+)(.*)/$2/)
    {
    $word = $1;
    $wordHash{$word }++;
    }
    }
    while (($word, $count) = each(%wordHash) )
    {
    $wordHash[$i] = "$word\t$count" ;
    $i++;
    print ("$word\n");
    }
    close(FILEHANDL E);



    What do you need with this?
    You haven't specified if you're having a problem, or if you're just sharing code...

    Comment

    • Limeburner72
      New Member
      • Sep 2006
      • 11

      #3
      Hi,
      I'd like to know where should I place a text file on my computer to be read from.The output from this code is always:Couldn't open this file.I don't know where I went wrong.

      Comment

      Working...