Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 5th, 2008, 8:01 PM   #1
crp763
Newbie
 
Join Date: Jun 2008
Posts: 1
Rep Power: 0 crp763 is on a distinguished road
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);
}
crp763 is offline   Reply With Quote
Old Jun 6th, 2008, 6:37 PM   #2
Mocker
Hobbyist Programmer
 
Mocker's Avatar
 
Join Date: Oct 2005
Location: Indiana
Posts: 216
Rep Power: 0 Mocker is an unknown quantity at this point
Send a message via AIM to Mocker
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.
__________________
#programmingforums relay - http://thegupstudio.com/cgi-bin/pforelay.cgi
freelance scripts - http://ryanguthrie.com/index.html
Mocker is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash or Perl? titaniumdecoy Other Scripting Languages 9 Jan 30th, 2006 4:42 PM
A simple perl script satimis Perl 3 Aug 15th, 2005 9:31 AM
Why do most shared hosting services offer php not perl? Jonnno Perl 5 May 19th, 2005 3:56 PM
Learning and Programming Perl G.I.Josh Perl 2 Mar 23rd, 2005 1:48 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:23 AM.

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