Closed Thread
Results 1 to 4 of 4

Thread: Help please!

  1. #1
    noob117 is offline Newbie
    Join Date
    May 2007
    Posts
    7
    Rep Power
    0

    Help please!

    I am suppose to make a perl script that counts the number of words in a text file and then creates a file called output file and writes "there are [number] words in input.txt". Yeah this is suppose to be easy but i suck balls so yeah. this is what i have, and it doesnt work and stuff.
    Code:
    #!C:\perl-5.10.0\bin\perl.exe
    $wordCount = 0;
    open(input, "input.txt") || die("No file:\n$!");
    open(output, ">output.txt") || die("No file:\n$!");
    
    $i = 0;
    
    while($line)
    {
    	$line = <input>;
    	@text[$i] = $line;
    	@words = split(' ',@text[$i]);
    	print "$i";
    	for($i = 0 ; $i < scalar(@words) ; $i++)
    	{
    		$wordCount++;
    		print "$i";
    	}
    	print $wordCount;
    	$i++;
    }
    
    
    select(output);
    print "There are $wordCount words in input.txt";
    
    
    
    
    
    #close files
    Last edited by WingedPanther; 02-17-2009 at 08:27 AM. Reason: add code tags (the # button)

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,486
    Blog Entries
    75
    Rep Power
    143

    Re: Help please!

    what output are you getting?
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    KevinADC is offline Programmer
    Join Date
    Jan 2007
    Posts
    125
    Rep Power
    0

    Re: Help please!

    Your code displays a near complete lack of understanding of how to write a program to solve the requirements. Its not even close. You can google for:

    perl count words

    and find many solutions to this class/course assignment

  5. #4
    Join Date
    May 2008
    Posts
    27
    Rep Power
    0

    Re: Help please!

    Perl File Handling: open, read, write and close files

    Won't tell you how to do it, but should point you in the right direction in terms of reading from files.
    Programming is an art form. Everyone can program, but few can do it right.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts