Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input

Status
Not open for further replies.

moof15

Programmer
Aug 22, 2002
23
0
0
US
Hi,

I just need a script to take 7 variables and put them in a array and print them out Example:
$DBName = "LS2DB001";
$Username = "LS2USER";
$Password = "LS2USER";
$filename = "convsql.txt";
$infilename = "convsql.sql";
$TSPATH = "C:\\loantemp\\";
$DB2HLQ = "LS2USER";
$LOBPATH = "C:\\Loantemp\\Lobpath\\";
$AUTLET = "";
$command_counter = 0;
$db2command = "db2 ";
$totalcommands = 0;
I need to put these in a array, then print them out..
Please help
Thnaks,
 
I'd say you'd be better off just using a hash like so:

Code:
my %hash = (
  DBName          => "LS2DB001",
  Username        => "LS2USER",
  Password        => "LS2USER",
  filename        => "convsql.txt",
  infilename      => "convsql.sql",
  TSPATH          => "C:\\loantemp\\",
  DB2HLQ          => "LS2USER",
  LOBPATH         => "C:\\Loantemp\\Lobpath\\",
  AUTLET          => "",
  command_counter => 0,
  db2command      => "db2 ",
  totalcommands   => 0,
  );

print "\$hash{$_}=$hash{$_}\n" foreach ( keys %hash );

Much easier. [wink] Notorious P.I.G.
 
the
Code:
@ARGV
variablecontains any perameters passed
to a function...

Code:
printVars(var1, var2, var3, ...);
or
Code:
Command Line: printvars.pl var1 var2 var3

sub printVars
{
   var1 = $ARGV[0];
   var2 = $ARGV[1];
# Etc...


Have Fun!

Thomas Smith
 
the @ARGV variablecontains any perameters passed
to a function...


This is not correct.
[tt]@ARGV[/tt] contains arguments passed to the script when it is invoked from the command line or another script.

[tt]@_[/tt] contains the arguments passed to a subroutine. So your code should look like
[tt]
sub printVars
{
$var1 = $_[0]; # $_[n] is the scalar form of @_
$var2 = $_[1]; # which is completely differen from $_
# Etc...
## Or
sub printVars
{
$var1 = shift @_;
$var2 = shift; # shift defaults to @_ inside a subroutine, to @ARGV in the main program
# Etc...
##Or even
sub printVars
{
my ($var1, $var2) = @_;
# Etc ...
[/tt]
As to the original question ... P.I.G.'s idea of using a hash is a very good one. Otherwise, to print out all your vars you have to do something ridiculous like
Code:
foreach $var ($DBName, $Username, $Password, $filename, 
              $infilename, $TSPATH, $DB2HLQ, $LOBPATH, 
              $AUTLET, $command_counter, $db2command, $totalcommands) 
{

    print "$var\n";
}

jaa
 
Thanks for the repy everyone,

moof15
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top