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 ?
thx's and happy holidays,
Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
http://www.thunder-rain.com/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
http://www.shlomifish.org/humour/ways_to_do_it.html
Bzr is slower than Subversion in combination with Sourceforge.
( By: http://dazjorz.com/ )
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/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Hi Mike!
> ----- Original Message -----
> From: "Shlomi Fish" <shl...@iglu.org.il>
> To: <begi...@perl.org>; "Mike Blezien" <mic...@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 ?
> >
[Snipping the code -see the message above for it.]
> > 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
You're welcome.
>
> :)
>
> Have a safe and great new year ... to all :)
>
Thanks, and likewise.
Regards,
Shlomi Fish
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Parody on "The Fountainhead" - http://shlom.in/towtf