#!/usr/bin/perl use strict; my $counter=1; my $no='D000001'; my $name=''; #to save the name to be searched my $result; my $flag=0; ###checking the argument if($#ARGV==1){ print "First type of search\n"; print "input: $ARGV[0]\n"; print "output: $ARGV[1]\n"; $result=">".$ARGV[1]; #get file for output $flag=1; check(); } elsif($#ARGV==2){ $name=$ARGV[1]; print "Second type of search\n"; print "input: $ARGV[0]\n"; print "name : $name\n"; print "output: $ARGV[2]\n"; $result=">".$ARGV[2]; #get file for output $flag=2; check(); } else { print "Invalid number of argument\n";} sub check{ # Read an entire record at a time $/ = "//\n"; # each record separated by //\n open(OUT,"$result") or die "Can't open $result."; #open result for output while (<>){ # Read the entry print "$no\n"; if($flag==1){ ###print "$_"; if(/AGE\s*(\d*)/){ print OUT "RECORD NO\t$no\n"; print OUT "AGE\t$1\n";}} if ($flag==2){ search($name);} $no++; } close(OUT); } sub search{ print "search done\n"; ##do some searching and other things ##I didn't include the function ##since actually the code is very long, and it doesn't only do simple search } #### NAME Tom AGE 21 // NAME Janice AGE 34 // NAME Clarice Age 45 //