Solved

Perl input question

Posted on 2002-07-26
6
150 Views
Last Modified: 2010-03-05
I am writing a perl script to do some file comparisons, but I would like it to take inputs similar to how korn does it....i.e.    script.sh input1 input2....
like a=$1   b=$2......

What is the easiest way to do this...

0
Comment
Question by:jkratzer
6 Comments
 
LVL 5

Accepted Solution

by:
BlackDiamond earned 50 total points
ID: 7181171
Here you go.  Pretty self explanatory I think, but let me know if you need more info.


#!/usr/bin/perl

print "You passed " . scalar(@ARGV) . " arguments\n";
print "The argument values are:\n\n";

foreach $arg (@ARGV) {
   print "$arg\n";
}
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7181235
probably not self explanatory (for everyone), but more perlish ;-)

#! /usr/bin/perl
$\="\n";
print "You passed ",$#ARGV+1," arguments";
grep(print,@ARGV);
0
 
LVL 84

Expert Comment

by:ozo
ID: 7181240
I would call that less perlish
More perlish might be:

#!/usr/bin/perl
$\="\n";
print "You passed ".@ARGV." arguments";
print "The argument values are:\n";
print for( @ARGV );
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 5

Expert Comment

by:BlackDiamond
ID: 7181451
Gotta love Perl.  Always 10 different ways to do everything, hehe.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7181777
perl slogan by Larry Wall: There's More Than One Way To Do It.
;-)

jkratzer, sorry for being off-topic
0
 
LVL 6

Author Comment

by:jkratzer
ID: 7184960
I figured it out about 1 hour after I posted.
I used......

open F,"<$ARGV[0]" or die "Can't open $ARGV[0] because $!";
$count{$_} |= 1 while <F> ;
open F,"<$ARGV[1]" or die "Can't open $ARGV[1] because $!";
$count{$_} |= 2 while <F> ;

Since BlackDiamond answered first I will give him the credit......Thanks for the help guys...


0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now