[32187] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3452 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 24 03:09:40 2011

Date: Sun, 24 Jul 2011 00:09:05 -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           Sun, 24 Jul 2011     Volume: 11 Number: 3452

Today's topics:
        Ownership of a file in unix file system spam_filter@invalid.nil
    Re: Ownership of a file in unix file system <whynot@pozharski.name>
    Re: Ownership of a file in unix file system <blmblm.myrealbox@gmail.com>
    Re: Ownership of a file in unix file system <vilain@NOspamcop.net>
    Re: Ownership of a file in unix file system <John.Smith@invalid.com>
    Re: Ownership of a file in unix file system <jurgenex@hotmail.com>
        stuck in regex <elliot@example.net>
    Re: stuck in regex <tadmc@seesig.invalid>
    Re: stuck in regex <jurgenex@hotmail.com>
    Re: stuck in regex <tadmc@seesig.invalid>
    Re: stuck in regex <jurgenex@hotmail.com>
    Re: stuck in regex <elliot@example.net>
    Re: stuck in regex <uri@StemSystems.com>
    Re: syntax query: ($var++ && next) if /match/ <derykus@gmail.com>
    Re: syntax query: ($var++ && next) if /match/ <blmblm.myrealbox@gmail.com>
    Re: syntax query: ($var++ && next) if /match/ <source@netcom.com>
        You shoot yourself in the foot. <snorkmeier._10c@gmail.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 23 Jul 2011 11:52:57 +0300
From: spam_filter@invalid.nil
Subject: Ownership of a file in unix file system
Message-Id: <862l27lkndps56truopihbm1b24b8g6ugn@4ax.com>

I need to create a file on a web server (running unix) and set its permission so
that no-one, except with correct ftp username & password can download or view it.
On my wwww server I've created test.pl. When I go to
www.notareal.com/cgi-bin/test.pl
Firefox shows "Hello world" as expected. When I use a FTP program the check if
newtext.tx has been created it's there OK.

The problem is that I cannot download the newtext.txt or view it. I can delete it
but that's just about it.


Here is a simple test.pl:

#!/usr/bin/perl
print "Content-Type: text/html; charset=iso-8859-1\n\n";
print '<html><BODY>';
open(TEKSTI,">newtext.txt");
print TEKSTI "just testing";
close(TEKSTI);
chmod 0600,"newtext.txt";       ## The problem line
print "Hello world</body> </HTML>";



If I leave out the problem line everything works but the file is set as 644 and
not 600. Can I leave it as 644? Can someone without user name and password still
access it from browsers or other program? 

I tried this on another www page and it worked there ok.


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

Date: Sat, 23 Jul 2011 14:03:26 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: Ownership of a file in unix file system
Message-Id: <slrnj2lak5.2kr.whynot@orphan.zombinet>

with <862l27lkndps56truopihbm1b24b8g6ugn@4ax.com> spam_filter@invalid.nil wrote:
*SKIP*
> The problem is that I cannot download the newtext.txt or view it. I
> can delete it but that's just about it.

(honestly, it's hard to grok wnat you want to say, so I left what makes
most sense to me)  Your subject is correct.  Have you tried to access
that file with browser?  I suppose you would succeede.  My understanding
is, that's not what you want either.  The problem is that your
www-server and ftp-server are running with different UIDs.  Permissions
are owner-group-others.  But the 'owner' here isn't you.  It's from
/etc/passwd.  If that's a shared hosting (if I use correct term), then
probably for kernel *you* do not exist at all.

If you have a place in the filesystem, where www-server can write
(create files) and ftp-server would allow you (as authenticated user)
and disallow any other user to read files then create your file there.
But probably your ftp-home (where you, as ftp-user, can manipulate
files) is document-root of your www-server.  Then you should configure
you www-server to forbid access to that file.  It would forbid access
from outside, your cgi-scripts would stay unaffected.  How you could do
either way is off-topic here.  You should find other newsgroup then.

*CUT*

-- 
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom


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

Date: 23 Jul 2011 17:34:54 GMT
From: blmblm@myrealbox.com <blmblm.myrealbox@gmail.com>
Subject: Re: Ownership of a file in unix file system
Message-Id: <990f1tF8n9U2@mid.individual.net>

In article <862l27lkndps56truopihbm1b24b8g6ugn@4ax.com>,
 <spam_filter@invalid.nil> wrote:

I think your question might be more a UNIX / web server question 
than a Perl question, and you might get better answers somewhere
else (though I'm not sure what group to recommend).  But maybe
I can say/ask a few marginally useful things:

> I need to create a file on a web server (running unix) and set its permission so
> that no-one, except with correct ftp username & password can download or view it.

What do you mean by "correct ftp username & password" here?

> On my wwww server I've created test.pl. When I go to
> www.notareal.com/cgi-bin/test.pl
> Firefox shows "Hello world" as expected. When I use a FTP program the check if
> newtext.tx has been created it's there OK.

"There"?  Where?  (This affects which users can access it.)

> The problem is that I cannot download the newtext.txt or view it. I can delete it
> but that's just about it.
> 
> 
> Here is a simple test.pl:
> 
> #!/usr/bin/perl
> print "Content-Type: text/html; charset=iso-8859-1\n\n";
> print '<html><BODY>';
> open(TEKSTI,">newtext.txt");
> print TEKSTI "just testing";
> close(TEKSTI);
> chmod 0600,"newtext.txt";       ## The problem line
> print "Hello world</body> </HTML>";
> 
> 
> 
> If I leave out the problem line everything works but the file is set as 644 and
> not 600. Can I leave it as 644? Can someone without user name and password still
> access it from browsers or other program? 

644 is world-readable, so the answer is sort of "yes", though it
also depends on permissions of enclosing directories.

> I tried this on another www page and it worked there ok.

"Another www page"?  do you mean another CGI program, or what?

One question I would ask is this:  What does newtext.txt show as
its owning UID?  (I'm thinking it might be a UID belonging to the
Web server, and that might not be what you intended.)

-- 
B. L. Massingill
ObDisclaimer:  I don't speak for my employers; they return the favor.


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

Date: Sat, 23 Jul 2011 11:13:05 -0700
From: Michael Vilain <vilain@NOspamcop.net>
Subject: Re: Ownership of a file in unix file system
Message-Id: <vilain-AC42B5.11130523072011@news.individual.net>

In article <862l27lkndps56truopihbm1b24b8g6ugn@4ax.com>,
 spam_filter@invalid.nil wrote:

> I need to create a file on a web server (running unix) and set its permission 
> so
> that no-one, except with correct ftp username & password can download or view 
> it.
> On my wwww server I've created test.pl. When I go to
> www.notareal.com/cgi-bin/test.pl
> Firefox shows "Hello world" as expected. When I use a FTP program the check 
> if
> newtext.tx has been created it's there OK.
> 
> The problem is that I cannot download the newtext.txt or view it. I can 
> delete it
> but that's just about it.
> 
> 
> Here is a simple test.pl:
> 
> #!/usr/bin/perl
> print "Content-Type: text/html; charset=iso-8859-1\n\n";
> print '<html><BODY>';
> open(TEKSTI,">newtext.txt");
> print TEKSTI "just testing";
> close(TEKSTI);
> chmod 0600,"newtext.txt";       ## The problem line
> print "Hello world</body> </HTML>";
> 
> 
> 
> If I leave out the problem line everything works but the file is set as 644 
> and
> not 600. Can I leave it as 644? Can someone without user name and password 
> still
> access it from browsers or other program? 
> 
> I tried this on another www page and it worked there ok.

The problem with creating files via a web browser is the the process 
that creates them is the owner of the file.  Depending on how you setup 
your web server and what web server it is (usually it's Apache), it will 
be something like www or nobody.  That's a configuration option.  So, 
you create a file with permissions rw------- (600), only www will be 
able to read it.

When you ftp into the machine and login, you're that user's ID (i.e. 
userA).  If the web server created the file to only allow www to read 
and write it, then userA won't be able to.

In shared web hosting environments, a way around this is to setup the 
web server to run CGI scripts under the user you want to create the 
file.  There's a program you can compile and install that allows you to 
run a CGI script as a specific user.  Look for cgiwrap in Google.  
You'll have to compile and install it as a SUID program and modify the 
path in your html page that calls the script.

There may be a way to run Apache in a shared environment to allow for an 
instance to run as a specific user, but it would require some sort of 
authentication.  cgiwrap bypasses that.

All this is irrelevant if you're running in a shared web hosting 
environment.  Check with your ISP on how you do this on their system.

-- 
DeeDee, don't press that button!  DeeDee!  NO!  Dee...
[I filter all Goggle Groups posts, so any reply may be automatically ignored]




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

Date: Sat, 23 Jul 2011 21:49:02 +0300
From: John <John.Smith@invalid.com>
Subject: Re: Ownership of a file in unix file system
Message-Id: <lb4m27p3asd2t95m2g9jgjae1b3fro19ru@4ax.com>

blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> wrote:

>In article <862l27lkndps56truopihbm1b24b8g6ugn@4ax.com>,
> <spam_filter@invalid.nil> wrote:
>
>I think your question might be more a UNIX / web server question 
>than a Perl question, and you might get better answers somewhere
>else (though I'm not sure what group to recommend).  But maybe
>I can say/ask a few marginally useful things:
>
>> I need to create a file on a web server (running unix) and set its permission so
>> that no-one, except with correct ftp username & password can download or view it.
>
>What do you mean by "correct ftp username & password" here?

I create the TEST.PL file with a notepad program on my home computer. Then I
upload it to the web server using FileZilla (an ftp client program). I also use
FileZilla to download the NEWTEXT.TXT file to see what's in it. To log on to the
server I need username and password.

>
>> On my wwww server I've created test.pl. When I go to
>> www.notareal.com/cgi-bin/test.pl
>> Firefox shows "Hello world" as expected. When I use a FTP program the check if
>> newtext.tx has been created it's there OK.
>
>"There"?  Where?  (This affects which users can access it.)

On the web server. Users access via web using, say, Firefox and going to
www.notareal.com/cgi-bin/test.pl
Once they see "Hello World" they should be able to go to
www.notareal.com/cgi-bin/newtext.txt
or atleast something should come up on the browser.

>
>> The problem is that I cannot download the newtext.txt or view it. I can delete it
>> but that's just about it.
>> 
>> 
>> Here is a simple test.pl:
>> 
>> #!/usr/bin/perl
>> print "Content-Type: text/html; charset=iso-8859-1\n\n";
>> print '<html><BODY>';
>> open(TEKSTI,">newtext.txt");
>> print TEKSTI "just testing";
>> close(TEKSTI);
>> chmod 0600,"newtext.txt";       ## The problem line
>> print "Hello world</body> </HTML>";
>> 
>> 
>> 
>> If I leave out the problem line everything works but the file is set as 644 and
>> not 600. Can I leave it as 644? Can someone without user name and password still
>> access it from browsers or other program? 
>
>644 is world-readable, so the answer is sort of "yes", though it
>also depends on permissions of enclosing directories.
>
>> I tried this on another www page and it worked there ok.
>
>"Another www page"?  do you mean another CGI program, or what?

I uploaded the very same TEST.PL on www.anotherofmyhomepages.com and then used
Firefox to see if I get an 404 error or "Hello world". I get the greeting. In
addition to greeting message a file NEWTEXT.TXT should have been created on the
server (it has).

>
>One question I would ask is this:  What does newtext.txt show as
>its owning UID?  (I'm thinking it might be a UID belonging to the
>Web server, and that might not be what you intended.)

When I use Filezilla to look at the file listing on the server I see the
NEWTEXT.TXT is 0600 80 80 which means that its a file that owner (me) can modify
and read but not some anonymous user. The "80 80" means owner is "no-one".

On www.anotherofmyhomepages.com NEWTEXT.TXT is 0600 80 80 and it can be accessed,
modified, deleted withe FileZille ftp client program.
However, on www.notareal.com NEWTEXT.TXT is also  0600 80 80 and but it can only
be deleted with FileZille ftp client program. Any modification (change 0600 ->
0755 etc), download is not possible.

What I am thinking is that is the some other Perl command I should use for
compatibility. Or is there some guideline that "you should not create files in
cg-bin directory" etc.


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

Date: Sat, 23 Jul 2011 12:31:52 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Ownership of a file in unix file system
Message-Id: <358m27lvp1ikh7mssbvi4hojelejl6pu8g@4ax.com>

spam_filter@invalid.nil wrote:
>I need to create a file on a web server (running unix) and set its permission so
>that no-one, except with correct ftp username & password can download or view it.
>On my wwww server I've created test.pl. When I go to
>www.notareal.com/cgi-bin/test.pl
>Firefox shows "Hello world" as expected. When I use a FTP program the check if
>newtext.tx has been created it's there OK.

Your question has absolutely nothing to do with Perl.

Investigate under which userID the web server is running this specific
task, investigate which userID is used as the effective UID in the FTP
program, and maybe even understand how permissions work on Unix (for
some people they are non-intuitive).
And then configure your web server and your FTP server such that the
file is created with the desired userID (check it using a shell!!!) and
you should be all set.

jue


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

Date: Sat, 23 Jul 2011 03:32:58 -0600
From: elliot <elliot@example.net>
Subject: stuck in regex
Message-Id: <98viq9FndvU1@mid.individual.net>

elliot@dan:/media/KINGSTON$ perl input1.pl
   1 #include <stdio.h>
   2 #include <malloc.h>
   3
   4 void testc(double **pa)
   5 {
   6  double b;
   7  double *a;
   8  int m;
   9
  10  a = (double*) malloc(sizeof(double)*5);
  11  a[0]=1.23;
  12  a[1]=2.46;
  13  a[2]=3.69;
  14  a[3]=4.11;
  15  a[4]=7.21;
  16  *pa=a;
  17  for (m=0;m<5;m++)
  18  {
  19    b=a[m];
  20    b=b+1.0;
  21    a[m]=b;
  22  }
  23 }


// gcc -c -Wall -Wextra cfile.c -o testc.o
elliot@dan:/media/KINGSTON$ cat input1.pl
#!/usr/bin/perl -w

use strict;
my $filename = "cfile.c";
open FILE, $filename or die $!;
while (<FILE>) { print $_; }





elliot@dan:/media/KINGSTON$

How do I s/// so as to adios the integers?
-- 
elliot


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

Date: Sat, 23 Jul 2011 08:24:43 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: stuck in regex
Message-Id: <slrnj2lieu.eve.tadmc@tadbox.sbcglobal.net>

elliot <elliot@example.net> wrote:

>   10  a = (double*) malloc(sizeof(double)*5);
                                            ^
>   11  a[0]=1.23;
          ^
>   12  a[1]=2.46;
          ^
>   13  a[2]=3.69;
          ^
>   14  a[3]=4.11;
          ^
>   15  a[4]=7.21;
          ^

>   17  for (m=0;m<5;m++)
               ^   ^

Those are all integers...


> How do I s/// so as to adios the integers?


-----------------------------
#!/usr/bin/perl
use warnings;
use strict;

while (<DATA>) {
    s/(?<![.\d])\d+(?![.\d])//g;
    print;
}

__DATA__
   1 #include <stdio.h>
   2 #include <malloc.h>
   3
   4 void testc(double **pa)
   5 {
   6  double b;
   7  double *a;
   8  int m;
   9
  10  a = (double*) malloc(sizeof(double)*5);
  11  a[0]=1.23;
  12  a[1]=2.46;
  13  a[2]=3.69;
  14  a[3]=4.11;
  15  a[4]=7.21;
  16  *pa=a;
  17  for (m=0;m<5;m++)
  18  {
  19    b=a[m];
  20    b=b+1.0;
  21    a[m]=b;
  22  }
  23 }
-----------------------------


The care taken to answer a question is in direct
proportion to the care taken in composing the question.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Sat, 23 Jul 2011 12:33:45 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: stuck in regex
Message-Id: <vd8m27d6henq207laeaerji8sl29ce0mor@4ax.com>

elliot <elliot@example.net> wrote:
>use strict;
>my $filename = "cfile.c";
>open FILE, $filename or die $!;
>while (<FILE>) { print $_; }
>
>How do I s/// so as to adios the integers?

while (<FILE>) {
	s/\d+/adios/g; 
	print $_; }
}

That was easy.

jue


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

Date: Sat, 23 Jul 2011 18:12:00 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: stuck in regex
Message-Id: <slrnj2mks3.g52.tadmc@tadbox.sbcglobal.net>

Jürgen Exner <jurgenex@hotmail.com> wrote:
> elliot <elliot@example.net> wrote:
>>use strict;
>>my $filename = "cfile.c";
>>open FILE, $filename or die $!;
>>while (<FILE>) { print $_; }
>>
>>How do I s/// so as to adios the integers?
                                   ^^^^^^^^
                                   ^^^^^^^^
>
> while (<FILE>) {
> 	s/\d+/adios/g; 
> 	print $_; }
> }
>
> That was easy.


But it will change the floating points that are in the data too...

:-)


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Sat, 23 Jul 2011 19:36:53 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: stuck in regex
Message-Id: <521n27tcmohq571vhkavpduoue4nboh52i@4ax.com>

Tad McClellan <tadmc@seesig.invalid> wrote:
>Jürgen Exner <jurgenex@hotmail.com> wrote:
>> elliot <elliot@example.net> wrote:
>>>use strict;
>>>my $filename = "cfile.c";
>>>open FILE, $filename or die $!;
>>>while (<FILE>) { print $_; }
>>>
>>>How do I s/// so as to adios the integers?
>                                   ^^^^^^^^
>                                   ^^^^^^^^
>>
>> while (<FILE>) {
>> 	s/\d+/adios/g; 
>> 	print $_; }
>> }
>>
>> That was easy.
>
>
>But it will change the floating points that are in the data too...
>
>:-)

How so? In e.g. 
	3.1415E01
_I_ see just three natural numbers, separated by a '.' and an 'E'. ;-)

However, I did forget about the optional signum in integers, so the OP
may want to add that to the RE.

jue


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

Date: Sun, 24 Jul 2011 00:11:39 -0600
From: elliot <elliot@example.net>
Subject: Re: stuck in regex
Message-Id: <991rcrFovcU1@mid.individual.net>

On 07/23/2011 08:36 PM, Jürgen Exner wrote:

> How so? In e.g.
> 	3.1415E01
> _I_ see just three natural numbers, separated by a '.' and an 'E'. ;-)
>
> However, I did forget about the optional signum in integers, so the OP
> may want to add that to the RE.
>
> jue

Even facetious replies helped me figure this out. It took me a while to 
figure out why the 2 was disappearing in the ultimate line, but I think 
I got it.  It compiles:

elliot@dan:/media/KINGSTON$ perl input2.pl
elliot@dan:/media/KINGSTON$ cat cfile2.c
#include <stdio.h>
#include <malloc.h>
void testc(double **pa)
{
double b;
double *a;
int m;
a = (double*) malloc(sizeof(double)*5);
a[0]=1.23;
a[1]=2.46;
a[2]=3.69;
a[3]=4.11;
a[4]=7.21;
*pa=a;
for (m=0;m<5;m++)
{
b=a[m];
b=b+1.0;
a[m]=b;
}
}
//gcc -c -Wall -Wextra cfile2.c -o testc.o  tja
elliot@dan:/media/KINGSTON$ gcc -c -Wall -Wextra cfile2.c -o testc.o
elliot@dan:/media/KINGSTON$ ls -l testc.o
-rw-r--r-- 1 elliot elliot 1048 2011-07-23 23:55 testc.o
elliot@dan:/media/KINGSTON$ cat input2.pl
#!/usr/bin/perl -w
use strict;
my $filename = "cfile.c";
open FILE, $filename or die $!;
open FILE2, ">cfile2.c" or die $!;
while (<FILE>) {
    #s/(?<![.\d])\d+(?![.\d])//g;
    s/\d+// unless m%/%;
    s/\s+//;
    print FILE2;
}
elliot@dan:/media/KINGSTON$

The script that I would think were more elegant and useful would be one 
that would remove an integer if it is the first word in a line, as well 
as whitespace thereafter.
-- 
elliot


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

Date: Sun, 24 Jul 2011 02:20:56 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: stuck in regex
Message-Id: <87d3h0qjw7.fsf@quad.sysarch.com>

>>>>> "e" == elliot  <elliot@example.net> writes:

  e> #!/usr/bin/perl -w

use warnings is better. it won't trigger warnings in modules you use.
  e> my $filename = "cfile.c";
  e> open FILE, $filename or die $!;
  e> open FILE2, ">cfile2.c" or die $!;
  e> while (<FILE>) {
  e>    #s/(?<![.\d])\d+(?![.\d])//g;
  e>    s/\d+// unless m%/%;

that is a noisy alternate delimiter. {} is the best one for that in most cases.
  e>    s/\s+//;
  e>    print FILE2;
  e> }

if you want to edit the file in place, you can use File::Slurp's
edit_file_lines.

use File::Slurp qw( edit_file_lines ) ;

edit_file_lines { s/\d+// unless m{/}; s/\s+//; } $file_name ;

done.

uri

-- 
Uri Guttman  --  uri AT perlhunter DOT com  ---  http://www.perlhunter.com --
------------  Perl Developer Recruiting and Placement Services  -------------
-----  Perl Code Review, Architecture, Development, Training, Support -------


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

Date: Fri, 22 Jul 2011 16:15:14 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: syntax query: ($var++ && next) if /match/
Message-Id: <45d12cf5-473a-4421-b1f8-34fa3d0cbc18@m3g2000pre.googlegroups.com>

On Jul 22, 3:04=A0pm, s...@netherlands.com wrote:
> On Fri, 22 Jul 2011 19:46:00 +0100, Rainer Weikusat <rweiku...@mssgmbh.co=
m> wrote:
> >s...@netherlands.com writes:
> >> On Fri, 22 Jul 2011 12:48:16 +0100, Justin C <justin.1...@purestblue.c=
om> wrote:
>
> >>>So far I have decided that ($seen =3D 1 and next) if ... is the
> >>>best solution for me... let's see what else this thread shows up befor=
e
> >>>I commit myself!
>
> >> Whats wrong with doing something like this:
>
> >> next if /^paul/ and $seen =3D 1;
>
> >It suggests that the $seen =3D 1 is actually part of the condition
> >which, in turn, will very likely make someone wonder whether or not it
> >was really supposed to be $seen =3D=3D 1. While the '$seen =3D 1 and nex=
t if'
> >reads very 'naturally' (assuming the reader is familiar with English)
> >it is sort-of an abuse.
>
> Thats true, it does read better but doesen't emit a (asignment) warning.
> That can probably be turned off though.


Similiarly, I've used 'and' chains
to sneak in a side effect :

    /^paul/ and $seen=3D1 and next;


but it's still ambiguous and harder to
see what's going on at a glance.

> I still prefer a block in this case.

Ditto.

Or even:  do {$seen=3D1; next } if /^paul/;

--
Charles DeRykus



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

Date: 23 Jul 2011 17:32:47 GMT
From: blmblm@myrealbox.com <blmblm.myrealbox@gmail.com>
Subject: Re: syntax query: ($var++ && next) if /match/
Message-Id: <990etvF8n9U1@mid.individual.net>

In article <87sjpy9wte.fsf@sapphire.mobileactivedefense.com>,
Rainer Weikusat  <rweikusat@mssgmbh.com> wrote:
> Justin C <justin.1104@purestblue.com> writes:
> > On 2011-07-21, Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
> >> Keith Thompson <kst-u@mib.org> writes:
> >>> Rainer Weikusat <rweikusat@mssgmbh.com> writes:
> >>>> Willem <willem@toad.stack.nl> writes:
> >>>>> Rainer Weikusat wrote:
> >>
> >> [...]
> >>
> >>>>> ) 	(($seen = 1) &&  next) if /^paul/;
> >>
> >> [...]
> >>
> >>>>>       ($seen = 1 and next) if /^paul/;
> >>>>
> >>>> Arguably a better idea. But the parenthesises can be dropped as well,

(You do know that the plural is actually "parentheses", right?)

> >>>> making this
> >>>>
> >>>> 	$seen = 1 and next if /^paul/;
> >>>>
> >>>> which I consider to be preferable.
> >>>
> >>> Some might consider
> >>>
> >>>     if (/^paul/) {
> >>>         $seen = 1;
> >>>         next;
> >>>     }
> >>>
> >>> to be preferable.
> >>
> >> Or
> >>
> >> 	/^paul/ and $seen = 1, next;
> >>
> >> You can put in on several lines if you're afraid your enter key might
> >> feel lonely otherwise
> >>
> >> /^paul/
> >> and
> >> $seen
> >> =
> >> 1
> >> ,
> >> next
> >> ;
> >
> > C'mon guys, now you're getting silly. I was going for a balance between
> > brevity and legibility. Using a block does not have much brevity, but
> > has a lot of legibility -
> 
> A text doesn't become easier to understand by adding more
> non-alphanumeric characters to it.

Presumably you mean "program text" here (since if you could also mean
natural language text I would respectfully disagree and I suspect you
would too since as this sentence is meant to demonstrate punctuation
can be very helpful in making sense of long sentences and indeed in
separating sentences not to mention that without nonalphanumerics
you couldnt spell contractions right).

Just sayin'.

The case is perhaps less clear for program text, but I would argue
that judicious use of parentheses, even when not needed, is an
aid to understanding.  Then again, I'm probably biased by the fact
that I'd rather put in some unnecessary parentheses from time to
time than try to keep in my head a table of operator precedences.
For example, I would rather just write

(a && b) || (c && d)

than try to remember which of the operators has higher precedence.
I'm aware that not everyone agrees with me.  :-)?


> > it was what my original code had (I was
> > younger and less experienced then). OTOH $seen = 1 and next if... is
> > brief to the detriment of legibility (or understandability),
> 
> Why this, since it does exactly what its literal meaning appears to
> be:
> 
> 	$seen = 1 and next if /^paul/

I would say that this line of code has an unambiguous literal
meaning only to someone who knows the relative precedence of all
the operators.  And (as someone else pointed out) what if the
assignment was "$seen = 0"?  even if the meaning would be clear
to someone who understands what "and" means in context, it seems
like a bit of work to remind oneself that here "and" is an
operator with short-circuit behavior rather than the ordinary
English word "and".

> (set $seen to 1 and execute next if $_ matches /^paul/)        

But isn't that sentence also potentially ambiguous?  Isn't there
some ambiguity about whether the "if" applies to both "set $seen
to 1" and "execute next", or just to "execute next"?

-- 
B. L. Massingill
ObDisclaimer:  I don't speak for my employers; they return the favor.


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

Date: Sat, 23 Jul 2011 22:31:58 -0700
From: David Harmon <source@netcom.com>
Subject: Re: syntax query: ($var++ && next) if /match/
Message-Id: <9NydnSfdhLPsM7bTnZ2dnUVZ_sadnZ2d@earthlink.com>

On Fri, 22 Jul 2011 16:09:17 +0100 in comp.lang.perl.misc, Rainer
Weikusat <rweikusat@mssgmbh.com> wrote,
>A text doesn't become easier to understand by adding more
>non-alphanumeric characters to it.

Except when it does.


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

Date: Sun, 24 Jul 2011 06:44:02 +0000 (UTC)
From: Snorkmeier <snorkmeier._10c@gmail.invalid>
Subject: You shoot yourself in the foot.
Message-Id: <j0gevh$rt3$4@dont-email.me>

BASIC:

10 GOSUB SHOOT_FOOT
20 GOTO 10
30 SHOOT_FOOT: PRINT "OW!"
40 RETURN

READY.

RUN

OW!
OW!
OW!
OW!
OW!
OW!
 ...


C:

shoot(foot);

Exiting due to signal SIGSEGV...


Smalltalk:

self shoot: self foot

DEBUG
SmallInteger doesNotUnderstand: addBulletHole


Common Lisp:

(shoot foot)

Exiting due to signal SIGSEGV...


Scheme:

(define with-shot-foot (f)
  (lambda (foot) (f (shoot foot))))

(define foobar
  ...)

((with-shot-foot foobar))

; feet are whole again here!
; but the return value of foobar is screwy


Java:

Rifle<Ammo9MM> r = RifleFactory.createRifle
    (Ammo9MM.class,10,RifleFactory.RIFLE_LOADED,
     RifleFactory.RIFLE_SEMIAUTOMATIC);
Foot f = Body.getSingletonInstance().getFoot();
try {
    r.shoot(f);
} catch (OutOfAmmunitionException e) {
    Logger.getInstance().logError(e);
    e.printStackTrace();
} catch (RifleJammedException e) {
    Logger.getInstance().logError(e);
    e.printStackTrace();
} catch (SecurityException e) {
    JOptionPane.showMessageDialog("Can't shoot foot in unsigned applet!");
} finally {
    r.ejectAmmo();
    r.unloadChamber();
    r.releaseAllHandles();
}

Exception java.lang.OutOfMemoryError: Java heap space
        in java.util.HashMap.put (HashMap.java: 317)
        in com.foo.audit.SerialNumber.intern (SerialNumber.java: 112)
        in com.foo.audit.SerialNumber.newInstance (SerialNumber.java: 33)
        in com.foo.Ammo.createSerialNo (Ammo.java: 42)
        in com.foo.Ammo9MM.<init> (Ammo9MM.java: 18)
        in com.foo.Ammo9MMFactory.create (Ammo9MMFactory.java: 1191)
 ...


Perl:

#!/bin/perl
$*JS()#@*%0)__!@MDF*$%)FK@)my_($foot)(*#ND&*%($bullet)9jcfnd8($rifle)

usr/scripts (ROOT CONSOLE)> ./shoot_foot.pl

DWIM parser surprises you!
You shot yourself in the head!

/dev/hda0 redirected to /dev/null

Exit status -1

Kernel panic

EAX = 0x00000000        EBX = 0x103f3abd
ECX = 0x00000dc3        EDX = 0x0003afb7
 ...

System halted


C++:

foot += bullet;

RATATATATATATATATATATATAT!
*crash! bang!*
*klunk klunk klunk*
*hisssssss*
"FREEZE!"
*cough cough cough*
"Someone call a bus! There must be ten thousand expended rounds in here 
and dozens of wounded!"
"Should I also arrest this survivor for egregious abuse of operator 
overloading?"
"You can add at least three counts of criminally negligent homicide."


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

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 3452
***************************************


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