Results 1 to 2 of 2

Thread: Perl script help "next;"

  1. #1
    Join Date
    Sep 2006
    Posts
    108

    Perl script help "next;"

    Can someone Please help me with this stupid script! AAHHHH!
    The script counts the words either typed by the user or counts the words in a file.
    ok, I am trying to learn PERL and this is one of the scripts our instructor gave us to figure out. I am trying really hard but I am stuck in parts like the "next;"
    I know next is suppose to just direct you to the next iteration but I that would be the for control structure and I can't make sence of it like that or any way for that matter but it works and there is nothing wrong with it. I just need more understanding of it.

    The course I am taking is online and the help is limited, so I would really really appreciate it if someone could point me in the right direction with this script.

    #!/usr/bin/perl

    $wordcount = 0;


    while (defined($line = <>))
    {
    chomp($line);
    for ($position = 0;
    $position < length($line) && $position != -1;
    $position = $newposition)
    {
    if (substr($line, $position, 1) eq " ")
    {
    $newposition = $position + 1;
    next;
    }

    $wordcount++;
    $newposition = index($line, " ", $position);
    }
    }

    print("$wordcount words counted in the file\n");



    Thankyou elli
    Last edited by elli; 09 Dec 2006 at 12:25 AM.

  2. #2
    Join Date
    Sep 2006
    Posts
    108
    Quote Originally Posted by elli
    Can someone Please help me with this stupid script! AAHHHH!
    The script counts the words either typed by the user or counts the words in a file.
    ok, I am trying to learn PERL and this is one of the scripts our instructor gave us to figure out. I am trying really hard but I am stuck in parts like the "next;"
    I know next is suppose to just direct you to the next iteration but I that would be the for control structure and I can't make sence of it like that or any way for that matter but it works and there is nothing wrong with it. I just need more understanding of it.

    The course I am taking is online and the help is limited, so I would really really appreciate it if someone could point me in the right direction with this script.

    #!/usr/bin/perl

    $wordcount = 0;


    while (defined($line = <>))
    {
    chomp($line);
    for ($position = 0;
    $position < length($line) && $position != -1;
    $position = $newposition)
    {
    if (substr($line, $position, 1) eq " ")
    {
    $newposition = $position + 1;
    next;
    }

    $wordcount++;
    $newposition = index($line, " ", $position);
    }
    }

    print("$wordcount words counted in the file\n");



    Thankyou elli

    I finally figured it out, so I don't need help anymore. Thanks elli

Similar Threads

  1. mail script in perl instead of using sendmail
    By dzigner in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 09 Mar 2006, 06:41 PM

Posting Permissions

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