reading from a text file

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

    reading from a text file

    Hi,
    I'm trying to write a program which reads from a text file but the output is always:Couldn't open a file.The path of file is C:\Perl\perlscr ipts.Where should I place this text file ?
  • pukur123
    New Member
    • Sep 2006
    • 61

    #2
    Paste the code here for debug.

    Comment

    • Limeburner72
      New Member
      • Sep 2006
      • 11

      #3
      Originally posted by pukur123
      Paste the code here for debug.
      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);

      Comment

      • robin
        New Member
        • Sep 2006
        • 6

        #4
        place the file so that the relative path is correct... i.e. in the same folder in your case

        or specify the whole path C:/perl.... yeah, slashes go the wrong way

        Comment

        Working...