[16817] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4229 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 5 18:10:35 2000

Date: Tue, 5 Sep 2000 15:10:18 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <968191818-v9-i4229@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 5 Sep 2000     Volume: 9 Number: 4229

Today's topics:
        RegEx:  I'm stumped <jar@mminternet.com>
    Re: RegEx:  I'm stumped <godzilla@stomp.stomp.tokyo>
    Re: RegEx:  I'm stumped <quidity.erebus@virgin.net>
    Re: RegEx:  I'm stumped (Mike Stok)
    Re: RegEx:  I'm stumped <jar@mminternet.com>
    Re: RegEx:  I'm stumped <jar@mminternet.com>
    Re: RegEx:  I'm stumped <jar@mminternet.com>
    Re: RegEx:  I'm stumped <godzilla@stomp.stomp.tokyo>
    Re: RegEx:  I'm stumped (Craig Berry)
    Re: RegEx:  I'm stumped <bart.lateur@skynet.be>
    Re: Remove carriage returns from input <flavell@mail.cern.ch>
    Re: Seperating text and integers from a variable <russ_jones@rac.ray.com>
    Re: showing external hyperlinks in a frame... (Stan Brown)
        Stable sorting <bart.lateur@skynet.be>
    Re: Stable sorting <uri@sysarch.com>
    Re: Troubles with dbd::oracle installation (John D Groenveld)
        Unlink with NT <andrew.edmunds@virgin.net>
    Re: Unlink with NT <hillr@ugsolutions.com>
    Re: use strict: why? (Craig Berry)
    Re: use strict: why? (Andrew Johnson)
    Re: use strict: why? (Hugh Lawson)
        using perl in a redundant way. johnvert@my-deja.com
    Re: using perl in a redundant way. <uri@sysarch.com>
    Re: using perl in a redundant way. <bart.lateur@skynet.be>
    Re: World Wide PERL PROGRAMMERS TELECOMMUTE <raphaelp@nr1webresource.com>
    Re: World Wide PERL PROGRAMMERS TELECOMMUTE <russ_jones@rac.ray.com>
    Re: World Wide PERL PROGRAMMERS TELECOMMUTE <godzilla@stomp.stomp.tokyo>
    Re: World Wide PERL PROGRAMMERS TELECOMMUTE <uri@sysarch.com>
    Re: write a file in an array (Chris Fedde)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 05 Sep 2000 11:18:38 -0700
From: jim roush <jar@mminternet.com>
Subject: RegEx:  I'm stumped
Message-Id: <eidarsg4on8a076m3iqikovvt7ujjni51b@4ax.com>

I'm writing a script that processes some html code.  Among other
things it must do is convert this bit of html  &Amp; to a simple &.  I
first started with

     s/&Amp;/&/

this did nothing.  I admit RegExs are one of my weak points.  What am
I doing wrong?


jar@mminternet.com
James A Roush


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

Date: Tue, 05 Sep 2000 11:43:56 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: RegEx:  I'm stumped
Message-Id: <39B53EEC.64AC1741@stomp.stomp.tokyo>

jim roush wrote:
 
> I'm writing a script that processes some html code.  Among other
> things it must do is convert this bit of html  &Amp; to a simple &.  I
> first started with
 
>      s/&Amp;/&/
 
> this did nothing.


TEST SCRIPT:
____________

#!/usr/local/bin/perl

print "Content-type: text/plain\n\n";


$string = "This &amp; that";

print "Input: $string\n\n";

$string =~ s/&amp;/&/i;

print "Output: $string\n\n";


$string = "This &Amp; that";

print "Input: $string\n\n";

$string =~ s/&amp;/&/i;

print "Output: $string\n\n";


$string = "This &AMP; that";

print "Input: $string\n\n";

$string =~ s/&amp;/&/i;

print "Output: $string";


exit;


PRINTED RESULTS:
________________

Input: This &amp; that

Output: This & that

Input: This &Amp; that

Output: This & that

Input: This &AMP; that

Output: This & that



Godzilla!
--
@© = (a .. z); @® = qw (7 15 4 26 9 12 12 1 18 15 3 11 19);
srand(time() ^ ($$ + ($$ << 15))); for ($§ = $®[$®[0]]; $§ < $®[0]; $§++)
{ sub G { rand(1000) < 500 ? "\u$1" : "\l$1" ; } foreach $¿ (@®) 
{ $¢ = $©[$¿-1]; $¢ =~ s¡([a-z])¡G($1)¡gie; $Ø = "$Ø$¢"; }
$Ø ="$Ø! "; $ø = substr ($Ø, $®[12] - $®[11], 0, " ");
$Ø =~ s¯(a)(r)¯$1 $2¯i; push (@Ø,$Ø); } foreach $¡ (@Ø)
{ print "$¡\n"; } @¶ = reverse (@Ø); foreach $¶ (@¶)
{ print "$¶\n"; } exit;


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

Date: Tue, 5 Sep 2000 19:46:00 +0100
From: "Alex Gough" <quidity.erebus@virgin.net>
Subject: Re: RegEx:  I'm stumped
Message-Id: <zdbt5.10617$k77.174695@news2-win.server.ntlworld.com>

"jim roush" <jar@mminternet.com> wrote in message
news:eidarsg4on8a076m3iqikovvt7ujjni51b@4ax.com...
> I'm writing a script that processes some html code.  Among other
> things it must do is convert this bit of html  &Amp; to a simple &.  I
> first started with
>
>      s/&Amp;/&/
>
> this did nothing.  I admit RegExs are one of my weak points.  What am
> I doing wrong?

You might like to try the HTML::Entities module.

Someone else once had your exact same problem...




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

Date: Tue, 05 Sep 2000 18:50:21 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: RegEx:  I'm stumped
Message-Id: <Nfbt5.34232$K5.554946@typhoon.austin.rr.com>

In article <eidarsg4on8a076m3iqikovvt7ujjni51b@4ax.com>,
jim roush  <jar@mminternet.com> wrote:
>I'm writing a script that processes some html code.  Among other
>things it must do is convert this bit of html  &Amp; to a simple &.  I
>first started with
>
>     s/&Amp;/&/
>
>this did nothing.  I admit RegExs are one of my weak points.  What am
>I doing wrong?

Without any surrounding context it's hard to diagnose what exactly you're
doing, let alone what you're doing wrong.

One thing you might do is use someone else's work, the HTML::Entities
module may be of use to you.  Using the debugger (and assuming a Latin 1
character set from my cut & paste...)

  DB<1> use HTML::Entities;

  DB<2>  $a = "V&aring;re norske tegn b&oslash;r &#230res";

  DB<3> print decode_entities($a);
Våre norske tegn bør æres

The HTML::Parser module/bundle contains HTML::Entities, you can read about
it at http://www.cpan.org/modules/by-module/HTML/HTML-Parser-3.11.readme

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |
GPG PGP Key 1024D/059913DA         | Fingerprint      0570 71CD 6790 7C28 3D60
stok@colltech.com (CT - work)      |                  75D2 9EC4 C1C0 0599 13DA


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

Date: Tue, 05 Sep 2000 12:31:51 -0700
From: jim roush <jar@mminternet.com>
Subject: Re: RegEx:  I'm stumped
Message-Id: <dfiarss3vjo15a6boi4t0ugqnopevtmc4o@4ax.com>

On Tue, 05 Sep 2000 18:50:21 GMT, mike@stok.co.uk (Mike Stok) wrote:

Thanks, I'll look at it.


>In article <eidarsg4on8a076m3iqikovvt7ujjni51b@4ax.com>,
>jim roush  <jar@mminternet.com> wrote:
>>I'm writing a script that processes some html code.  Among other
>>things it must do is convert this bit of html  &Amp; to a simple &.  I
>>first started with
>>
>>     s/&Amp;/&/
>>
>>this did nothing.  I admit RegExs are one of my weak points.  What am
>>I doing wrong?
>
>Without any surrounding context it's hard to diagnose what exactly you're
>doing, let alone what you're doing wrong.
>
>One thing you might do is use someone else's work, the HTML::Entities
>module may be of use to you.  Using the debugger (and assuming a Latin 1
>character set from my cut & paste...)
>
>  DB<1> use HTML::Entities;
>
>  DB<2>  $a = "V&aring;re norske tegn b&oslash;r &#230res";
>
>  DB<3> print decode_entities($a);
>Våre norske tegn bør æres
>
>The HTML::Parser module/bundle contains HTML::Entities, you can read about
>it at http://www.cpan.org/modules/by-module/HTML/HTML-Parser-3.11.readme
>
>Hope this helps,
>
>Mike

jar@mminternet.com
James A Roush


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

Date: Tue, 05 Sep 2000 12:32:56 -0700
From: jim roush <jar@mminternet.com>
Subject: Re: RegEx:  I'm stumped
Message-Id: <fhiars81ncpu4ko57h1vgfa9vja7k5cm0n@4ax.com>

On Tue, 5 Sep 2000 19:46:00 +0100, "Alex Gough"
<quidity.erebus@virgin.net> wrote:

>"jim roush" <jar@mminternet.com> wrote in message
>news:eidarsg4on8a076m3iqikovvt7ujjni51b@4ax.com...
>> I'm writing a script that processes some html code.  Among other
>> things it must do is convert this bit of html  &Amp; to a simple &.  I
>> first started with
>>
>>      s/&Amp;/&/
>>
>> this did nothing.  I admit RegExs are one of my weak points.  What am
>> I doing wrong?
>
>You might like to try the HTML::Entities module.
>
>Someone else once had your exact same problem...
>


Thanks, I'll look at it.


jar@mminternet.com
James A Roush


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

Date: Tue, 05 Sep 2000 13:02:12 -0700
From: jim roush <jar@mminternet.com>
Subject: Re: RegEx:  I'm stumped
Message-Id: <96kars4kuulp6a1i1adlipvm0d05pq841d@4ax.com>

On Tue, 05 Sep 2000 11:43:56 -0700, "Godzilla!"
<godzilla@stomp.stomp.tokyo> wrote:

>jim roush wrote:
> 
>> I'm writing a script that processes some html code.  Among other
>> things it must do is convert this bit of html  &Amp; to a simple &.  I
>> first started with
> 
>>      s/&Amp;/&/
> 
>> this did nothing.
>
>
>TEST SCRIPT:
>____________
>
>#!/usr/local/bin/perl
>
>print "Content-type: text/plain\n\n";
>
>
>$string = "This &amp; that";
>
>print "Input: $string\n\n";
>
>$string =~ s/&amp;/&/i;
>
>print "Output: $string\n\n";
>
>
>$string = "This &Amp; that";
>
>print "Input: $string\n\n";
>
>$string =~ s/&amp;/&/i;
>
>print "Output: $string\n\n";
>
>
>$string = "This &AMP; that";
>
>print "Input: $string\n\n";
>
>$string =~ s/&amp;/&/i;
>
>print "Output: $string";
>
>
>exit;
>
>
>PRINTED RESULTS:
>________________
>
>Input: This &amp; that
>
>Output: This & that
>
>Input: This &Amp; that
>
>Output: This & that
>
>Input: This &AMP; that
>
>Output: This & that
>
>
>
>Godzilla!


Thanks, just adding the i to ignore case fixed the problem.



jar@mminternet.com
James A Roush


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

Date: Tue, 05 Sep 2000 13:24:59 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: RegEx:  I'm stumped
Message-Id: <39B5569B.74C22BA0@stomp.stomp.tokyo>

jim roush wrote:

> Godzilla!" wrote:
> > jim roush wrote:

> Thanks, just adding the i to ignore case fixed the problem.


* smiles *

Godzilla!
-- 
Clear Concise Communication.
  http://la.znet.com/~callgirl/clarity.cgi


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

Date: Tue, 05 Sep 2000 20:41:46 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: RegEx:  I'm stumped
Message-Id: <sramka21ljn109@corp.supernews.com>

jim roush (jar@mminternet.com) wrote:
: I'm writing a script that processes some html code.  Among other
: things it must do is convert this bit of html  &Amp; to a simple &.  I
: first started with
: 
:      s/&Amp;/&/
: 
: this did nothing.  I admit RegExs are one of my weak points.  What am
: I doing wrong?

Nothing that you've shown us:

  /usr2/people/cberry > perl -w
  use strict;

  $_ = 'and some stuff &Amp; and some more stuff';
  s/&Amp;/&/;
  print;

Output:

  and some stuff & and some more stuff

Clearly the problem is in some other part of your code.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Every force evolves a form."
   |              - Shriekback


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

Date: Tue, 05 Sep 2000 21:50:17 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: RegEx:  I'm stumped
Message-Id: <jiqars82u78562m8o719m88gi499ukb9rb@4ax.com>

jim roush wrote:

>     s/&Amp;/&/
>
>this did nothing. 

Probably just the wrong case. It's "&amp;", not "&Amp;". Oh, and you
need to add the //g modifier (put a "g" between the 3rd slash and the
semicolon), unless you only want to replace the first occurrence.

-- 
	Bart.


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

Date: Tue, 5 Sep 2000 23:13:29 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Remove carriage returns from input
Message-Id: <Pine.GHP.4.21.0009052308180.20987-100000@hpplus03.cern.ch>

On Tue, 5 Sep 2000, Larry Rosler wrote:

> But chr(10) is line feed, not carriage return, except on the Mac.

chr(10) is the ASCII line feed character on any (ASCII) platform.

What's different about the Mac is that it doesn't use this character
to represent newline.

> Most likely the original poster wants to strip newlines, 

I'm even more convinced that if one doesn't distinguish clearly
between the specific ASCII control characters (CR and LF, \015 and
\012 respectively) on the one hand, and the logical functions (\n and
\r, not necessarily in that order) on the other hand, then one just
discusses around in circles.

all the best



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

Date: Tue, 05 Sep 2000 13:02:35 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: Seperating text and integers from a variable
Message-Id: <39B5353B.1B713C91@rac.ray.com>

Mark-Jason Dominus wrote:
> 
> In article <MPG.141ecd4e234bdef098ad1e@nntp.hpl.hp.com>,
> Larry Rosler  <lr@hpl.hp.com> wrote:
> >> Don't leave out any of the parentheses.
> >
> >Why not?
> 
> Because it's simpler and clearer to say "Don't leave out any of the
> parentheses" than to explain what all the parentheses are for, and
> because in the past when I've omitted that instruction, the querent
> came back and said "IT DIDNT WORK DUMMY" when they omitted the
> parentheses.


The parentheses make your intentions perfectly clear, not only to the
compiler, but to yourself. They're cheap documentation, and they make
it a lot easier on the next poor sap that has to maintain your code
(think y10k: we never thought our two digit years would still be
around in 00).



-- 
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747

Quae narravi, nullo modo negabo. - Catullus


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

Date: Tue, 5 Sep 2000 15:16:16 -0400
From: brahms@mindspring.com (Stan Brown)
Subject: Re: showing external hyperlinks in a frame...
Message-Id: <MPG.141f108f1a2e470398b742@news.mindspring.com>

[This followup was also e-mailed to the cited author for speed. 
Please follow up in the newsgroup.]

Alex Walker <alexwalker@hotmail.com> wrote in 
comp.infosystems.www.authoring.html:
>
>My main page has no frames. When people click on an external hyperlink I
>would like the resulting page to consist of two parts not 1:a header frame
>in it which displays my banner (a bit like askjeeves), and the linked page
>below.
>
>Hope this makes sense!

It makes sense, but why are you reposting this query? It has already 
been answered, within the past 48 hours.

Summary: it's unethical, and probably illegal. Don't do it.

-- 
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA
                                             http://oakroadsystems.com
My reply address is correct as is. The courtesy of providing a correct
reply address is more important to me than time spent deleting spam.


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

Date: Tue, 05 Sep 2000 21:39:38 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Stable sorting
Message-Id: <6gpars002219jch28f334jbgucnetsk18m@4ax.com>

I wonder what techniques are considered smart, with regards to creating
a "stable sort", i.e. all things being  equal, the original item order
is preserved.

I've read that the Schwartzian Transform would be one good way. This is
what I'd make of it (assuming that each record is an anonymous array):

	@sorted = map { $_->[1] }
	  sort { $a->[1][3] <=> $b->[1][3] || $a->[0] <=> $b->[0] }
	    map { [ $_, $records[$_]] } @records;

This is the sort I actually used:

	@sorted = @record[ sort { $records[$a][3] <=> $records[$b][3]
	  || $a <=> $b } 0 .. $#records ];

I wonder what is better, and if there are better alternatives I haven't
thought of; or at least, if one of these can be optimized.

-- 
	Bart.


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

Date: Tue, 05 Sep 2000 22:02:50 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Stable sorting
Message-Id: <x73djemr92.fsf@home.sysarch.com>

>>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:

  BL> I wonder what techniques are considered smart, with regards to creating
  BL> a "stable sort", i.e. all things being  equal, the original item order
  BL> is preserved.

  BL> I've read that the Schwartzian Transform would be one good way. This is
  BL> what I'd make of it (assuming that each record is an anonymous array):

  BL> 	@sorted = map { $_->[1] }
  BL> 	  sort { $a->[1][3] <=> $b->[1][3] || $a->[0] <=> $b->[0] }
  BL> 	    map { [ $_, $records[$_]] } @records;

you can't tell that is stable unless you define what is in @records. 

and the second comparison makes no sense if @records are anon arrays as
it is comparing the refs themselves. ref values are meaningless for a
stable sort.

  BL> This is the sort I actually used:

  BL> 	@sorted = @record[ sort { $records[$a][3] <=> $records[$b][3]
                   ^^^^^^
should be @records

  BL> 	  || $a <=> $b } 0 .. $#records ];

  BL> I wonder what is better, and if there are better alternatives I haven't
  BL> thought of; or at least, if one of these can be optimized.

that looks better. but the GRT is faster. i will assume integer values
for the sort field:

	@sorted_inds =
		map unpack( 'x4N' ),
		sort
		map pack( 'NN', $records[$_][3], $_ ), 0 .. $#records ;

check out our paper at:

http://www.hpl.hp.com/personal/Larry_Rosler/sort/sorting.html

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 5 Sep 2000 14:19:58 -0400
From: groenvel@cse.psu.edu (John D Groenveld)
Subject: Re: Troubles with dbd::oracle installation
Message-Id: <8p3dge$be4$1@ewok.cse.psu.edu>

Does README.help's "Can't find libclntsh.so at run time" apply?
John
groenveld@acm.org


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

Date: Tue, 05 Sep 2000 20:31:46 +0100
From: Andy <andrew.edmunds@virgin.net>
Subject: Unlink with NT
Message-Id: <39B54A22.FAD13E1E@virgin.net>

Hi,

I've been looking through the faq's, and I can't find much on this
subject.

I'm using Perl 5 to create and delete files in a subdirectory.  This
works fine on my machine at home running windows 98, but when I put it
on my server I can't unlink the file.

The commands used are :

open (STUFF,"/path/linkl.txt");
close (STUFF);

to create the file, and :

unlink ("/path/linkl.txt");

to remove the file.  The creating part works fine, but I can't unlink
it.  Is there something about this command that NT doesn't like ?  I'm
assured by my provider that i've got rwed privalages for this
subdirectory, and i've tried absolute paths as well, but that doesn't
work either.

Any points welcome.

Cheers,

Andy



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

Date: Tue, 05 Sep 2000 13:03:27 -0700
From: Ron Hill <hillr@ugsolutions.com>
Subject: Re: Unlink with NT
Message-Id: <39B5518F.4500B626@ugsolutions.com>


Andy wrote:

> Hi,
>
> I've been looking through the faq's, and I can't find much on this
> subject.
>
> I'm using Perl 5 to create and delete files in a subdirectory.  This
> works fine on my machine at home running windows 98, but when I put it
> on my server I can't unlink the file.
>
> The commands used are :
>
> open (STUFF,"/path/linkl.txt");
> close (STUFF);
>
> to create the file, and :
>
> unlink ("/path/linkl.txt");
>

try unlink ("/path/link1.txt) or die "Can't delete $FILENAME: $!\n";

this will give the reason as to why it does not work ($!) is the error

Ron


>
> to remove the file.  The creating part works fine, but I can't unlink
> it.  Is there something about this command that NT doesn't like ?  I'm
> assured by my provider that i've got rwed privalages for this
> subdirectory, and i've tried absolute paths as well, but that doesn't
> work either.
>
> Any points welcome.
>
> Cheers,
>
> Andy



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

Date: Tue, 05 Sep 2000 18:17:25 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: use strict: why?
Message-Id: <srae5lpnkmp176@corp.supernews.com>

Tim Hammerquist (tim@degree.ath.cx) wrote:
: I've noticed in this NG that 'use strict' is often encouraged much like
: a dealer pushes drugs.  I completely understand it's benefits as a
: pragma.  However, it's not a rule.
[snip perldoc quote
: The Camel, 3rd, says something very similar in it's chapter on pragmas.
: Every other reference listed in the index hints at the same, with dozens
: of sprinkled "maybe", "sometimes", "may", etc.
[snip another perldoc quote]
: NB: "...or know the reason why not."  Besides, the top of perlstyle
: disclaims that these are only Larry's "guidelines" for maintainable code
: not out-and-out rules.
: 
: And while anything I write larger than 50 lines (almost always) has this
: pragma, there are times that 'use strict' disallows a feature you
: attempt to use.  Tom C. gave some examples in Cookbook that wouldn't
: work under 'use strict'.

But again, if you use these features (e.g., symbolic references) you are
wandering into a minefield.  It may be that that minefield is by far the
shortest path to your destination, and that you trust your ability to find
mines enough that you're willing to risk the trip.  But a tool like
'strict', which is designed to keep you away from mines, has to be turned
off.  It's like the ground-proximity alarm on an airplane...you turn it
off when you're on landing approach, but landings are indeed pretty
dangerous because the ground is (necessarily) nearby.

One thing to note is that the clpm community encourages 'strict' even more
insistently than a 'normal' perl shop might, since 90% of posters here are
presenting a problem and requesting help, and many of these problems would
be resolved without our help if the posters had made their code strict-
compliant.  So drubbing posters who do not use strict is a noise-reduction
measure.  In other words, posters are expected to take full advantage of
local resources (perldoc, -w, strict) before bugging the newsgroup.  In
general, people with working code, strict-compliant or not, do not bother
the group.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Every force evolves a form."
   |              - Shriekback


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

Date: Tue, 05 Sep 2000 20:42:29 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: use strict: why?
Message-Id: <VUct5.12210$a5.177438@news1.rdc1.mb.home.com>

In article <slrn8r9b5b.1c7.tim@degree.ath.cx>,
 Tim Hammerquist <tim@degree.ath.cx> wrote:
> I've noticed in this NG that 'use strict' is often encouraged much like
> a dealer pushes drugs.  I completely understand it's benefits as a
> pragma.  However, it's not a rule.

[snip]

> `perldoc perlstyle`
>     The most important thing is to run your programs under the -w
>     flag at all times. You may turn it off explicitly for particular
>     portions of code via the `$^W' variable if you must. You should
>     also always run under `use strict' or know the reason why not.
> 
> NB: "...or know the reason why not."  Besides, the top of perlstyle
> disclaims that these are only Larry's "guidelines" for maintainable code
> not out-and-out rules.

The "or know the reason why not" is the key element here. Many posters
and lurkers on this NG are neophytes, and won't "know the reason why
not" yet, so it makes very good sense to encourage the use of the
strict pragma and -w.

It strikes me that anyone who already knows the reason 'why not',
needn't bother asking why people recommend it in the first place --
they already know why it is a good idea, and they already know when
they can safely ignore such advice.

regards,
andrew

-- 
Andrew L. Johnson   http://members.home.net/perl-epwp/
      It may be that your sole purpose in life is simply to 
      serve as a warning to others.


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

Date: Tue, 05 Sep 2000 20:53:58 GMT
From: hlawson@triad.rr.com (Hugh Lawson)
Subject: Re: use strict: why?
Message-Id: <slrn8raooo.2hb.hlawson@localhost.localdomain>

This is prob a dumb question, but it's the question I have.

script follows:

#!/usr/bin/perl -w
use strict;
use Tk;
use vars qw($mw);
$mw = MainWindow->new;
$main::text = "hello";
#^^^^^^^^^
$mw::btn = $mw->Button(-text=>$main::text)->pack;
#                              ^^^^^^^^^  
MainLoop;

But, if I change '$main::text' throughout to '$a::text', the program seems
to work ok, considering it only displays the widget.

Is there a rule or convention governing this issue? I have searched for
this without success.
-- 
Hugh Lawson
Greensboro, North Carolina
hlawson@triad.rr.com



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

Date: Tue, 05 Sep 2000 21:18:46 GMT
From: johnvert@my-deja.com
Subject: using perl in a redundant way.
Message-Id: <8p3nv5$f82$1@nnrp1.deja.com>

Hello,

Recently there was talk here about how some people write Perl like they
write C, and someone (I believe Uri) suggested to post code here, so
that someone can guide me to the Perlish way.  Well, I'm one of these
people -- I write Perl like I write C, and I would like you to tear this
piece of code apart.  Don't be nice:

# this segment italicizes comments in various programming languages.
# there must be a better way.
while(defined($line=<SRC>))
{
    # C
    if($line=~m|/\*|){
        $line=~s|/\*|\<i\>/\*|;
    }
    if($line=~m|\*/|){
        $line=~s|\*/|\*/\</i\>|;
    }

    # C++
    if($line=~m|//|){
        $line=~s|//|\<i\>//|;
        $line=~s|\n|\</i\>\n|;
    }

    # Scheme
    if ($line=~m|;;|) {
        $line=~s|;;|\<i\>;;|;
        $line=~s|\n|\</i\>\n|;
    }

    print $line;
}

thanks,
  -- john


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 05 Sep 2000 21:46:36 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: using perl in a redundant way.
Message-Id: <x77l8qms04.fsf@home.sysarch.com>

>>>>> "j" == johnvert  <johnvert@my-deja.com> writes:

  j> piece of code apart.  Don't be nice:

fine with me! :)

  j> while(defined($line=<SRC>))

recent perl's do the defined implicitly for you. 


  j> {

blech! use the one true brace style and put it at the end of the while line.

  j>     # C
  j>     if($line=~m|/\*|){
  j>         $line=~s|/\*|\<i\>/\*|;

why match and match again? just do the s/// itself. and there is no
need to escape those chars in the replacement string.

	$line =~ m{/\*}{<i>/*} ;

  j>         $line=~s|\*/|\*/\</i\>|;

	$line =~ m{\*/}{*/</i>} ;

  j>     if($line=~m|//|){
  j>         $line=~s|//|\<i\>//|;
  j>         $line=~s|\n|\</i\>\n|;

and that can be done in one s/// as well.

	$line =~ s{(//.*$)}{<i>$1</i>}

  j>     # Scheme
  j>     if ($line=~m|;;|) {
  j>         $line=~s|;;|\<i\>;;|;
  j>         $line=~s|\n|\</i\>\n|;

and again:

	$line =~ s{(;;.*$)}{<i>$1</i>}


so your code reduces to:


	while( $line = <SRC> ) {

		$line =~ m{/\*}{<i>/*} ;	# C start
		$line =~ m{\*/}{*/</i>} ;	# C end
		$line =~ s{(//.*$)}{<i>$1</i>}	# C++
		$line =~ s{(;;.*$)}{<i>$1</i>}	# scheme

		print $line ;
	}

and that is very broken if any of those strings appear in quoted
strings, nested comments, etc. 

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Tue, 05 Sep 2000 22:01:40 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: using perl in a redundant way.
Message-Id: <8pqarsgvmp4g59ukpdlnqjaqsgr57dfa1i@4ax.com>

johnvert@my-deja.com wrote:

>    if($line=~m|/\*|){
>        $line=~s|/\*|\<i\>/\*|;
>    }

You're testing too much. You're doing the same match in both your m//
and your s///. You just need the s///; if nothing is matched, nothing
happens. And you don't need so many backslashes.

    $line=~s|/\*|\<i\>/\*|;
or
    $line=~s|/\*|<i>/*|;

>    if($line=~m|\*/|){
>        $line=~s|\*/|\*/\</i\>|;
>    }

    $line=~s|\*/|*/</i>|;

>    # C++
>    if($line=~m|//|){
>        $line=~s|//|\<i\>//|;
>        $line=~s|\n|\</i\>\n|;
>    }

Use the success of the first substitution to decide of you want to
continue:

    $line=~s|//|<i>//| and $line=~s|\n|</i>\n|;

>    # Scheme
>    if ($line=~m|;;|) {
>        $line=~s|;;|\<i\>;;|;
>        $line=~s|\n|\</i\>\n|;
>    }

    $line=~s|;;|<i>;;| and $line=~s|\n|</i>\n|;

These last two cases can be reduced even further, by doing just one
substitution. Note that /./ matches anything but a newline.

C++:
	$line =~ s|(//.*)|<i>$1</i>|;

Scheme:
	$line =~ s|(;;.*)|<i>$1</i>|;


p.s. You sufficiently took care of html-encoding special characters,
most notably "&" and "<", I hope?

-- 
	Bart.


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

Date: Tue, 5 Sep 2000 20:16:45 +0200
From: "Raphael Pirker" <raphaelp@nr1webresource.com>
Subject: Re: World Wide PERL PROGRAMMERS TELECOMMUTE
Message-Id: <8p3d82$ddg$17$1@news.t-online.com>

>   P> $15.00 to $25.00 per hour commensurate with experience.
consider adding a 0 to your offer or you won't get any programmer!




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

Date: Tue, 05 Sep 2000 14:14:56 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: World Wide PERL PROGRAMMERS TELECOMMUTE
Message-Id: <39B54630.469566FA@rac.ray.com>

Raphael Pirker wrote:
> 
> >   P> $15.00 to $25.00 per hour commensurate with experience.
> consider adding a 0 to your offer or you won't get any programmer!

I happen to know that Drew needs a job and he'll work for $15.000 to
$25.000. (US, where that's a decimal point)

-- 
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747

Quae narravi, nullo modo negabo. - Catullus


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

Date: Tue, 05 Sep 2000 12:30:48 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: World Wide PERL PROGRAMMERS TELECOMMUTE
Message-Id: <39B549E8.15AED7F9@stomp.stomp.tokyo>

Uri Guttman idiotically blathers:
 
> > P  writes:
 
>   P> $15.00 to $25.00 per hour commensurate with experience.
 
> HAHAHAHAHHAHAHAAHAH!!
 
> go hire moronzilla. most money she will ever make. and pay her 
> at the bottom of your scale. you won't be getting your money's
> worth even then.


As you know, Mr. Buttman, at age forty and some odd months,
I am retired. I have no need for employment. As it is, between
my twenty year old daughter and myself, our net liquidable
worth, this year, is one point four million dollars.

How are you doing financially?


Godzilla!
--
Stereotypical Perl Monger.
  http://la.znet.com/~callgirl/monger.cgi


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

Date: Tue, 05 Sep 2000 21:34:30 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: World Wide PERL PROGRAMMERS TELECOMMUTE
Message-Id: <x7aedmmska.fsf@home.sysarch.com>

>>>>> "G" == Godzilla!  <godzilla@stomp.stomp.tokyo> writes:

  >> go hire moronzilla. most money she will ever make. and pay her 
  >> at the bottom of your scale. you won't be getting your money's
  >> worth even then.

  G> As you know, Mr. Buttman, at age forty and some odd months,
  G> I am retired. I have no need for employment. As it is, between
  G> my twenty year old daughter and myself, our net liquidable
  G> worth, this year, is one point four million dollars.

so why are you here instead of being a typical rich bitch somewhere
else? if you don't get it, you are not wanted here.

  G> How are you doing financially?

just fine, thanx for asking.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Tue, 05 Sep 2000 19:05:05 GMT
From: cfedde@u.i.sl3d.com (Chris Fedde)
Subject: Re: write a file in an array
Message-Id: <Btbt5.53$uMh.170638336@news.frii.net>

In article <39A4E1BE.327AE912@delta.de>,
Ralf Heydenreich  <heydenreich@delta.de> wrote:
>sorry, I'm never been here. Perhaps it's better to learn BASIC at first
>:)
>
>Ralf Heydenreich schrieb:
>

Perl is a GREAT language to use if you are trying to learning
programming.  If only it had been around when I was learning using
msbasic, zilog assembler and Ratfor :-)

I'd recommend picking up Randal Schwartz book "Learning Perl".
There are many other titles out there but I can't vouch for them
personally since I've never used them.

chris
-- 
    chris fedde
    303 773 9134


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

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


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

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 V9 Issue 4229
**************************************


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