Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I can't use EGREP 1

Status
Not open for further replies.

viadisky

Technical User
Jun 19, 2003
110
GB
Hi,

I'm currently running this version of Perl in my MS Windows XP machine.

[blue]This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 33 registered patches, see perl -V for more detail)

Copyright 1987-2006, Larry Wall

Binary build 819 [267479] provided by ActiveState Built Aug 29 2006 12:42:41[/blue]

Why can't I use egrep? I'm seeing this error if I change grep to egrep in my script:

[red]Undefined subroutine &main::egrep called at code3.pl line 5, <FILE> line 4.[/red]

Code:
D:\PERL\Sample Perl Scripts\CODE>type code3.pl
#!C:\Perl\bin\perl.exe

open (FILE, '<file.txt')or die "$!\n";

@result = egrep (/\"apple\"/i, <FILE>);
print @result;

close (FILE);

Regards
viadisky
 
vladisky

Don't confuse Perl's grep function with the system command grep. In shell scripting, you normally invoke these kinds of commands all the time. In Perl, although it is possible to 'shell out' to other commands, normally you don't need to.

In this case, Perl's regular expression engine will do all the same 'extended' things that egrep provides.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Thanks for all the information :)

I'm currently learning REGEX using and most of the examples in the book I'm using have [blue]egrep[/blue]. I'm using the code I posted earlier to simulate examples in the book. Thank you again.

Regards
viadisky

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top