> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, August 09, 2005 10:39 AM
> To: beginners@perl.org
> Subject: Seeding variables from command line
> 
> Sorry to bother everyone, but i was working on this yesterday and i
> couldn't get it to work.  I guess i have the wrong syntax for passing
> variables in from the command line.
> 
> Here's my script:
> 
> ===== crypt.pl =====
> #!/usr/bin/perl
> my $pwd = $1;
> my $seed = $2;
> my $key = substr(crypt("$pwd","$seed"),2);
> print $key;
> =================

This is my first attempt at helping out (newbie myself) but I figure
I'll learn more if I can help provide answers.  Here goes...

First, this is Perl, not a shell; Perl uses @ARGV for command line
arguments.  $1 and $2 are not instantiated with the values of your
arguments.

Very simply, you could write the following:

#!/usr/bin/perl

use warnings;
use strict;

my $pwd = $ARGV[0];
my $seed = $ARGV[1];
my $key = substr(crypt("$pwd","$seed"),2);
print "$key\n";

I'd suggest checking the number of elements in @ARGV first, though, to
be sure you have the proper number of arguments.

ry


> 
> For example, I want to type:
> 
>          crypt.pl  string1 string2
> 
>  and it should spit out the value of $key.
> 
> Right now both variables are returning null.  Any suggestions?



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to