in reply to Re: Newbe needs script assistance
in thread Newbe needs script assistance

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.

Replies are listed 'Best First'.
Re^3: Newbe needs script assistance
by johngg (Canon) on Feb 17, 2011 at 00:02 UTC

    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

Re^3: Newbe needs script assistance
by Anonymous Monk on Feb 16, 2011 at 23:03 UTC