gdnew has asked for the wisdom of the Perl Monks concerning the following question:
Well,in my program I use while(<>) purposely to read other part of the module.
Here I include part of my working program.
This is part of my input files:#!/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 sim +ple search }
Thank you in advanced.NAME Tom AGE 21 // NAME Janice AGE 34 // NAME Clarice Age 45 //
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: about while() combine with ARGV
by japhy (Canon) on Feb 19, 2002 at 08:49 UTC | |
by thor (Priest) on Feb 19, 2002 at 12:45 UTC | |
by japhy (Canon) on Feb 19, 2002 at 14:00 UTC | |
by particle (Vicar) on Feb 19, 2002 at 14:44 UTC | |
by gdnew (Acolyte) on Feb 19, 2002 at 10:10 UTC |