FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » query: how many use PHP for linux scripts
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: query: how many use PHP for linux scripts [message #185958 is a reply to message #185954] Thu, 15 May 2014 15:26 Go to previous messageGo to previous message
Ben Bacarisse is currently offline  Ben Bacarisse
Messages: 82
Registered: November 2013
Karma:
Member
Jasen Betts <jasen(at)xnet(dot)co(dot)nz> writes:

> On 2014-05-14, Ben Bacarisse <ben(dot)usenet(at)bsb(dot)me(dot)uk> wrote:
>> The Natural Philosopher <tnp(at)invalid(dot)invalid> writes:
>>
>>> On 13/05/14 21:35, Tim Streater wrote:
>> <snip>
>>>> I can't be arsed to fiddle around with C these days. Too much faffing
>>>> around with declarations - and no string handling to speak of either.
>>>>
>>>> Non-issues in PHP.
>>>>
>>> string handling is the chief reason I prefer C..
>>
>> That seems odd since PHP has almost every single low-level C string
>> function available to it. You can strspn and strncmp to your heart's
>> content in PHP. Pretty much the only ones missing are strcat and strcpy
>> but, surely, they can't be why you prefer C.
>>
>> A PHP translation of C string handling would inevitably be simpler since
>> there would be no need manage the storage. That's the biggest advantage
>> in my opinion, even if never used any of PHP's more complex string
>> manipulation.
>
> white program the reads a text file and swaps every pair of lines and writes
> a new file.

I'd go:

function write_line($fin, $fout)
{
while (($c = fgetc($fin)) !== false && fputs($fout, $c) && $c != "\n");
return $c !== false;
}

function skip_line($fin, $fout)
{
while (($c = fgetc($fin)) !== false && $c != "\n");
return $c !== false;
}

function write_swapped_pair($fin, $fout)
{
$here = ftell($fin);
skip_line($fin, $fout);
if (write_line($fin, $fout))
return fseek($fin, $here) == 0 &&
write_line($fin, $fout) &&
skip_line($fin, $fout);
else return false;
}

function write_swapped_lines($fin, $fout)
{
while (write_swapped_pair($fin, $fout));
}

the behaviour with an odd number of lines, and when then last line is
not properly terminated, was not given so I took the easiest option!

This is not much more than a translation of what I'd do in C, which in a
way was my point.

The main difference is exchanging the test for EOF to false which takes
a little care (!== rather than !=), but then testing for EOF in C takes
case (you must use the right type variable). I don't think this is a
counter-example, but it's possible I missed the point your were making.

--
Ben.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to get the POST name of a field in a form that uses a counter
Next Topic: PHP-SOAP/5.4.21 SoapClient terminating POST without waiting for reply, but still complaining "error fetching http headers".
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 06:53:58 GMT 2024

Total time taken to generate the page: 0.04639 seconds