Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Perl (http://www.programmingforums.org/forum21.html)
-   -   Perl Noob, regex (http://www.programmingforums.org/showthread.php?t=15946)

crp763 Jun 5th, 2008 8:01 PM

Perl Noob, regex
 
I just started Perl and can't find very many in depth tutorials, so I am not quite sure what is wrong exactly with the following script, and I desperately want to learn in-depth regex. Any help?

:

$file = 'C:\\Documents and Settings\\*My Name Here*\\Desktop\\Code\\Programming\\PerlfileText.txt';
$continue = 'y';
while ($continue eq 'y')
{
    print 'Enter filename to search: ';
        $file = <>;
        chomp ($file)
        open (search, $file) || die("Could not open specified file\n");
        $text = <search>;
        if($text =~ /is.d/);
        {
            print '\nA match was found\n';
                close (search);
        }
        else
        {
            print "\nNo matching pattern\n";
                close (search);
        }
        print "Continue?(y\/n): ";
        $continue = <>;
        chomp ($continue);
}


Mocker Jun 6th, 2008 6:37 PM

Re: Perl Noob, regex
 
What are you trying to match, and what is your script showing?

I see a couple issues to note..

:

print '\nA match was found\n';
should be
:

print "\nA match was found\n";

also, the code $text = <search>; only reads the first line of the file.
If you want to look for a match on any line in the file, you have to put that in a loop to check each line.


All times are GMT -5. The time now is 12:39 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC