View Full Version : Advanced Perl Functions : ?
Dave987
06-10-2004, 09:16 AM
'lo all, I'm interested in learning about the advanced perl functions ? The only ones I know of are int() and rand() , and I have no idea at all how to use them.
If anyone would kindly write a mini-HowTo underneath , or even PM me , I'd be very greatful. Thanks alot everyone!
Once I learn these, my EQEmu Perl knowledge will be complete! Mwahaha! :twisted:
Thanks all.
Derision
06-10-2004, 09:36 AM
I'm not a Perl guru myself, but if you don't get a reply here, going to www.google.com and searching for perl int, or perl rand, will educate you in those functions if you invest a few minutes clicking on the returned results.
Dave987
06-10-2004, 09:39 AM
That true Derision but 2 points.
a) I didn't really want a flame as such..
b) It's easier if someone actually replies who does use them, that way , if you don't understand something, you can ask. Google'd sites often speak in loads of Gibberish , and you often have to go into lots of Sub-Folders in Sub-Folders in Sub-Folders through a Folder Tree only to find out your at the wrong thing and need to start over.
Basically, I was just looking for a simple answer, which wouldn't waste my time.
Thanks anyway.
Edit: After a quick google search, the rand() and int() are not even usefully explained for EQEmu. Thats why I posted : So I could get code snippets and learn from those. Perl is used in other things, not just EQEmu , and the int's and rand's are not used in code snippets for EQEmu.
Derision
06-10-2004, 09:45 AM
My reply wasn't meant as a flame, just as a suggestion if you didn't get any other replies to your thread, since when I searched with those terms on google, I got links that explained to me how those functions work.
I apologize if my reply to your post came across as a flame and assure you I won't post on your threads again.
Dave987
06-10-2004, 09:50 AM
I won't post on your threads again.
I'm not saying don't post - Please do! I just read it as a flame because it was so short and .. well, things can be mis-read on the internet right? :wink:
You say you found code examples on how to use these ? I'd appreciate it if you would link a site please? All I could find was people being super hi-tech and using rand() for webservers and things ... however, if you have found a clear to use code snippet that could almost be left unchanged for EQEmu , I would be very thankful for the link.
Sorry once again, I spose we should start putting accents into our Posts. :wink:
Thanks
Derision
06-10-2004, 09:53 AM
Well, this link seems to be a helpful with regard to rand:
http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch02_08.htm
and this one for int:
http://iis1.cps.unizar.es/Oreilly/perl/prog/ch03_076.htm
Dave987
06-10-2004, 09:58 AM
Thanks for your help Derision. You say your not a Perl guru yourself so:
Could anyone check this one please?
The Code snippet says $random = int( rand( $Y-$X+1 ) ) + $X;
Does this mean:
{
quest::summonitem($random =int(rand( 1001-1009)))
}
would summon any item between 1001 and 1009 ?
See Derision ? That's why I asked for Code snippets - I'm 90% sure thats completely wrong, though I thank you for trying to help.
It's appreciated. :)
Scorpious2k
06-10-2004, 10:16 AM
quest::summonitem($random =int(rand( 1001-1009)))
How about
{
$random=int(rand(9)+1001);
quest::summonitem($random);
}
or
{
quest::summonitem(int(rand(9)+1001));
}
Dave987
06-10-2004, 10:22 AM
Exactly what I was looking for!
Thanks alot Scorp, this will help alot ;)
Is there a way to make it so only certain random items are summoned?
Say I wanted to randomly summon either item 120 , 150 or 564 , would that be possible? At a guess, it would look like this..
nope .. I have no idea - is it possible?
Thanks ALOT scorp :D
x-scythe
06-10-2004, 10:24 AM
so if i wanted three items that werent continuous in there ID# like 1506, 1670, and 3004 for example it would be like:
{
$random=int(rand 1506+1607+3004);
quest::summonitem($random);
}
edit: lol must have replied at the same time as you dave.
Dave987
06-10-2004, 10:27 AM
Exactly 2 minutes after me :P
This will help our server alot, Thanks again Scorp and Derision,
it's Greatly Appreciated!
/perl master on :twisted:
"No-one can stop me, No-one!!"
m0oni9
06-10-2004, 12:24 PM
BTW, for looking up perl functions, I usually use http://www.perldoc.com/perl5.6/pod/perlfunc.html. If you want to get non-contiguous values, you're probably best off putting them all into an array, and then choosing an array index at random.
edit: See if this works for you..
sub getrand
{
return $_[rand @_];
}
$x = getrand (1002, 3023, 91982);
print "item is $x\n";
x-scythe
06-10-2004, 02:48 PM
thanks for the info. when i tried your link tho it led me to a dead end
edit: n/m there was just a period added to the end. got it working once i took the period out of the link
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.