[32899] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4177 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 21 09:09:31 2014

Date: Fri, 21 Mar 2014 06:09:03 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 21 Mar 2014     Volume: 11 Number: 4177

Today's topics:
        _ check <gravitalsun@hotmail.foo>
    Re: _ check <jurgenex@hotmail.com>
    Re: _ check <gravitalsun@hotmail.foo>
    Re: _ check <rweikusat@mobileactivedefense.com>
    Re: Removing lines containing same first string boundar <derykus@gmail.com>
    Re: Removing lines containing same first string boundar <rweikusat@mobileactivedefense.com>
    Re: Removing lines containing same first string boundar <john@castleamber.com>
    Re: Removing lines containing same first string boundar <m@rtij.nl.invlalid>
    Re: Removing lines containing same first string boundar <m@rtij.nl.invlalid>
    Re: Removing lines containing same first string boundar <kaz@kylheku.com>
    Re: Removing lines containing same first string boundar <rweikusat@mobileactivedefense.com>
    Re: Removing lines containing same first string boundar <kaz@kylheku.com>
    Re: Running a script as if it were a Windows executable <me@xenu.tk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 20 Mar 2014 22:43:43 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: _ check
Message-Id: <lgfju1$20u3$1@news.ntua.gr>

first I check if a file exists ( -f $file ) and then doing several tests 
using the _ for being fast.

I have serious problem because the _ checks e.g -z _ sometimes is giving 
wrong results. the code is multi thread . What is going wrong ?


------------------------------

Date: Thu, 20 Mar 2014 14:12:17 -0700
From: Jrgen Exner <jurgenex@hotmail.com>
Subject: Re: _ check
Message-Id: <dbmmi99t5fftt6iigeen7as3049c64aniu@4ax.com>

George Mpouras <gravitalsun@hotmail.foo> wrote:
>first I check if a file exists ( -f $file ) and then doing several tests 
>using the _ for being fast.
>
>I have serious problem because the _ checks e.g -z _ sometimes is giving 
>wrong results. the code is multi thread . What is going wrong ?
                            ^^^^^^^^^^^^

Are you sure you are not running into race conditions?

jue


------------------------------

Date: Thu, 20 Mar 2014 23:21:06 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: _ check
Message-Id: <lgfm45$25uj$1@news.ntua.gr>

Στις 20/3/2014 23:12, ο/η Jürgen Exner έγραψε:
> George Mpouras <gravitalsun@hotmail.foo> wrote:
>> first I check if a file exists ( -f $file ) and then doing several tests
>> using the _ for being fast.
>>
>> I have serious problem because the _ checks e.g -z _ sometimes is giving
>> wrong results. the code is multi thread . What is going wrong ?
>                              ^^^^^^^^^^^^
>
> Are you sure you are not running into race conditions?
>
> jue
>

do not know, I am bunging my head with this. It is an apache mod perl. 
Maybe it have to do with apache cache.
I do not know if _ is saying always the truth. I mean if between the -f 
and _ an other thread ask for -f what will happen


------------------------------

Date: Thu, 20 Mar 2014 21:36:18 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: _ check
Message-Id: <87txaswo19.fsf@sable.mobileactivedefense.com>

George Mpouras <gravitalsun@hotmail.foo> writes:
> Στις 20/3/2014 23:12, ο/η Jürgen Exner έγραψε:
>> George Mpouras <gravitalsun@hotmail.foo> wrote:
>>> first I check if a file exists ( -f $file ) and then doing several tests
>>> using the _ for being fast.
>>>
>>> I have serious problem because the _ checks e.g -z _ sometimes is giving
>>> wrong results. the code is multi thread . What is going wrong ?
>>                              ^^^^^^^^^^^^
>>
>> Are you sure you are not running into race conditions?
>>
>> jue
>>
>
> do not know, I am bunging my head with this. It is an apache mod
> perl. Maybe it have to do with apache cache.
> I do not know if _ is saying always the truth. I mean if between the
> -f 
> and _ an other thread ask for -f what will happen

As a somewhat simplified statement: Perl doesn't really support
multi-threading, all it can do is have multiple perl processes (::=
interpreters) run in a shared address space (thus, elegantly combining
all disadvantages of either model with each other in order to provide
none of the advantages). For your case, this means that each thread has
its own 'stat buffer'.

What do you mean by "-z _ sometimes is giving wrong results"? All uses
of stat are prone to TOCTOU-races, meaning, -z file being true by the
time the test was made doesn't even imply that it's still true by the
time your code sees the result.



------------------------------

Date: Wed, 19 Mar 2014 06:53:14 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: Removing lines containing same first string boundaries?
Message-Id: <94fc0e4d-b57a-461d-b80d-ccd81863c3b8@googlegroups.com>

On Wednesday, March 19, 2014 12:21:22 AM UTC-7, Martijn Lievaart wrote:
> On Tue, 18 Mar 2014 20:46:00 +0000, Rainer Weikusat wrote:
> 
> 
> 
> > Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> 
> >> Kaz Kylheku <kaz@kylheku.com> writes:
> 
> >>
> 
> >>> On 2014-03-17, Tuxedo <tuxedo@mailinator.com> wrote:

 ... 
> >> There are one-line Perl versions as well of course.  Maybe
> 
> >>   perl -ane '$seen{$F[0]} = print unless $seen{$F[0]}'

> > That's a neat idea. Obvious extension of that:
> 
> > perl -ane '$seen{$F[0]} //= print'
>  
> As someone already said, %seen is boring.
> 
> perl -ane '$_{$F[0]} //= print'
>

Golfers would whine about an extra stroke:

perl -lanE '$_{$F[0]} //= say'

-- 
Charles DeRykus


------------------------------

Date: Wed, 19 Mar 2014 13:55:25 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Removing lines containing same first string boundaries?
Message-Id: <87siqee1iq.fsf@sable.mobileactivedefense.com>

Martijn Lievaart <m@rtij.nl.invlalid> writes:
> On Tue, 18 Mar 2014 20:46:00 +0000, Rainer Weikusat wrote:
>
>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>> Kaz Kylheku <kaz@kylheku.com> writes:
>>>
>>>> On 2014-03-17, Tuxedo <tuxedo@mailinator.com> wrote:
>>>>> I have a plain text file with each line in the format:
>>>>>
>>>>> Start of line followed immediately by a string of character(s), a
>>>>> whitespace, another string, a newline.
>>>>>
>>>>> -------- file.txt -------
>>>>>
>>>>> SOMESTRING XXX SOMESTRING ZZZ SOMEOTHERSTRING YYYZZ23 DIFFERENTSTRING
>>>>> HELLO

[...]

>> perl -ane '$seen{$F[0]} //= print'
>
> As someone already said, %seen is boring.
>
> perl -ane '$_{$F[0]} //= print'

At the expense of some 'loss in generality' (aka 'risk of causing weird
effects in case of name collisions with Perl special variables'), the
symbol table already provides a perfectly usable hash:

perl -ane '${$F[0]} //= print'


------------------------------

Date: Wed, 19 Mar 2014 10:47:25 -0600
From: John Bokma <john@castleamber.com>
Subject: Re: Removing lines containing same first string boundaries?
Message-Id: <87bnx2t9sy.fsf@castleamber.com>

Martijn Lievaart <m@rtij.nl.invlalid> writes:

> On Tue, 18 Mar 2014 15:36:40 +0000, Rainer Weikusat wrote:
>
>> 	This is similar to the rotating hash, but it actually mixes the
>> 	internal state. It takes 9n+9 instructions and produces a full 4-
> byte
>> 	result. Preliminary analysis suggests there are no funnels.
>> 
>> 	This hash was not in the original Dr. Dobb's article. I 
> implemented it
>> 	to fill a set of requirements posed by Colin Plumb. Colin ended up
>> 	using an even simpler (and weaker) hash that was sufficient for 
> his
>> 	purpose.
>>         
>>         http://burtleburtle.net/bob/hash/doobs.html
>
> Interesting read. Thx.

Indeed, thanks.

-- 
John Bokma                                                               j3b

Blog: http://johnbokma.com/        Perl Consultancy: http://castleamber.com/
Perl for books:    http://johnbokma.com/perl/help-in-exchange-for-books.html


------------------------------

Date: Wed, 19 Mar 2014 17:49:44 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Removing lines containing same first string boundaries?
Message-Id: <8euova-kmp.ln1@news.rtij.nl>

On Wed, 19 Mar 2014 13:55:25 +0000, Rainer Weikusat wrote:

> Martijn Lievaart <m@rtij.nl.invlalid> writes:

>> As someone already said, %seen is boring.
>>
>> perl -ane '$_{$F[0]} //= print'
> 
> At the expense of some 'loss in generality' (aka 'risk of causing weird
> effects in case of name collisions with Perl special variables'), the
> symbol table already provides a perfectly usable hash:
> 
> perl -ane '${$F[0]} //= print'

Great find. I love it.

M4


------------------------------

Date: Wed, 19 Mar 2014 17:56:38 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Removing lines containing same first string boundaries?
Message-Id: <6ruova-kmp.ln1@news.rtij.nl>

On Wed, 19 Mar 2014 06:53:14 -0700, C.DeRykus wrote:

> On Wednesday, March 19, 2014 12:21:22 AM UTC-7, Martijn Lievaart wrote:
>> On Tue, 18 Mar 2014 20:46:00 +0000, Rainer Weikusat wrote:
>> 
>> 
>> 
>> > Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>> 
>> >> Kaz Kylheku <kaz@kylheku.com> writes:
>> 
>> 
>> >>
>> >>> On 2014-03-17, Tuxedo <tuxedo@mailinator.com> wrote:
> 
> ...
>> >> There are one-line Perl versions as well of course.  Maybe
>> 
>> >>   perl -ane '$seen{$F[0]} = print unless $seen{$F[0]}'
> 
>> > That's a neat idea. Obvious extension of that:
>> 
>> > perl -ane '$seen{$F[0]} //= print'
>>  
>> As someone already said, %seen is boring.
>> 
>> perl -ane '$_{$F[0]} //= print'
>>
>>
> Golfers would whine about an extra stroke:
> 
> perl -lanE '$_{$F[0]} //= say'

We're getting there, combining with Rainers suggestion and removing 
whitespace, we get

perl -lanE '${$F[0]}//=say'

I doubt that can be shortened any further.

M4


------------------------------

Date: Wed, 19 Mar 2014 17:51:31 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: Removing lines containing same first string boundaries?
Message-Id: <20140319102447.423@kylheku.com>

On 2014-03-19, Martijn Lievaart <m@rtij.nl.invlalid> wrote:
> We're getting there, combining with Rainers suggestion and removing
> whitespace, we get
>
> perl -lanE '${$F[0]}//=say'
>
> I doubt that can be shortened any further.

Note that this symbol table hack has obvious flaws: namely that you don't own
the symbol space, and that space has content already:

Here is an obvious failing test case for the perl:

$ perl -lanE '${$F[0]}//=say'
_ foo
[Ctrl-D]

Some other nonworking test cases:

( foo
? foo
$ foo

The output is blank instead of the expected _ foo. The fix is to properly
namespace the keys so that they don't clash with existing symbols; but the
broken solution is already over par for the course as it is:

  perl -lanE '${$F[0]}//=say'

  awk '{if(!s[$1]++)print;}'

Also, this is almost normal, everyday awk, representing how that tool is
typically used: all that is lacking is whitespace and a meaningful name for the
hash instead of s.


------------------------------

Date: Wed, 19 Mar 2014 18:15:52 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Removing lines containing same first string boundaries?
Message-Id: <87txaucaw7.fsf@sable.mobileactivedefense.com>

Kaz Kylheku <kaz@kylheku.com> writes:
> On 2014-03-19, Martijn Lievaart <m@rtij.nl.invlalid> wrote:
>> We're getting there, combining with Rainers suggestion and removing
>> whitespace, we get
>>
>> perl -lanE '${$F[0]}//=say'
>>
>> I doubt that can be shortened any further.
>
> Note that this symbol table hack has obvious flaws: namely that you don't own
> the symbol space, and that space has content already:

	"At the expense of some 'loss in generality' (aka 'risk of
	causing weird effects in case of name collisions with Perl
	special variables'),"

A more interesting test case would be

\ bla

(when using print instead of say).

[...]

> the
> broken solution is already over par for the course as it is:
>
>   perl -lanE '${$F[0]}//=say'
>
>   awk '{if(!s[$1]++)print;}'
>
> Also, this is almost normal, everyday awk, representing how that tool is
> typically used:

awk '!s[$1]--'

(tested with gawk)

But this is sort of off topic in a Perl news group. Also,

$_{$F[0]}//=print	# [*]

is really a nicer algorithm because it doesn't do anything if the test
succeeds.

[*] I don't particularly like the idea of using a special command-line
option telling perl to strip newlines on input just because this means
that a builtin which unconditionally adds a newlines can be used.



------------------------------

Date: Thu, 20 Mar 2014 05:22:59 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: Removing lines containing same first string boundaries?
Message-Id: <20140319222127.857@kylheku.com>

On 2014-03-19, Rainer Weikusat <rweikusat@mobileactivedefense.com> wrote:
> awk '!s[$1]--'

We have a winner! :)

How easy to forget that a lone expression means "print $0 if I am true".


------------------------------

Date: Thu, 20 Mar 2014 00:11:48 +0100
From: Tomasz Konojacki <me@xenu.tk>
Subject: Re: Running a script as if it were a Windows executable?
Message-Id: <lgd5hk$kl$1@news.icm.edu.pl>

Hi!

There is simple tool included with both ActivePerl and Strawberry Perl, 
it's called pl2bat.

Cheers,
Tomasz

Użytkownik Alek Trishan napisał:
> I have a perl script that I can run by opening a command window and typing
>      perl.exe myscript.pl
>
> I would like to create an "executable" file (but not a desktop shortcut)
> that, when clicked on, would execute that command.
>
> Can anyone help?
>
> Thanks.



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 4177
***************************************


home help back first fref pref prev next nref lref last post