perl to php translation

This is a discussion on perl to php translation within the alt.comp.lang.php forums, part of the PHP Programming Forums category; could someone traslate this small piece of perl code to php ? many thanks Jor while ( -f <counter.lock> ) { ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-01-2006
jor
 
Posts: n/a
Default perl to php translation

could someone traslate this small piece of perl code to php ?
many thanks
Jor

while ( -f <counter.lock> ) {
select ( undef, undef, undef, 0.3 );
}

open ( LOCKFILE, ">counter.lock" );
open (CD, "$count");
$counter = <CD>;
close (CD);

Reply With Quote
  #2 (permalink)  
Old 12-01-2006
Ric
 
Posts: n/a
Default Re: perl to php translation

jor schrieb:
> could someone traslate this small piece of perl code to php ?
> many thanks
> Jor
>
> while ( -f <counter.lock> ) {
> select ( undef, undef, undef, 0.3 );
> }
>
> open ( LOCKFILE, ">counter.lock" );
> open (CD, "$count");
> $counter = <CD>;
> close (CD);
>


$fp = fopen("counter.lock", 'r');
while (!feof($fp)){
select ( undef, undef, undef, 0.3 );
}
fclose($fp);

$fp = fopen("counter.lock", 'w');

$fp = fopen($count, 'r');
$counter = fgets($fp));
fclose($fp);


-Ric
Reply With Quote
  #3 (permalink)  
Old 12-02-2006
Koncept
 
Posts: n/a
Default Re: perl to php translation

In article <ekpvs1$nre$1@online.de>, Ric <antispam@randometry.com>
wrote:

> > could someone traslate this small piece of perl code to php ?
> > many thanks
> > Jor
> >
> > select ( undef, undef, undef, 0.3 );


There is no *select* function in PHP. If you wanted to duplicate this
could, you would have to write a function to handle it. Something that
would handle the vars detailed in perldoc -f select

($nfound, $timeleft ) = select($rout=$rin,
$wout=$win,$eout=$ein,$timeout);

> > open ( LOCKFILE, ">counter.lock" );


To handle a locked file, you can use *flock*
$fp = fopen('counter.lock','w');
if(flock($fp,LOCK_EX)){ // lock the file
// do stuff here
flock($fp, LOCK_UN); // release lock
}

> > $counter = <CD>;

If you want to read an entire file handle into a scalar, you can use
file_get_contents or the way Ric laid things out.

// Not sure what your $count var references but you do...
$counter = file_get_contents( "$count" );

--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
Reply With Quote
  #4 (permalink)  
Old 12-02-2006
jor
 
Posts: n/a
Default Re: perl to php translation

Koncept wrote:
> In article <ekpvs1$nre$1@online.de>, Ric <antispam@randometry.com>
> wrote:
>
> > > could someone traslate this small piece of perl code to php ?
> > > many thanks
> > > Jor
> > >
> > > select ( undef, undef, undef, 0.3 );

>
> There is no *select* function in PHP. If you wanted to duplicate this
> could, you would have to write a function to handle it. Something that
> would handle the vars detailed in perldoc -f select
>
> ($nfound, $timeleft ) = select($rout=$rin,
> $wout=$win,$eout=$ein,$timeout);
>
> > > open ( LOCKFILE, ">counter.lock" );

>
> To handle a locked file, you can use *flock*
> $fp = fopen('counter.lock','w');
> if(flock($fp,LOCK_EX)){ // lock the file
> // do stuff here
> flock($fp, LOCK_UN); // release lock
> }
>
> > > $counter = <CD>;

> If you want to read an entire file handle into a scalar, you can use
> file_get_contents or the way Ric laid things out.
>
> // Not sure what your $count var references but you do...
> $counter = file_get_contents( "$count" );
>
> --
> Koncept <<
> "The snake that cannot shed its skin perishes. So do the spirits who are
> prevented from changing their opinions; they cease to be a spirit." -Nietzsche



Many thanks both for the quick response!

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:46 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0