Google Answers Logo
View Question
 
Q: Help with a Perl script ( No Answer,   3 Comments )
Question  
Subject: Help with a Perl script
Category: Computers
Asked by: mickr-ga
List Price: $10.00
Posted: 10 Aug 2006 03:46 PDT
Expires: 09 Sep 2006 03:46 PDT
Question ID: 754616
Hi,

I have a script 

open(FILE, "<$ARGV[$#ARGV - 1]");
open(OUTFILE, ">$ARGV[$#ARGV]");

while (<FILE>)
{
  $endarg = $#ARGV - 2;
  
	if (/^[ ]*name $ARGV[0] / ... /^[ ]*endname/ ) {
	} else {
		print OUTFILE $_;
	}
		
		
}



which prints out the contents of a file but skips the bits between 

name <persons name>
...
endname

where persons name is the first argument from the command line so i run this like

script.pl smith infile outfile

what I would like is to do an arbitary number of names at the same time

script.pl smith brown infile outfile

so $ARGV[0] would need to be something like $ARGV[0] ... $ARGV[$#ARGV - 1]

Regards,

Mick

Clarification of Question by mickr-ga on 11 Aug 2006 00:30 PDT
Thanks very much! Got it to work!
Answer  
There is no answer at this time.

Comments  
Subject: Re: Help with a Perl script
From: bozo99-ga on 10 Aug 2006 16:48 PDT
 
Add a state variable that indicates whether you are printing or not
printing and you can set this variable to "not printing" in a loop
that tests all the names.
Subject: Re: Help with a Perl script
From: haripatti-ga on 23 Aug 2006 22:27 PDT
 
how about this

$search_string = join("|", $ARGV[0]..$ARGV[$#ARGV - 2]);

	if (/^[ ]*name ($search_string) / ... /^[ ]*endname/ ) {
	} else {
		print OUTFILE $_;
	}
Subject: Re: Help with a Perl script
From: mickr-ga on 24 Aug 2006 03:21 PDT
 
Great got it to work using 

$search_string = join("|", @ARGV[0 .. $#ARGV - 2]);

thanks very much!

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy