in reply to Newbe needs script assistance

Perhaps I reacted hastily. But the question does sound like a poorly-summarized version of a class assignment.

In an effort to be helpful rather than smug, here are a few suggestions:

You're most likely to get good help here if you post where you are with respect to the problem. Have you tried something? Do you have a plan of where to begin? Do you have at least a strategy of how you would accomplish the problem as a series of simple steps? Do you have any code written? The more you can give us, and the more specific you can be with respect to your hangups the better we can assist you. But you're not likely to get much help if the sum total of your effort on the project is simply posting a two sentence question here asking someone to do it for you.


Dave

Replies are listed 'Best First'.
Re^2: Newbe needs script assistance
by vader (Initiate) on Feb 16, 2011 at 22:31 UTC
    Yes a scholl Project, I am trying to understand what I am missing, and trying to find the correct methodology to help understand perl more. #!/usr/bin/perl # # # # # # ## { open (story8, "story8.txt") or die "can't open file"; while ($line = <story8>){ print $line;} if ($_ =~ /^(^\s+)(\s.*?)*\s\1$/) { print ("the line is $_ \n"); } } I have tried different ways but have a had time find the correct strings to get it to work. I have looked on google, but seem to run into good explanations, or something different is displayed _____________________________________________________________ This is also a combo class, I was not informed by my advisor when signing up, that this was broke into two parts, the first half 5 weeks we are to learn how to code using perl, and the second half is unix administration.

      I think you are trying to do something like show which lines have repeated words in them. The problem description in your original post is a little unclear and seemed to cover several requirements but your code hints at this solution. Given this input file:

      this and that fish and chips and mushy peas the cat and catkin boom bang boom

      This code:

      #!/usr/bin/perl # use strict; use warnings; my $inputFile = q{spw888564.txt}; open my $inputFH, q{<}, $inputFile or die qq{open: < $inputFile: $!\n}; while ( <$inputFH> ) { next unless m{(\w+).*\b\1\b}; print qq{Found '$1' repeated in: $_}; } close $inputFH or die qq{close: < $inputFile: $!\n};

      Produces this output:

      Found 'and' repeated in: fish and chips and mushy peas Found 'boom' repeated in: boom bang boom

      I hope I have guessed correctly and this is some help but please ask more questions if things are unclear.

      Cheers,

      JohnGG