Solved

Perl input question

Posted on 2002-07-26
6
148 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 5

Expert Comment

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

Expert Comment

by:ahoffmann
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

10 Experts available now in Live!

Get 1:1 Help Now