[18193] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 361 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 26 21:06:02 2001

Date: Mon, 26 Feb 2001 18:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <983239512-v10-i361@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 26 Feb 2001     Volume: 10 Number: 361

Today's topics:
    Re: Any tips on creating file records from a web form? <um@no.com>
    Re: Any tips on creating file records from a web form? <dersgniw@fuse.net>
    Re: Any way to modify a script while executing it? (Tony L. Svanstrom)
    Re: Array length (Victor Eijkhout)
        Help deciphering Perl code (Falc2199)
    Re: Help deciphering Perl code <juex@deja.com>
        HELP needed on a simple Parse::RecDescent program (prob <ekliao@hotmail.com>
    Re: HELP needed on a simple Parse::RecDescent program ( (Randal L. Schwartz)
    Re: HELP needed on a simple Parse::RecDescent program ( <ren@tivoli.com>
    Re: Help with sockets <um@no.com>
        How do I test whether a CODE reference is an NOP? <johnlin@chttl.com.tw>
        local vs. global context <jhall@ifxonline.com>
    Re: local vs. global context egwong@netcom.com
    Re: local vs. global context <um@no.com>
    Re: Please Help with 10 line programm -- beginner quest <callgirl@la.znet.com>
    Re: Please Help with 10 line programm -- beginner quest <bart.lateur@skynet.be>
    Re: Please Help with 10 line programm -- beginner quest (Mark Jason Dominus)
    Re: Please Help with 10 line programm -- beginner quest <callgirl@la.znet.com>
    Re: Please Help with 10 line programm -- beginner quest (John Joseph Trammell)
        print "problem" (Was: Re: local vs. global context) (Tony L. Svanstrom)
    Re: question on how to code a program <c_clarkson@hotmail.com>
    Re: question on how to code a program (Steven Smolinski)
    Re: receiving piped input??? <um@no.com>
    Re: regexp clarification (Martien Verbruggen)
    Re: shell script to perl (NEWBIE) egwong@netcom.com
    Re: Simple question about change of base (James Weisberg)
        Somewhat complicated hash from DB question <dersgniw@fuse.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 26 Feb 2001 20:30:28 -0800
From: "Ben L." <um@no.com>
Subject: Re: Any tips on creating file records from a web form?
Message-Id: <3a9b057d$1_2@news2.one.net>

If you are only concerned with keeping the data in a flat text file - a
common practice is to take all the data from the form fields and simply
write them to a file with a delimiter (a pipe | is commonly used) between
the fields.  There are a few things to keep in mind that can trip you up:

1. Remove all newlines from your form data so they don't mess up your flat
file.
2. Make sure you either a. check any possible HTML tags to make sure they
are complete or b. remove < and > from form input - reason is that a signle
< or > *might* get into your file, then later when you retrieve and print it
out, your html may be broken and not display correctly.
3.  Remove delimiter characters | from the form input ... it will cause
problems when you try to read it later.
4. If you use CGI.pm to parse to get your query string great ... if not then
remember you need to translate some characters back to their correct for
(like ? for example)

That should be about it ... this method of simply using a flat text file is
fine if you need a simple quick solution and you don't need anything
complicated.  How many users will be using this script and is it possible
that they will do it at the same time?  Concurrent access is a problem on
simple systems like this ... if you know you will have many people all using
it at once, you have to implement some sort of locking scheme so that data
is not lost during concurrent read/write.




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

Date: Mon, 26 Feb 2001 20:44:35 -0500
From: "Brian" <dersgniw@fuse.net>
Subject: Re: Any tips on creating file records from a web form?
Message-Id: <t9m1fhcnho1417@corp.supernews.com>

I know how to get the info from the form.  I'm trying to figure out a good
way to store that data depending on the name of the field it belongs to.

"Ilmari Karonen" <iltzu@sci.invalid> wrote in message
news:983217282.27707@itz.pp.sci.fi...
> In article <t9l6gtmih3dke9@corp.supernews.com>, Brian wrote:
> >
> >Let's say I've got form input fields of "information" "email" and "misc".
> >
> >What is a good way to create a record that would hold this info and then
> >read it?  I'd rather not use any modules as not many are installed on our
> >machine.  Also, I suppose I'd have to remove all newlines so a new record
> >won't span multiple lines.  Should I just replace all "\n" with <br>?
How
> >can I delimit these records?
>
> Well, you do have CGI.pm, right?  And I hope you're already using it.
>
> Take a look at the query_string() method.  The returned value should
> be one line of ASCII text, and you can turn it back into a CGI object
> by passing it to CGI->new().
>
> Depending on your needs, the save() method can also be useful.
>
> --
> Ilmari Karonen - http://www.sci.fi/~iltzu/
> "Control: cmsg newgroup sci.math.tasteless"  -- Red Drag Diva in the
monastery
>
> Please ignore Godzilla and its pseudonyms - do not feed the troll.




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

Date: Mon, 26 Feb 2001 23:13:59 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Any way to modify a script while executing it?
Message-Id: <1epgo49.wzvbpffupdfaN%tony@svanstrom.com>

Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:

> I was shocked! How could Dick <donkan7@yahoo.com>
> say such a terrible thing:
> 
> >Each time I run this it of course says the default is 33. What I'd like
> >to be able to do is to have a change in the default value "stick". For
> >example
> 
> Language War!!! I just want to point out that in AppleScript (shudder) if
> you declare a variable as a "property" variable instead of a normal
> variable type then you get persistence by default and whatever value it
> has at the termination of the script sticks...just like cr*p sticks to a
> wall. This is about the only really nice feature of that horrible blight
> of a language I can remember. Okay off-topic episode is over, back to your
> normal everyday programming everyone, nothing to see here.

And I remember how those values could be found in the program (easily
with resedit) even after you'd replaced them... I don't have to add that
I'd sent it to someone and that it was my username and password that was
still there, do I?!


When it comes to code that's rewriting itself... I remember a guy that
asked about porting (and switiching to C[++]) a program written in
assembly that had been rewriting (optimizing) itself for quite some time
(I think the last programmer that'd touched that program had been gone
for 10 years, or so). I actually laughed when I heard him ask for help.
;-)


        /Tony


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

Date: Mon, 26 Feb 2001 18:59:25 -0500
From: victor@eijkhout.net (Victor Eijkhout)
Subject: Re: Array length
Message-Id: <1epg9ti.12lzqn9s0g8wfN%victor@eijkhout.net>

Uri Guttman <uri@sysarch.com> wrote:

> if $a{b} is an array REF (it can't be an array),

Apperently. I don't notice that much: Perl makes it too easy to just
write $a{b}[2] and I can just pretend it's a multi-dimensional array and
don't have to think about how that is implemented.

> then you should read perlref for how to handle refs.

From the state of the perl docs you'd think that it *hurts* to put all
information conveniently together.

Anyway. Thanks for the responses everyone.

-- 
Victor Eijkhout
"the time comes for everyone to do deliberately what 
he used to do by mistake"  [Quentin Crisp]


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

Date: 27 Feb 2001 01:01:58 GMT
From: falc2199@aol.comNOJUNK (Falc2199)
Subject: Help deciphering Perl code
Message-Id: <20010226200158.02634.00000064@ng-ct1.aol.com>



The following code selects a line randomly from a file....

while (<FILE>)
{
  if (rand($.) < 1) 
{
   $line = $_;
}

}

Can someone please explain to me how this code is working? 

If you can not decipher the entire thing, can you tell me what '$.' is?
How would rand react to it?

Thanks in advance for any help,
Falc


To e-mail, remove NOJUNK


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

Date: Mon, 26 Feb 2001 17:14:00 -0800
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: Help deciphering Perl code
Message-Id: <3a9aff57$1@news.microsoft.com>

"Falc2199" <falc2199@aol.comNOJUNK> wrote in message
news:20010226200158.02634.00000064@ng-ct1.aol.com...
> The following code selects a line randomly from a file....
>
> while (<FILE>)
> {
>   if (rand($.) < 1)
> {
>    $line = $_;
> }
> }
>
> Can someone please explain to me how this code is working?
>
> If you can not decipher the entire thing, can you tell me what '$.' is?

Stolen from perldoc perlvar:
    $.      The current input record number for the last file handle from
            which you just read() (or called a `seek' or `tell' on). The
            value may be different from the actual physical line number in
            the file, depending on what notion of "line" is in effect--see
            `$/' on how to change that. An explicit close on a filehandle
            resets the line number. Because `<>' never does an explicit
            close, line numbers increase across ARGV files (but see examples
            in the eof entry in the perlfunc manpage). Consider this
            variable read-only: setting it does not reposition the seek
            pointer; you'll have to do that on your own. Localizing `$.' has
            the effect of also localizing Perl's notion of "the last read
            filehandle". (Mnemonic: many programs use "." to mean the
            current line number.)

> How would rand react to it?

Stolen from perldoc perlfunc:
 rand EXPR
    rand    Returns a random fractional number greater than or equal to `0'
            and less than the value of EXPR. (EXPR should be positive.) If
            EXPR is omitted, the value `1' is used. Automatically calls
            `srand' unless `srand' has already been called. See also
            `srand'.





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

Date: 26 Feb 2001 17:32:09 -0600
From: Eric Liao <ekliao@hotmail.com>
Subject: HELP needed on a simple Parse::RecDescent program (problem: some rules are matched twice)
Message-Id: <unml9toho76r6k6jev6dmkvaq7tk29lqes@4ax.com>

Hi All,

I am a new user of Parse::RecDescent.  I tried to use v1.80 to
implement a simple parser with a simple grammar for parsing c/c++/java
code.  The result looks good except that 5 rules seem to be matched
twice (see output and expected output below).  I could not figure out
why.  Any help would be greatly appreciated.  Please e-mail
ekliao@hotmail.com or post to the groups.  Thank you.

Regards,

Eric Liao



Code here:
=======================================================================
use strict;
use Parse::RecDescent;

$::RD_AUTOACTION = q {
			for ($::i = 0; $::i<= $#item; $::i++) {
				print "($::i) $item[$::i] ";
			}
					print "\n";
		};

$::grammar = q{

program		:	BRACE_LEFT statement(s) BRACE_RIGHT

statement	:   	expression SEMICOLON

expression	:	unary_expr PLUS_OP expression
		        |	unary_expr

unary_expr	:	UNARY_OP unary_expr
			|	brack_expr

brack_expr	:	PAREN_LEFT expression PAREN_RIGHT
			|	token_expr
			
token_expr	:	constant
			|	IDENTIFIER
			
constant	:	NUMBER
			|	STRING

SEMICOLON	:	';'
BRACE_LEFT	:	'{'
BRACE_RIGHT	:	'}'
UNARY_OP	:	'-'
PLUS_OP		:	'+'
			|	'-'
PAREN_LEFT	:	'('
PAREN_RIGHT	:	')'
NUMBER		:	/\\d+/
STRING		:	/"[^"\\\\]+(\\\\.[^"\\\\]*)*"/
IDENTIFIER	:	/[a-z]\\w*/i

};

my $parser = new Parse::RecDescent($::grammar)  or  die "invalid
grammar";
undef $/;
my $text = <DATA>;
defined $parser->program($text) or die "malformed program";

__DATA__
{
   "hello";
}

================================================================
Actual output:

(0) BRACE_LEFT (1) {
(0) STRING (1) "hello"
(0) constant (1) 1
(0) token_expr (1) 1
(0) brack_expr (1) 1
(0) unary_expr (1) 1
(0) STRING (1) "hello"
(0) constant (1) 1
(0) token_expr (1) 1
(0) brack_expr (1) 1
(0) unary_expr (1) 1
(0) expression (1) 1
(0) SEMICOLON (1) ;
(0) statement (1) 1 (2) 1
(0) BRACE_RIGHT (1) }
(0) program (1) 1 (2) ARRAY(0x1d1fecc) (3) 1

===========================================
Expected output:

(0) BRACE_LEFT (1) {
(0) STRING (1) "hello"
(0) constant (1) 1
(0) token_expr (1) 1
(0) brack_expr (1) 1
(0) unary_expr (1) 1
(0) expression (1) 1
(0) SEMICOLON (1) ;
(0) statement (1) 1 (2) 1
(0) BRACE_RIGHT (1) }
(0) program (1) 1 (2) ARRAY(0x1d1fecc) (3) 1


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

Date: 26 Feb 2001 15:59:00 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: HELP needed on a simple Parse::RecDescent program (problem: some rules are matched twice)
Message-Id: <m1wvad9et7.fsf@halfdome.holdit.com>

>>>>> "Eric" == Eric Liao <ekliao@hotmail.com> writes:

Eric> I am a new user of Parse::RecDescent.  I tried to use v1.80 to
Eric> implement a simple parser with a simple grammar for parsing c/c++/java
Eric> code.  The result looks good except that 5 rules seem to be matched
Eric> twice (see output and expected output below).  I could not figure out
Eric> why.  Any help would be greatly appreciated.  Please e-mail
Eric> ekliao@hotmail.com or post to the groups.  Thank you.

You can't print out your result while you are parsing it, because you
can't "unprint" a backtrack.  You backtracked in "expression" from the
first subrule to the second subrule, but you'd already printed out the
result of a successful first step of that first subrule.

Don't do that. Pass the data upstairs, and have the final top-level
rule do all the work.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 26 Feb 2001 17:49:17 -0600
From: Ren Maddox <ren@tivoli.com>
Subject: Re: HELP needed on a simple Parse::RecDescent program (problem: some rules are matched twice)
Message-Id: <m3snl1knsy.fsf@dhcp9-175.support.tivoli.com>

On 26 Feb 2001, ekliao@hotmail.com wrote:

> expression	:	unary_expr PLUS_OP expression
> 		        |	unary_expr

Here you have a rule with two productions that both start off the same
way.  Each production is attempted in order.  In the case of your
actual data:

> __DATA__
> {
>    "hello";
> }

The first production fails, and then the parser back-tracks and tries
the second production.  Since you are printing the data for every
production, you see the productions that comprise this failed
attempt.  This explains the extra output you saw.

Here is the relevant section from the docs:

       Note that this behaviour is quite different from the
       "prefer the longer match" behaviour of yacc. For example,
       if yacc were parsing the rule:

               seq : 'A' 'B'
                   | 'A' 'B' 'C'

       upon matching "AB" it would look ahead to see if a 'C' is
       next and, if so, will match the second production in
       preference to the first. In other words, yacc effectively
       tries all the productions of a rule breadth-first in
       parallel, and selects the "best" match, where "best" means
       longest (note that this is a gross simplification of the
       true behaviour of yacc but it will do for our purposes).

       In contrast, `Parse::RecDescent' tries each production
       depth-first in sequence, and selects the "best" match,
       where "best" means first. This is the fundamental
       difference between "bottom-up" and "recursive descent"
       parsing.

HTH...
-- 
Ren Maddox
ren@tivoli.com


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

Date: Mon, 26 Feb 2001 20:09:29 -0800
From: "Ben L." <um@no.com>
Subject: Re: Help with sockets
Message-Id: <3a9b0092$1_2@news2.one.net>

The problem is you are trying to send and receive through the same socket in
the same process.  In the words of the Perl gods you should only attempt
that if you are a real wizard, or if you are really into pain.  What you
need to do is modify your scirpt to fork an identical copy of itself ...
with the parent reading the socket and the child writing to it (or
vice-versa) ... that is the only way to accomplish the bi-directional
communication you desire while remaining sane.  There is some excellent
sample code for this in the IPC (inter-process communication) tutorial:

http://www.perl.com/pub/doc/manual/html/pod/perlipc.html

Check out the interactive client example under the TCP with IO::Socket
section.  Enjoy!

Ben


Dennis Kowalski <dennis.kowalsk@daytonoh.ncr.com> wrote in message
news:3a9a7571$1@rpc1284.daytonoh.ncr.com...
> I am trying to write a script that connects to a server program, send data
> to it and get output back.
>
> I have a C program that does it, but now I am trying in Perl.
>
> I seem to connet to the server module OK.
>
> I build a message and send it.
>
> Then I receive off of the socket.
>
> The data I get, seems to be what I sent
>
> Can anybody look at the following code and tell me what is wrong?
>
> Doe anybode have some sample code that des what I am trying to do?
>
> SAMPLE CODE
>
> use IO::Socket;
>
> $port = '18059';
> $ip = 'IP ADDRESS WAS HERE';
> my $socket = new IO::Socket::INET (PeerAddr => $ip,
>            PeerPort => $port,
>            Proto => 'tcp')
>   or die "Can not connect to server.\n";
> $socket->autoflush(1);
>
>   # msg is built here
>
>   # send the msg to the server
>   print $socket $output_rec;
>
>   &read_socket;
>   exit;
>
> # routine to read the socket
> sub read_socket
> {
>  # read 2 byte vli, unpack it and subtract 2
>  $rcvrec = read ($socket,$vlib,2);
>  $vli = unpack("n",$vlib);
>  $vli2 = $vli -2;
>
>  $buffin = 0;
>
>  # read data portion from the socket
>
>  $rcvrec = read ($socket,$buffin,$vli2);
>  if ($buffin)
>  {
>    print RCV $vlib;
>    print RCV $buffin;
>  }
>  0;
> }
>
>
>
>




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

Date: Tue, 27 Feb 2001 09:46:27 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: How do I test whether a CODE reference is an NOP?
Message-Id: <97f199$7b0@netnews.hinet.net>

Dear all,

I mean NOP by sub {}
How do I test if a CODE reference is a NOP?

if(!defined $code) { print 'undefined' }
elsif($code eq 'sub {}') { print 'defined but no operation' }
# Pseudo code, of course, not working


By the way, applying the same question, how do I test whether
a CODE reference is doing 'exit'?

my $code1 = \&exit;
my $code2 = sub {exit};
if($code1 eq \&exit) { print "code1 eq 'exit'\n" }
else { print "code1 ne 'exit'\n" }
if($code1 eq $code2) { print "code1 $code1 eq code2 $code2\n" }
else { print "code1 $code1 ne code2 $code2\n" }

__END__
code1 eq 'exit'
code1 CODE(0x1bef1a4) ne code2 CODE(0x1be23b0)


Then, another question is aroused by association:
Is there an nop function (built-in) such that

\&exit  v.s.  sub {exit}  ::=  \&nop  v.s.  sub {}


Thank you very much.

John Lin





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

Date: Tue, 27 Feb 2001 01:06:29 GMT
From: "John Hall" <jhall@ifxonline.com>
Subject: local vs. global context
Message-Id: <p4Dm6.62253$Xj4.3208244@news1.rdc1.sdca.home.com>

This is probably  a silly newbie question, but I am unable to find the
[probably simple] answer in any of the material suggested by this fine list:

If I declare a local variable in a subroutine via "my $variable" but then in
the same subroutine I want to access another variable, from the meat of the
program also named $variable, how do I do that?




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

Date: 27 Feb 2001 01:41:55 GMT
From: egwong@netcom.com
Subject: Re: local vs. global context
Message-Id: <97f0l3$q9k$1@newssvr06-en0.news.prodigy.com>

John Hall <jhall@ifxonline.com> wrote:
> This is probably  a silly newbie question, but I am unable to find the
> [probably simple] answer in any of the material suggested by this fine list:
> 
> If I declare a local variable in a subroutine via "my $variable" but then in
> the same subroutine I want to access another variable, from the meat of the
> program also named $variable, how do I do that?

It's not a Silly Newbie Question, but it is a faq:

  How can I access a dynamic variable while a similarly named
  lexical is in scope?

HTH,
ERic


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

Date: Mon, 26 Feb 2001 20:48:18 -0800
From: "Ben L." <um@no.com>
Subject: Re: local vs. global context
Message-Id: <3a9b09ad$1_1@news2.one.net>

> If I declare a local variable in a subroutine via "my $variable" but then
in
> the same subroutine I want to access another variable, from the meat of
the
> program also named $variable, how do I do that?
>
   I'm not sure what kind of program you write that has meat :)  Variables
decalred using my are "lexically scoped" - that means they only exist inside
the current subroutine or block, when the program steps outside of that
subroutine or block they cease to exist.  If you want to access a
non-lexically scoped variable that was used in a global space while you are
inside a subroutine - you have to include the package name: $Package::foo.
In a plain ole perl script your package is "main".  Here is an example:

#!/apps/perl/bin/perl

$foo = "I'm in main\n";

&hidden;

sub hidden{
   my $foo = "I'm in subroutine!\n";

   print "my lexicaly scoped foo: ",$foo;
   print "my gloabl foo: ", $main::foo;
}





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

Date: Mon, 26 Feb 2001 16:10:40 -0800
From: Kiralynne Schilitubi <callgirl@la.znet.com>
Subject: Re: Please Help with 10 line programm -- beginner questions  Thanks Guys
Message-Id: <3A9AF080.B6135E58@la.znet.com>

"Randal L. Schwartz" wrote:
 
> >>>>> "Kiralynne" == Kiralynne Schilitubi wrote:


* growls *

Too many arrows in yours and Uri's quoting style.
This is not neat, crisp, clean and concise.

Hey check it out! I actually have a real email
address which works, unlike so many others here.

(someone else wrote:)

> > > What do you mean "using strict"?
 
> > A realistic definition for strict
> > would be,
 
> > "Bloat my program's memory usage,
> >  cause my program to run slower,
> >  make my program as difficult as
> >  possible to write along with
> >  causing it to crash often."
 
> With all the stuff you've learned over the past year,
> Kira, I'm amazed at how you still act like a luddite
> about some of Perl's core features.

Oh, I am far from a luddite. My programs available
for use on my homesite dispel any notion my big butt
keeps me firmly attached to terra firma, although
I do terra pair of jeans at times and my worst end
is not considered firma.

I've been involved with Perl more than a year, my
dear Randall. 
 
> > The author of the strict module indicates, paraphrased, a
> > careful choice should be made before using strict. Use of
> > strict is not appropriate for many programs.
 
> Are you misreading this statement (from perldoc strict):
 
>        If no import list is supplied, all possible restrictions
>        are assumed.  (This is the safest mode to operate in, but
>        is sometimes too strict for casual programming.)
>        Currently, there are three possible things to be strict
>        about:  "subs", "vars", and "refs".
 
> Perhaps you're confusing "casual programming" with "many programs".
> Most of the programs I write are not in the "casual programming"
> category, and in fact Stonehenge's official position on "strict" is
> "anything that exceeds 10 lines or 10 minutes of use or we get paid
> more than $10 for must use strict".  That's at least 90% of what I
> write.

Not misreading his notes at all. He is clearly sending a signal,

"Think twice before using strict."

Casual programming, in my personal perspective, are programs
ranging from one thousand lines to two-thousand lines. My
chat is just over three-thousand-five-hundred lines. This one
I would catagorize as a 'moderate' size program. Almost all
scripts I have looked at, have read, available on our net
as freebies, are very casual scripts. Matt's scripts, as
an example, are casual scripts. It is logical and statistics
show, most Perl scripts used by average people, are casual
scripts. It is equally logical then to consider "many"
scripts as casual. Thus, the strict module author is
making reference to many scripts.

Here is what I consider an extremely casual program I wrote
for some yahoo over in comp.lang.perl who has never bothered
to download it,

http://la.znet.com/~callgirl/sample.html

This one is about thirty to sixty minutes work for me.
Quite casual, nothing impressive and, a freebie. It
does not employ strict, natually. Use of strict never
entered my thoughts for a script this easy, this casual.

* curses *

Annoys me when people ask for help and never bother
to check back.

 
> > Strict is analogous to training wheels on a bicycle.
 
> No, more like rear view mirrors.  There are very few things that a
> high-performance program will want to do that "use strict" prevents,
> and even so, it can be disabled for any chunk of code in a controlled
> fashion.

I would debate module use in general. You know my stance is
better programmers write their own code and avoid modules.
Memory bloat is a certainty. Some modules are very efficient
about memory use, others are abhorrent. Speed is also an issue.
A module will always slow down a script and, like memory use,
this speed slow down can be insignificant or very noticable.
Programmers need to carefully consider if a module is actually
needed or, perhaps, if module use is a lazy person's crutch.

Nonetheless, some commercial ventures do warrant module
use for cheap low quality knock-out coding. We all like
to turn a profit with as little effort as possible.

Returning to strict, having to pre-declare variables is not
efficient. Declaring a variable upon first use, is efficient.
Turning strict on and off, as needed, is not efficient. Writing
scripts which have no need for strict, is efficient along with
a display of programming talent. I never use strict. It isn't
I am all that talented. It is strict will not allow many shortcuts
used in my programs and, will not allow bending of rules for
more efficient scripts.

My position is, as stated many times, strict is a useful tool
for beginning programmers or programmers lacking confidence.
Strict only serves one purpose; catching mistakes. A person
should work towards developing an ability to write scripts
which are relatively error free and, develop an ability to
a degree where strict is no longer a crutch. Strict removes
motivation to develop better abilities.

Strict is training wheels on a bicycle. Strict is 18 wheeler
mirrors on a Corvette. Stict is my attitude when my girl
goes out with a guy, well, strict module is not that strict.

 
> Kira, you are clearly learning.

Learning along with teaching a yahoo or two around
here a few lessons.

> Your posts keep including more and  more interesting
> Perl knowledge.

Well, I have to dish out my imaginative programming
a little at time for you boys, lest you suffer
vigorous gray matter spontaneous combustion.

KAAAA..BOOM!

heh.. heh..


>  But please give up your hold on
> "anything modern is bloated". 
> That's a long-dead battle.

You misspelled "module".


Godzilla!


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

Date: Tue, 27 Feb 2001 00:25:11 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Please Help with 10 line programm -- beginner questions  Thanks Guys
Message-Id: <fpsl9tc7cgssjma1n0gu509b7ev1t82ic3@4ax.com>

Kiralynne Schilitubi wrote:

>> What do you mean "using strict"?
> 
>A realistic definition for strict
>would be,
>
>"Bloat my program's memory usage,
> cause my program to run slower,
> make my program as difficult as
> possible to write along with 
> causing it to crash often."

Not true. "strict" ONLY has an effect on the parsing of the program.
Once compiled, the program will run exactly just as fastwith as without
"strict". As for crashing, the same applies: the compiled code is
exactly the same, so there's not one single reason on why it should
crash more often.

Yes, your program can become more difficult to write, especially if it
was supposed to be a very short program. "strict" forces you to write a
whole elaborate introduction on who is who, instead of letting you jump
right in the middle of the action.

-- 
	Bart.


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

Date: Tue, 27 Feb 2001 00:29:10 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Please Help with 10 line programm -- beginner questions  Thanks Guys
Message-Id: <3a9af4d5.3c50$3e3@news.op.net>
Keywords: Floridian, Trudy, anise, caiman

In article <fpsl9tc7cgssjma1n0gu509b7ev1t82ic3@4ax.com>,
Bart Lateur  <bart.lateur@skynet.be> wrote:
>Not true. "strict" ONLY has an effect on the parsing of the program.

strict 'refs' has a run-time effect.  The other two are compile-time only.
-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Mon, 26 Feb 2001 18:01:15 -0800
From: Kiralynne Schilitubi <callgirl@la.znet.com>
Subject: Re: Please Help with 10 line programm -- beginner questions  Thanks Guys
Message-Id: <3A9B0A6B.F87C2AD0@la.znet.com>

Bart Lateur wrote:
 
> Kiralynne Schilitubi wrote:
 
> >> What do you mean "using strict"?

> >A realistic definition for strict
> >would be,

> >"Bloat my program's memory usage,
> > cause my program to run slower,
> > make my program as difficult as
> > possible to write along with
> > causing it to crash often."
 
> Not true. "strict" ONLY has an effect on the parsing of the program.
> Once compiled, the program will run exactly just as fastwith as without
> "strict". As for crashing, the same applies: the compiled code is
> exactly the same, so there's not one single reason on why it should
> crash more often.

This is untrue. My tests show a significant average 1.64 percent slow
down of a script using a very simple code snippet. This is only for 
one snippet. In a casual or a moderately complex script, this percentage
slow down could range up to five percent, ten percent or more in
some cases. This is not a direct reflection on memory usage. My
hunch is use of strict consumes memory to a more significant degree
than shown by average slow down. Tests are below my signature.
This percentage slow down, this increase in memory consumption,
would increase considerably if a program turns strict on and off
during the course of the script, as well. Bottom line is use of
strict slows a script, uses more memory and, this degradation
of a program would increase with complexiety.

You should know by now, I * always * do my homework before
making any statement which is to be taken as factual.

 
> Yes, your program can become more difficult to write, especially if it
> was supposed to be a very short program. "strict" forces you to write a
> whole elaborate introduction on who is who, instead of letting you jump
> right in the middle of the action.

Much worse. Use of strict causes pragma hints to report false
and misleading error messages. This is what happens with strict
in use for my example snippet below my signature, when lacking
a correct my declaration,

Global symbol "$ilabika" requires explicit package name at... line 7.
Global symbol "$ilabika" requires explicit package name at... line 12.
Global symbol "$ilabika" requires explicit package name at... line 14.
Execution of test4.pl aborted due to compilation errors

Pragma warning indicates a total of three errors on various
lines. Reality dictates $ilabika only needs to be a my declaration
on line 7, to correct this error, when using strict. These messages
are misleading and would certainly confuse a beginner programmer.

As I have said many times, use of strict is good for beginners,
this does help. However, nowhere in documentation are there
any explanations pragma warnings might be misleading or flat
out in error. So use of strict is good but a programmer needs
to know, there are problems associated with strict and warnings.

I have yet to read any Techno-Geekster regular populating this
group say, 

"Strict will slow down your script and use more memory. 
 Strict might cause misleading or erroneous error messages."

What I do read is Techno-Geeksters saying,

"You MUST use strict."


You never read me stating the latter but you will
read me being honest and stating the former.

Godzilla!

--

TEST SCRIPT:
____________

#!perl

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

use Benchmark;

print "Run 1:\n\n";

&Time;

print "\n\nRun 2:\n\n";

&Time;

print "\n\nRun 3:\n\n";

&Time;


sub Time

 {
  timethese (100000,
   {
    'name1' =>
    'use strict;
     my ($ilabika) = "Godzilla Rocks!";
     srand(time() ^ ($$ + ($$ << 15))); 
     sub nickrand
     { rand(40) < 20 ? "\u$1" : "\l$1"; }
     $ilabika =~  s/([a-z])/nickrand($1)/gie;',

    'name2' =>
    '$ilabika = "Godzilla Rocks!";
     srand(time() ^ ($$ + ($$ << 15))); 
     sub nickrand
     { rand(40) < 20 ? "\u$1" : "\l$1"; }
     $ilabika =~  s/([a-z])/nickrand($1)/gie;',
   }
  );
 }

exit;



PRINTED RESULTS:
________________

Run 1:

Benchmark: timing 100000 iterations of name1, name2...
name1: 30 wallclock secs (29.93 usr +  0.00 sys = 29.93 CPU) @ 3341.13/s
name2: 30 wallclock secs (29.83 usr +  0.00 sys = 29.83 CPU) @ 3352.33/s


Run 2:

Benchmark: timing 100000 iterations of name1, name2...
name1: 31 wallclock secs (30.98 usr +  0.00 sys = 30.98 CPU) @ 3227.89/s
name2: 31 wallclock secs (30.21 usr +  0.00 sys = 30.21 CPU) @ 3310.16/s


Run 3:

Benchmark: timing 100000 iterations of name1, name2...
name1: 30 wallclock secs (30.37 usr +  0.00 sys = 30.37 CPU) @ 3292.72/s
name2: 30 wallclock secs (29.77 usr +  0.00 sys = 29.77 CPU) @ 3359.09/s


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

Date: Mon, 26 Feb 2001 23:38:00 GMT
From: trammell@bayazid.hypersloth.net (John Joseph Trammell)
Subject: Re: Please Help with 10 line programm -- beginner questions
Message-Id: <slrn99lo18.rge.trammell@bayazid.hypersloth.net>

On Mon, 26 Feb 2001 16:38:25 -0500, Shane McDaniel <shanem@ll.mit.edu> wrote:
> Cool.  It's points like these that I like to tell people that "Every
> programming language will let you shoot yourself in the foot, however
> with perl you're using an automatic."

And what good is a gun that won't let you shoot yourself
in the foot if you want to, anyhow?  :-)



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

Date: Tue, 27 Feb 2001 02:01:20 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: print "problem" (Was: Re: local vs. global context)
Message-Id: <1epgw5m.fwtsd416psr4yN%tony@svanstrom.com>

<egwong@netcom.com> wrote:

> John Hall <jhall@ifxonline.com> wrote:
> > This is probably  a silly newbie question, but I am unable to find the
> > [probably simple] answer in any of the material suggested by this fine list:
> > 
> > If I declare a local variable in a subroutine via "my $variable" but then in
> > the same subroutine I want to access another variable, from the meat of the
> > program also named $variable, how do I do that?
> 
> It's not a Silly Newbie Question, but it is a faq:
> 
>   How can I access a dynamic variable while a similarly named lexical is
>   in scope?

I have to ask about this, because at 3 AM I just don't get it:

## start
$t = 2;
   {
      my $t = 1;
      print $main::t . "\n" . print $t;
   }
## end

and the output is:

## start
12
1
## end

Feel free to call me stupid, as long as you at the same time explain why
it seems to be printed like "$t$::t$t"?


        /Tony


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

Date: Mon, 26 Feb 2001 18:30:15 -0600
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: question on how to code a program
Message-Id: <C6ADA0C686F8AC05.AFB9AFA036E4167C.98F1093AD51E3CAE@lp.airnews.net>

"Abigail" <abigail@foad.org> wrote:
: Torque (gifg@netzero.netNOSPAM) wrote:
: ;; I'm trying to code a cgi program with perl to count the number of
: ;; years, months, days, hours, minutes, and seconds since a given date.
:
: There are a bunch of modules on CPAN that will help you do this.
:
: ;; I thought I could use Matt's Script archive's countdown.pl as an
: ;; example and try to get it to work backwards, but it just isn't working
: ;; out.  I've decided to scrap that and start over.
:
: The best way to deal with Matt's programs is to invent a time machine,
: go back into history and kill Matts parents before he was conceived.
: That would solve the Perl community from a big problem, in both the
: past, present and future.
:
    ROTFL, I knew someone would be unable to resist.

Charles K. Clarkson





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

Date: Tue, 27 Feb 2001 00:59:29 GMT
From: sjs@linux.ca (Steven Smolinski)
Subject: Re: question on how to code a program
Message-Id: <slrn99m3h8.jp.sjs@ragnar.stevens.gulch>

Abigail <abigail@foad.org> wrote:
> The best way to deal with Matt's programs is to invent a time machine,
> go back into history and kill Matts parents before he was conceived.
> That would solve the Perl community from a big problem, in both the
> past, present and future.

I was in my local bookstore, and saw a Perl/CGI book by Matt Wright.
The few pages I skimmed had a few errors, as suspected, and I was
putting it back with a snort when I saw a quote on the back.

The quote was from Randal!  It said that the book ought to be on every
programmer's bookshelf or some such glowing comment. 

Randal!  What's happened?  Did they threaten to kill your family?  If
you can't speak freely, rot13 your reply and we'll figure out a way to
get you and your loved ones to safe Switzerland!

At least, that's the only explanation for the quote I could come up
with.  I mean, they wouldn't take him out of context, would they?

Steve
-- 
Steven Smolinski => http://www.steven.cx/


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

Date: Mon, 26 Feb 2001 20:17:19 -0800
From: "Ben L." <um@no.com>
Subject: Re: receiving piped input???
Message-Id: <3a9b0269$1_1@news2.one.net>

> > How do I read the output from myprogram inside of myperlscript???
>
> open (CMD, "ls -al |"); # Pipe at the end of the command means that I am
>                         # reading from the command. If it were at the
> beginning,
>                         # - "| ls -al" - I could write in to the command
(of
> course
>                         # not 'ls -al')
> my @lsData = <CMD>;
> close (CMD);
>
> hth,
> M.
>

He isn't asking how to use a pipe inside perl ... his example was a shell
script piping output INTO his perl program ... although your information is
good and useful :)




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

Date: Tue, 27 Feb 2001 10:32:49 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: regexp clarification
Message-Id: <slrn99lpt1.1ug.mgjv@martien.heliotrope.home>

On 26 Feb 2001 14:57:12 GMT,
	Abigail <abigail@foad.org> wrote:
> Martien Verbruggen (mgjv@tradingpost.com.au) wrote on MMDCCXXXVI
> September MCMXCIII in <URL:news:slrn99kjlv.gro.mgjv@martien.heliotrope.home>:
> () 
> () Of course, if you don't have a computer, then you can't install Perl.
> () But then the question remains: What did you use to post to Usenet? And
> 
> Well, there's always webtv. And internet cafe's, terminals in shopping
> centra, and Burgerkings' "20 minutes of of internet with your value meal".

And if the OP answered either of those, then they would have answered my
question.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd.   | Then things get worse.
NSW, Australia                  | 


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

Date: 26 Feb 2001 23:08:57 GMT
From: egwong@netcom.com
Subject: Re: shell script to perl (NEWBIE)
Message-Id: <97enm8$5486$2@newssvr06-en0.news.prodigy.com>

terminalsplash <shino_korah@yahoo.com> wrote:
> 
> I was trying to convert a shell script *.sh to perl script.
> In the shell script the statement
> setenv THENAME  /dir1/file1
> in perl i used system("setenv THENAME  /dir1/file1);
> It says can't execute setenv..no such file or directory

Welcome to perl, I hope your stay in a pleasant one.

To do something similar to "setenv" in perl, use the %ENV hash.  In your
case, it will be

  $ENV{THENAME}='/dir1/file1';

see the perlvar manpage for details on %ENV.

For a list of builtin functions (i.e. *not* "setenv"), see perlfunc.
See perlsyn for syntax and perldata for the data types (the difference
between a $scalar and an @array and a %hash and what all of those
funny prefix's mean).

The standard recommended method for learning perl is to get the book
_Learning Perl_, although, really, with a little patience and
experimentation, you can figure a lot of it out from the bundled
documentation.

Good luck,
ERic


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

Date: Mon, 26 Feb 2001 23:55:38 GMT
From: chadbour@wwa.com (James Weisberg)
Subject: Re: Simple question about change of base
Message-Id: <_1Cm6.19249$Sl.843446@iad-read.news.verio.net>

In article <t9lk0ho6ver404@corp.supernews.com>,
Craig Berry <cberry@cinenet.net> wrote:
>James Weisberg (chadbour@wwa.com) wrote:
>: >Here's a simple question. I would like to convert a base 10 number
>: >into a base 32 number, i.e. [0-31] -> [0-9a-z] (lower case letters are
>: >preferable). Is there a simple way to do this in Perl? 
>: 	Doop! I mean a base 36 number! [0-35] -> [0-9a-z]. 


	Thanx to everyone who responded. I wasn't so lazy as to not be
able to write a piece of code using an array of the form:
		@digits = ( 0..9, 'a'..'z' );

	Instead I was thinking that there may have already been a utility
I was overlooking to do this (using a potentially arbitrary base). Of
course, I can't seem to count how many values are in [0-9a-z], so I
appreciate the routines you all have written. ;-)


-- 
World's Greatest Living Poster


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

Date: Mon, 26 Feb 2001 20:41:32 -0500
From: "Brian" <dersgniw@fuse.net>
Subject: Somewhat complicated hash from DB question
Message-Id: <t9m19q16r4dha0@corp.supernews.com>

I'm trying to create a hash from a database read.  I'm nesting the hash
using a couple of fields from the database and a counter.  I've been messing
around but can't get it to work.  I want to be able to populate it and then
read it...

$csr=&ora_open($lda,"select * from db_table");
while (@dbArray=&ora_fetch($csr)) {
    $cols = $csr->{NAME};
    for ($x; $x < @dbArray; $x++) {
        $blds{$dbArray[2]}{$dbArray[5]}{bldsInHere}++;
        $blds{$dbArray[2]}{$dbArray[5]}{bldsInHere}{$cols->[$x]} =
@dbArray[$x];
    }
}
# so a hash should look something like this -
# blds->column3->column6->numberOf These->col1{value}
# blds->column3->column6->numberOf These->col2{value}

foreach $org (keys %blds) {
    foreach $rel (keys $blds{$org}) {
        foreach $this (keys $blds{$org}{$rel}) {
            $x = $blds{$org}{$rel}{$this}{A_COLUMN}
        }
    }
}

Any advice would be greatly appreciated.

Regards,
Brian




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

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 V10 Issue 361
**************************************


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