Home > perl > Self-grepping text file (Perl Script)

Self-grepping text file (Perl Script)

This very simple Perl file greps the text which occurs after the __DATA__ marker
The perl code and the text can be edited at anytime by entering the parameter.
Having the script and text together makes it portable.
Adapt the script to your own requirements.

#!/usr/bin/perl
# Description : grep own text
# Version 1.1

if ($#ARGV >= 0){$keyw = $ARGV[0];}
else { print "enter keyword (or -v to edit):"; $keyw=; }
chomp $keyw;

if ($keyw=~/-v/i){system ("gvim $0"); exit;} # edit this file

@info=<DATA>; # read text into array

for $line (@info)
{
print grep /$keyw/i,$line;
}
__DATA__
Arts & Design Category
Art galleries & Museums

* International Galleries and Museums
* US Galleries and Museums
etc etc

Categories: perl Tags:
  1. No comments yet.
  1. No trackbacks yet.