Home > Archive > PERL Miscellaneous > March 2004 > Perl: Generate registration code
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Perl: Generate registration code
|
|
|
| I am new to Perl. I want to write a Perl script that generates a
registration code on my website. It's basically a hex of the w of
the year and year, plus and multiplied by some number. I have a
sample of what I would like in VB. Can someone help convert this to
Perl. I'm hoping it's as simple as VB. Thanks for your help...
------- VB Code ------------
Sub RegCode()
Dim strCode as String
strCode = Hex(((DatePart("ww", Date) & Year(Date)) + 12345) * 12345)
Debug.Print strCode
End Sub
---------------------------
John
| |
| Richard Morse 2004-03-27, 12:01 am |
| In article <c2c15952.0403261030.bb12901@posting.google.com>,
john_1998@hotmail.com (John) wrote:
> I am new to Perl. I want to write a Perl script that generates a
> registration code on my website. It's basically a hex of the w of
> the year and year, plus and multiplied by some number. I have a
> sample of what I would like in VB. Can someone help convert this to
> Perl. I'm hoping it's as simple as VB. Thanks for your help...
>
> ------- VB Code ------------
> Sub RegCode()
> Dim strCode as String
> strCode = Hex(((DatePart("ww", Date) & Year(Date)) + 12345) * 12345)
> Debug.Print strCode
> End Sub
> ---------------------------
To get the date, look at the 'localtime' function. It doesn't supply a
w of the year, so if it absolutely must be based off of the w , you
might need to look at various date modules from CPAN (http://search.cpan.org).
When you say "hex of the ...", presumably you mean a hex string
representing the number that you generate. The sprintf function will do
this:
perl -e "print sprintf('%x', 24), qq{\n}"
returns:
18
HTH,
Ricky
| |
|
|
| Andrew Rodland 2004-03-27, 12:01 am |
| John wrote:
> I am new to Perl. I want to write a Perl script that generates a
> registration code on my website. It's basically a hex of the w of
> the year and year, plus and multiplied by some number. I have a
> sample of what I would like in VB. Can someone help convert this to
> Perl. I'm hoping it's as simple as VB. Thanks for your help...
>
> ------- VB Code ------------
> Sub RegCode()
> Dim strCode as String
> strCode = Hex(((DatePart("ww", Date) & Year(Date)) + 12345) * 12345)
> Debug.Print strCode
> End Sub
> ---------------------------
use Date::Format;
sub regcode {
print sprintf('%x', timetostr('%W%Y', time));
}
or so.
|
|
|
|
|