Hi Shlomi,
----- Original Message -----
From: "Shlomi Fish" <shlo...@iglu.org.il>
To: <beginners@perl.org>; "Mike Blezien" <mick...@frontiernet.net>
Sent: Sunday, December 27, 2009 7:38 AM
Subject: Re: Convert PHP functions to Perl
On Sunday 27 Dec 2009 15:12:24 Mike Blezien wrote:
Hello,
Hi Mike!
I'm working on converting some PHP coding to a Perl system. come across a
couple of functions I'm not familiar with and was hoping we have some
experienced PHP programmer on the list that can help out. These are the
functions I need to switch over to Perl:
str_shuffle()
microtime()
What is the Perl equivalent to these functions ?
Here you go:
<<<<<<<<<<<<<<<<<<<<<<
#!/usr/bin/perl
# Implement PHP's str_shuffle() and microtime() in Perl 5.
# Written by Shlomi Fish ( http://www.shlomifish.org/ )
#
# Copyright by Shlomi Fish, 2009 and licensed under the MIT/X11 License (
# http://www.opensource.org/licenses/mit-license.php ).
#
# If you like this code, please consider contributing to either me:
# http://www.shlomifish.org/meta/how-to-help/ or the Perl Foundation:
# http://www.perlfoundation.org/ .
use strict;
use warnings;
use List::Util qw(shuffle);
# See
# http://php.net/manual/en/function.str-shuffle.php
sub str_shuffle
{
my $string = shift;
return join("", shuffle(split //, $string));
}
sub test_str_shuffle
{
my $string = shift;
print sprintf(qq{Shuffling of "%s" is "%s".\n},
$string, str_shuffle($string)
);
}
use Time::HiRes qw(gettimeofday);
# See:
# http://php.net/manual/en/function.microtime.php
sub microtime
{
my $get_as_float = shift;
my ($secs, $microsecs) = gettimeofday();
if ($get_as_float)
{
return $secs + ($microsecs * 1e-6);
}
else
{
return "$microsecs $secs";
}
}
sub test_microtime
{
my $get_as_float = shift;
print "Microtime(" .
($get_as_float ? "true" : "false") . ") = " .
microtime($get_as_float) . "\n"
;
}
test_str_shuffle("HelloWorld");
test_str_shuffle("This sentence is false.");
test_microtime(1);
test_microtime();
microtime() seems like it is badly designed and you may wish using
Time::HiRes's gettimeofday() directly.
thx's and happy holidays,
Happy holidays and a happy new year to you too.
Regards,
Shlomi Fish
Works prefectly! Thank you. Using the gettimeofday() directly does work better
:)
Have a safe and great new year ... to all :)
Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Custom Programming & Web Hosting Services
http://www.thunder-rain.com/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/