[9596] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3190 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 17 18:07:24 1998

Date: Fri, 17 Jul 98 15:00:30 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 17 Jul 1998     Volume: 8 Number: 3190

Today's topics:
    Re: array parsing problem (Steve Linberg)
    Re: array parsing problem <mishra.aditya@emeryworld.com>
    Re: array parsing problem <mishra.aditya@emeryworld.com>
    Re: array parsing problem <yong@shell.com>
        Can a Crontab run perl script <whaidri@ford.com>
    Re: Can a Crontab run perl script (Steve Linberg)
    Re: Can a Crontab run perl script <yong@shell.com>
    Re: Can a Crontab run perl script (Cheng-Jih Chen)
    Re: Changing user from nobody to username <yong@shell.com>
    Re: Coding Quiz (was Re: efficiency: print<<"xxx" vs. p <*@qz.to>
        hash undef problem <shenge@ece.ucdavis.edu>
    Re: Help me on the if-then-else branch <hn7824@tntech.edu>
    Re: Help me on the if-then-else branch <joneil@cks.ssd.k12.wa.us>
    Re: I'm baffled.. (and an amateur:) <yong@shell.com>
    Re: I'm baffled.. (and an amateur:) (Steve Linberg)
    Re: I'm baffled.. (and an amateur:) <jdporter@min.net>
    Re: I'm baffled.. (and an amateur:) (Craig Berry)
    Re: I'm baffled.. (and an amateur:) (Larry Rosler)
    Re: mastering regular expressions <quinn@phoenix.net>
    Re: module forcing a reload of itself (a mod_perl quest <jdf@pobox.com>
    Re: Mutiple pattern searches (Larry Rosler)
    Re: newbie date format (Matt Knecht)
    Re: newbie date format (Larry Rosler)
    Re: On mixing (seek/tell) and (sysopen/syswrite) <kj0@mailcity.com>
    Re: Perl Beautifier Home Page (Leslie Mikesell)
    Re: persistent objects (Josh Blackwell)
    Re: Premature End of Script Header problem <yong@shell.com>
    Re: regexp help? <radin@ews.uiuc.edu>
    Re: RegExps: Check if string consists of EXACTLY 3 digi <mgregory@asc.sps.mot.com>
    Re: Sendmail ? <*@qz.to>
    Re: Strangness in for loop ?! <yong@shell.com>
    Re: system() return values <yong@shell.com>
    Re: system() return values <mishra.aditya@emeryworld.com>
        upload in CGI perl <rosadi@students.uiuc.edu>
    Re: Variables <yong@shell.com>
    Re: WARNING: Newbie Inquiry - PERL Architecture <quinn@phoenix.net>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Fri, 17 Jul 1998 16:03:36 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: array parsing problem
Message-Id: <linberg-1707981603360001@projdirc.literacy.upenn.edu>

In article <6oo8vl$il5$1@ocean.cup.hp.com>, "Gil Brown" <gil_brown@hp.com>
wrote:

> Hi;
> 
> I am trying to parse a line from a file by assigning it to an array. I need
> the 4th element of the line and sometimes it does not exist. When it doesn't
> exist perl complains about an uninitialized value but print the value
> whitout complaining if it's there. What am I missing?
> 
> use strict;
> use FileHandle;
> use diagnostics;
> 
> 
> my @data;
> my $fh = new FileHandle; # Create local filehandle
> open ($fh, "/home/gbrown/test/hqhp1") || die $!;
> while (defined(my $line = <$fh>))
> {
>         @data=split(/ +/,$line);
>          print "$data[3]\n";
> }

Ummm... so you're missing data in element 4?  Are you sure the incoming
data is valid?  What are your plans for when the data is invalid, as it
seems to be in this case?
_____________________________________________________________________
Steve Linberg                       National Center on Adult Literacy
Systems Programmer &c.                     University of Pennsylvania
linberg@literacy.upenn.edu              http://www.literacyonline.org


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

Date: Fri, 17 Jul 1998 12:54:35 -0700
From: "Mishra Aditya" <mishra.aditya@emeryworld.com>
Subject: Re: array parsing problem
Message-Id: <6ooa5g$l32@news.cnf.com>

>         print "$data[3]\n";
try replacing this line by
         print "$data[3]\n" if ($#data >= 3);

Adi




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

Date: Fri, 17 Jul 1998 12:55:40 -0700
From: "Mishra Aditya" <mishra.aditya@emeryworld.com>
Subject: Re: array parsing problem
Message-Id: <6ooa7f$l3i@news.cnf.com>

Try replacing          print "$data[3]\n"; by        print "$data[3]\n" (if
$#data > = 3);
Adi





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

Date: Fri, 17 Jul 1998 15:18:05 -0500
From: Yong Huang <yong@shell.com>
To: Gil Brown <gil_brown@hp.com>
Subject: Re: array parsing problem
Message-Id: <35AFB17D.F4B1F8B5@shell.com>

I don't understand your question. You're not missing anything. It's up to you to
make a decision what to do when it's not there. You can say instead "This time
the 4th element is not there" to your user.

Yong Huang

Gil Brown wrote:

> Hi;
>
> I am trying to parse a line from a file by assigning it to an array. I need
> the 4th element of the line and sometimes it does not exist. When it doesn't
> exist perl complains about an uninitialized value but print the value
> whitout complaining if it's there. What am I missing?
>
> use strict;
> use FileHandle;
> use diagnostics;
>
> my @data;
> my $fh = new FileHandle; # Create local filehandle
> open ($fh, "/home/gbrown/test/hqhp1") || die $!;
> while (defined(my $line = <$fh>))
> {
>         @data=split(/ +/,$line);
>          print "$data[3]\n";
> }
>
> Thank you.





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

Date: Fri, 17 Jul 1998 15:51:28 -0400
From: Wali Haidri <whaidri@ford.com>
Subject: Can a Crontab run perl script
Message-Id: <35AFAB40.6076@ford.com>

I wrote a perl (actually an oraperl) program. It runs as expected when
submitted from the command line. But when I run it from a crontab, it
does not work.

Thanks.


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

Date: Fri, 17 Jul 1998 16:41:31 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Can a Crontab run perl script
Message-Id: <linberg-1707981641310001@projdirc.literacy.upenn.edu>

In article <35AFAB40.6076@ford.com>, whaidri@ford.com wrote:

> I wrote a perl (actually an oraperl) program. It runs as expected when
> submitted from the command line. But when I run it from a crontab, it
> does not work.
> 
> Thanks.

You're welcome!

Do you have a question?  :)
_____________________________________________________________________
Steve Linberg                       National Center on Adult Literacy
Systems Programmer &c.                     University of Pennsylvania
linberg@literacy.upenn.edu              http://www.literacyonline.org


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

Date: Fri, 17 Jul 1998 15:41:47 -0500
From: Yong Huang <yong@shell.com>
To: whaidri@ford.com
Subject: Re: Can a Crontab run perl script
Message-Id: <35AFB70B.C89C1959@shell.com>

It should. Tell us more. What error? Try run it like this "myscript
>mylog".

I have an oraperl script running every midnight.

Yong Huang

Wali Haidri wrote:

> I wrote a perl (actually an oraperl) program. It runs as expected when
> submitted from the command line. But when I run it from a crontab, it
> does not work.
>
> Thanks.





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

Date: 17 Jul 1998 17:16:56 -0400
From: cjc@interport.net (Cheng-Jih Chen)
Subject: Re: Can a Crontab run perl script
Message-Id: <6oof08$ljg$1@interport.net>

In article <35AFAB40.6076@ford.com>, Wali Haidri  <whaidri@ford.com> wrote:
>I wrote a perl (actually an oraperl) program. It runs as expected when
>submitted from the command line. But when I run it from a crontab, it
>does not work.

Most likely, your environment isn't set properly through cron, i.e.,
ORACLE_HOME.  When running perl stuff like that from cron, I usual have
cron run a shell script that sets the environment, and invokes the perl
program at the end.




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

Date: Fri, 17 Jul 1998 15:20:36 -0500
From: Yong Huang <yong@shell.com>
To: dhawker@my-dejanews.com
Subject: Re: Changing user from nobody to username
Message-Id: <35AFB214.8FB68041@shell.com>

Your msg should really be sent to the unix web server group. The configuration
file on the server side contains the word nobody. The Web server administrator
can change it. In case of Apache. The line is in httpd.conf.

Yong Huang

dhawker@my-dejanews.com wrote:

> The web server is run as "nobody" and emails sent from a web script have
> nobody@host in the From. Is it possible, in perl, to change the identity to
> our username? Short of sending ourself an email to be processed by our mail
> server script which runs as our username.
>
> dhawker@bigfoot.com
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum





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

Date: 17 Jul 1998 20:08:57 GMT
From: Eli the Bearded <*@qz.to>
Subject: Re: Coding Quiz (was Re: efficiency: print<<"xxx" vs. print)
Message-Id: <eli$9807171605@qz.little-neck.ny.us>

In comp.lang.perl.misc, Uri Guttman  <uri@sysarch.com> wrote:
> 1. Who is main the PERSON you should think about while you are writing code?

The reader, same as with any other writing.

> 2. Other than comments, what is the most important HUMAN aspect of code?

Identifier names.

> 3. What is the main PURPOSE of comments?

To reenforce the statement through redundancy.

> Bonus: What is the OPPOSITE of spaghetti code?

Combed code.

> good luck and flame on!

Sure, I'll flame for each answer you mark wrong. :^)

Elijah
------
#!/usr/local/bin/perl5 -- # -*- my ny.pm sig -*-
$_=$^ ;s;s;sss;;s^.^ju^&&s&P+&\n&&&(s(_..)(ers)||s|^|^^|)&&s(T)(q(st%eg))eg;
s<.(o).><$& new 1$$>i+s+\dst.+$a--||reverse(q(rep k))+ge;s*%.+u* so+*i;s=\++
="me"=mex&&s%ege%l$"hke%;$a||s/^\S+ /\/\//;s;\d+;yor;;s[KE]<ac$&>i;print $_;


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

Date: 17 Jul 1998 21:33:06 GMT
From: Eric Sheng <shenge@ece.ucdavis.edu>
Subject: hash undef problem
Message-Id: <6oofui$7ov$1@mark.ucdavis.edu>

Hi all,

	I am using a hash of hash of hash in my script as follow:

$all_groups{$group_name}{$element_name}{$element_component} = "xyz";

what I need to do at one point is "undef" all the data structure under a
certain $element_name.  I am doing:

	undef $all_groups{$group_name}{$element_name}

but I believe it is not deleting the $element_name itself.  So after
the above line if I do:

	foreach $group_name (keys %all_groups) {
	    foreach $element_name (keys %{$all_groups{$group_name}}) {
		print("$element_name\n");
	    }
	}

I still see the "Element_name" I "undef" before.  What should I do?


Thanks!

--Eric


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

Date: Fri, 17 Jul 1998 16:08:47 -0500
From: Hari Natarajan <hn7824@tntech.edu>
To: lloyd <lloyd007@best.com>
Subject: Re: Help me on the if-then-else branch
Message-Id: <35AFBD5F.B89C9EA6@tntech.edu>

Hi Lloyd,
After the statement $name = <STDIN>; in your program, add the line "
chop($name);". It works.

Good luck
Hari

lloyd wrote:

> I am a total newcomer to the perl language. I bought the book Learning
> Perl and I have learned a lot already, but there is a small 9 line program
> that I cannot figure out.
>
> Here is the program:
>
> #!/usr/local/bin/perl -w
>
> print "What is your name?\n";
> $name = <STDIN>;
> if ($name eq "lloyd") {
>    print "Hi Lloyd glad to see you back!\n";
> } else {
> print "hello, $name\n";
> }
>
> I get a prompt asking me for my name, and it accepts my input, However
> when I put the word Lloyd in, it ignores the if then branch and goes
> straight to the last line and prints hello lloyd.
>
> Why is this happening. I copied this program stright out of that book and
> it doesn't work. Someone please be kind enough to help.....
>
> lloyd francis
> lloyd007@best.com





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

Date: Fri, 17 Jul 1998 14:39:47 -0700
From: Jerome O'Neil <joneil@cks.ssd.k12.wa.us>
To: Eric Harley <eharley@pacbell.net>
Subject: Re: Help me on the if-then-else branch
Message-Id: <35AFC4A3.3302E70F@cks.ssd.k12.wa.us>

We can knock it down to three like this:

#!/usr/local/bin/perl -w
print qq{What is your name?\n};
chomp($name = <STDIN>);
($name =~ /lloyd/i) ? print qq{Hi Lloyd glad yer back!\n} : qq{Hello,
$name\n};

Think some smart fella can get it to a one-liner?

Jerome 


Eric Harley wrote:

> #!/usr/local/bin/perl -w
> 
> print "What is your name?\n";
> 
> chomp($name = <STDIN>);
> 
> if ($name =~ /lloyd/i) {
>    print "Hi Lloyd glad to see you back!\n";
> } else {
>    print "hello, $name\n";
> }


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

Date: Fri, 17 Jul 1998 15:29:02 -0500
From: Yong Huang <yong@shell.com>
Subject: Re: I'm baffled.. (and an amateur:)
Message-Id: <35AFB40E.D38338B9@shell.com>

Contrary to what many people think, single print sometimes does have
problems. When writing a CGI script, you have to insert dynamic content
between HTML code. This breaks the first form of your single print
(print qq{}). That's still acceptable. But if your original code is
using the here document and you want to insert the dynamic content in
there, you have to give up on the here document.

Yong Huang

John Porter wrote:

> JFR wrote:
> >
> >         print start_form;
> >         print "<HTML>\n";
> >         print "<HEAD>\n";
> >[etc.]
>
> May I gently suggest that you use a single print statement
> for things like this?  E.g.
>
> print qq{
>   <HTML>
>   <HEAD>
>   ....
>   </HTML>
> };
>
> or a Here document:
>
> print <<EOF;
>   <HTML>
>   <HEAD>
>   ....
>   </HTML>
> EOF
>
> --
> John Porter
>
> sub Another::Just {
> shift;local$\=",\n";local$,=' ';
> print reverse @_,(caller(0))[3]=~/(.*)::(.*)/;
> }
> sub Hacker::Perl{(caller(0))[3]=~/(.*)::(.*)/}
> Just Another Perl Hacker;





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

Date: Fri, 17 Jul 1998 16:47:06 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: I'm baffled.. (and an amateur:)
Message-Id: <linberg-1707981647070001@projdirc.literacy.upenn.edu>

In article <35AFB40E.D38338B9@shell.com>, Yong Huang <yong@shell.com> wrote:

> Contrary to what many people think, single print sometimes does have
> problems. When writing a CGI script, you have to insert dynamic content
> between HTML code. This breaks the first form of your single print
> (print qq{}). That's still acceptable. But if your original code is
> using the here document and you want to insert the dynamic content in
> there, you have to give up on the here document.

Huh?

$foo = "<p>This is a dynamically generated paragraph</p>";

print qq(
<h1>Here is some HTML</h1>
$foo
<p>Wasn't that a lovely paragraph I built?</p>
);

print <<EOF;
<h1>Here is some more HTML</h1>
$foo
<p>Wasn't that another lovely paragraph I built?</p>
EOF

Perhaps I misunderstand you?
_____________________________________________________________________
Steve Linberg                       National Center on Adult Literacy
Systems Programmer &c.                     University of Pennsylvania
linberg@literacy.upenn.edu              http://www.literacyonline.org


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

Date: Fri, 17 Jul 1998 21:05:56 GMT
From: John Porter <jdporter@min.net>
Subject: Re: I'm baffled.. (and an amateur:)
Message-Id: <35AFBE49.22FA@min.net>

Yong Huang wrote:
> 
> Contrary to what many people think, single print sometimes does have
> problems. When writing a CGI script, you have to insert dynamic content
> between HTML code. This breaks the first form of your single print
> (print qq{}). That's still acceptable. But if your original code is
> using the here document and you want to insert the dynamic content in
> there, you have to give up on the here document.

I guess I don't understand what you mean by "break".
And whatever breaks the qq{} breaks the Here doc too.

my $var = dynamically_generated_html();

print qq{
  <font size=1>
  $var
  </font> 
};

print <<EOF;
  <font size=1>
  $var
  </font> 
EOF

What's broken?

If you really want to generate the dynamic stuff "in-line",
there's more than one way to do that, too.  Here's one:

print <<EOF;
  <font size=1>
  @{[ generate_html_lines_dynamically() ]}
  </font> 
EOF

Another would be to use the Interpolate module.

-- 
John Porter


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

Date: 17 Jul 1998 20:58:21 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: I'm baffled.. (and an amateur:)
Message-Id: <6oodtd$ka1$1@marina.cinenet.net>

Yong Huang (yong@shell.com) wrote:
: Contrary to what many people think, single print sometimes does have
: problems. When writing a CGI script, you have to insert dynamic content
: between HTML code. This breaks the first form of your single print
: (print qq{}). That's still acceptable. But if your original code is
: using the here document and you want to insert the dynamic content in
: there, you have to give up on the here document.

Not if you do it by calculating all your dynamic stuff into scalars, then
just stick the relvant scalars in where needed in a doublequotish here
doc.  Or better yet, keep the 'boilerplate' of the page in a separate
file, then read that in doing substitutions at marked points (a la
Text::Template) and sending the result to stdout.  That's both prettier
and far easier to maintain than the "calculate a little, output a little"
back-and-forth style.  IMHO, YMMV.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Fri, 17 Jul 1998 14:28:07 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: I'm baffled.. (and an amateur:)
Message-Id: <MPG.101961c3889b0d9989725@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <35AFB40E.D38338B9@shell.com> on Fri, 17 Jul 1998 15:29:02 -
0500, Yong Huang <yong@shell.com> says...
> Contrary to what many people think, single print sometimes does have
> problems. When writing a CGI script, you have to insert dynamic content
> between HTML code. This breaks the first form of your single print
> (print qq{}). That's still acceptable. But if your original code is
> using the here document and you want to insert the dynamic content in
> there, you have to give up on the here document.

Not really, but it is slightly more advanced.  The simplest way is to use 
more than one HERE document in a print statement:

print <<HERE1, output_from_a_function_or_whatever, <<HERE2;
These are the contents of
the first HERE document,
HERE1
and these are the contents
of the second HERE document.
HERE2

Now you know why you need a semicolon after the print statement.

Another way is to compute the dynamic content before the print statement, 
and interpolate the (scalar or list) value into the HERE document, as you 
can into any double-quoted string:

my $x = 1;
my $scalar = $x + $x;
my @array = qw(whatever creates the list);
print <<HERE;
The sum of \$x and \$x is $scalar.
The array \@array contains @array (prints it by default with space 
separation).
HERE

The most sophisticated way is to interpolate the dynamic content directly 
into the HERE document:

print <<HERE;
The sum of \$x and \$x is ${\($x + $x)}.
The value of the list is {[qw(whatever creates the list)]}.
HERE

This is quite legible once you get used to it, and almost preserves the 
cohesiveness and visual appearance of the HERE document that is its value 
in the first place.

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 16 Jul 1998 11:18:54 -0500
From: "Quinn,M" <quinn@phoenix.net>
To: Amanda Silver <aks@cs.brown.edu>
Subject: Re: mastering regular expressions
Message-Id: <35AE27EE.ABC5D551@phoenix.net>

see http://www.amazon.com and search by publisher=
o'reilly and title=mastering regular

Melinda Quinn  melinda@acm.org

Amanda Silver wrote:
> 
> i also was wondering if the Mastering Regular Expressions book by o'reilly
> really is the best book and if it will help me alot, can anyone here provide a review?
> 
> thanks.


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

Date: 17 Jul 1998 17:41:58 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: Eli the Bearded <*@qz.to>
Subject: Re: module forcing a reload of itself (a mod_perl question)
Message-Id: <sok09k21.fsf@mailhost.panix.com>

Eli the Bearded <*@qz.to> writes:

Eli - I was *just* going through the same hell myself today.  Here's
one way to do it.  If your custom module is in

  /some/path

then write this wrapper script:

  #!/bin/sh
  PERL5LIB=/some/path; export PERL5LIB
  /usr/local/apache/sbin/apachectl restart

In your relevant .conf file, you'll want

  PerlInitHandler Apache::StatINC

That ought to do it for scripts that rely on Apache::Registry.  If
your scripts are real Apache scripts, then PerlInitHandler is the
handler to hook, not PerlHandler (which is too late).  I hope this is
of use.  I figured it out by first banging my head against the
appalingly bad Apache docs then reading the excellent LDS/Doug
MacEachern article in TPJ #9.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf/
who actually *is* a drummer/coder


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

Date: Fri, 17 Jul 1998 12:56:35 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Mutiple pattern searches
Message-Id: <MPG.10194c4a3e7040bc989723@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <35AF380A.533C@email.sps.mot.com> on Fri, 17 Jul 1998 11:40:29 
+0000, John Nguyen <RC0705@email.sps.mot.com> says...
> Is there a way of searching a text file using multiple search patterns. 
> For example, say I want only lines from a text file that does NOT
> include these three patterns: abc xyz mno
> 
> My problem is that the string patterns are elements in an array.  How do
> you specify an array in a search pattern and have a ! (not) symbol in
> front of each element since I only want lines that do not include these
> string patterns.
> 
> John

perlfaq6: "How do I efficiently match many regular expressions at once?"

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 17 Jul 1998 20:27:11 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: newbie date format
Message-Id: <zsOr1.26$a34.39463@news2.voicenet.com>

Larry Rosler <lr@hpl.hp.com> wrote:
>The logic of Orig is wrong, but it doesn't much change the Benchmarks.

Was a typo.  Nice catch.

>Clean  Dirty  Orig   perl -v   uname -a
> 9.73   7.32  6.98   5.002     HP-UX       9.05 HP 9000/735
>10.08   7.58  7.43   5.003     Windows_NT  4.00 HP Vectra XU 6/200
> 6.63   6.53  6.13   5.004_03  HP-UX      10.20 HP 9000/819

I can add:

Clean  Dirty  Orig   perl -v   uname -a
23.82  18.97  17.30  5.004_04  SunOS 5.6 Generic sun4c sparc  | Sparc 2
21.57  13.72  14.23  5.003     SunOS 4.1.4 1 sun4m            | Sparc 10

Hmm.. dont' see any speed increase when using Suns.

>Now let's look at a more realistic use:  mm/dd:

The more that needs doing, the more the quick and dirty solution becomes
wrong... almost by definition!

>Clean:  8.32
> Orig:  9.01
>
>And extrapolate to '%d/%.2d/%.2d %.2d:%.2d:%.2d'.  Are we beginning to 
>see the light?

For larger cases, yes.  But, this confuses me.  Surely sprintf is a
reasonably complex procedure.  I don't see (Other than using benchmarks)
how it could *possibly* be faster than a few conditionals.  It just
doesn't make sense to me.

Then again, Perl is not C.

-- 
Matt Knecht - <hex@voicenet.com>
"496620796F752063616E207265616420746869732C20796F7520686176652066
617220746F6F206D7563682074696D65206F6E20796F75722068616E6473210F"


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

Date: Fri, 17 Jul 1998 14:06:55 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: newbie date format
Message-Id: <MPG.10195cc5c843226e989724@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <zsOr1.26$a34.39463@news2.voicenet.com> on Fri, 17 Jul 1998 
20:27:11 GMT, Matt Knecht <hex@voicenet.com> says...
 ...
> >And extrapolate to '%d/%.2d/%.2d %.2d:%.2d:%.2d'.  Are we beginning to 
> >see the light?
> 
> For larger cases, yes.  But, this confuses me.  Surely sprintf is a
> reasonably complex procedure.  I don't see (Other than using benchmarks)
> how it could *possibly* be faster than a few conditionals.  It just
> doesn't make sense to me.
> 
> Then again, Perl is not C.

That is the answer -- and it took me a while to figure it out.  My first 
eye-opener:  Compute the length of the largest string in an array.   
Leaving out the loop and concentrating just on the 'max' statement, my 
first (C) approach:

$max = $len if $max < ($len = length);

C model:  length() is a function call (think strlen()) which is 
relatively expensive, so do it once and remember the result if needed.  
The correct (Perl) approach:

$max = length if $max < length;

Perl model:  length() is a built-in that grabs a datum from a string's 
"dope vector".  It is no more expensive than '+'.  What takes time is 
processing all those extra tokens in the parse tree.

Now apply this to sprintf.  It used to be a call to a C function, but C 
functions are *fast* compared to processing "a few conditionals" in Perl!  
Evidently in 5.004 it has become more built-in (some specs changed and 
it acquired its own documentation, instead of pointing to C's), but still 
implemented in C, hence *fast* compared to processing "a few 
conditionals" in Perl.

The built-ins have been benchmarked here many times and always show up 
fast -- grep/map vs. explicit loops; substr vs regex; ...  If speed 
matters, the less verbiage in a Perl expression, the better.

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 17 Jul 1998 21:42:50 GMT
From: k y n n <kj0@mailcity.com>
Subject: Re: On mixing (seek/tell) and (sysopen/syswrite)
Message-Id: <6ooggq$1l3@news1.panix.com>


>:What I want to know is, what can I safely use in place of tell() and
>:seek() in conjunction with sysopen(), syswrite()?

>No.  And when you stop mutilating your address, I'll tell
>you what you should do instead.

OK, new, unmutilated address in the header.

K.
-- 
To those who prefer to reply by e-mail, please remove the upper-case
letters from the return address in the header.  Thank you.  K.


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

Date: 17 Jul 1998 15:10:52 -0500
From: les@MCS.COM (Leslie Mikesell)
Subject: Re: Perl Beautifier Home Page
Message-Id: <6oob4c$eq0$1@Mars.mcs.net>

In article <900654362.763147@thrush.omix.com>,
Zenin  <zenin@bawdycaste.org> wrote:
>
>	Even if a beautifier isn't perfect, if it can make the completely
>	unreadable somewhat readable I'd use it.

Even if you disagree about the beauty part it would be nice to have
a tool that would take code that had been reformatted separately
by different people and fix it to a point where a diff would
make sense.

  Les Mikesell
   les@mcs.com


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

Date: Fri, 17 Jul 1998 13:53:17 -0700
From: josh@netoutfit.com (Josh Blackwell)
Subject: Re: persistent objects
Message-Id: <josh-ya02408000R1707981353170001@news.keyway.net>


In , <oee7m1dg8zn.fsf@alpha.hut.fi>, Jarkko Hietaniemi <jhi@alpha.hut.fi> wrote:

> looper@sparadigm.com (looper) writes:
> 
> > 
> > 
> > Is there a simple way I can store a reference to something in a file that
> > the other perl processess can open and actually use (just given something
> > like ARRAY(0xacc50))? 
> > 
> > I have a nested data structure that maintains an array of objects
> > (FileHandle's, Socket's etc.) which is created by one perl invocation. I
> 
> Umm, how on earth could you store live file/network connections to a file?
> Those are tightly tied to a single live process.

Hello Jarkko,

Currently a persistent Perl interpreter (that runs within a webservers
process via NSAPI) creates an array of socket connections and maintains
them in a namespace. Separate invocations of the same *persistent* perl
interpreter throughout the website can get into the namespace, get the GLOB
reference to the socket, and use it fine. However, what I really  need is
to have a regular perl interpreter, not just a persistent one, get at the
GLOB reference as well (for reasons too lengthy to describe here). 
   If the GLOB reference is guaranteed to be valid and correct shouldnt
other perl processess technically be able to use them? Am I over my head?


> Such things _can_ be done but only iff the operating systems gives a
> large helping hand, "checkpointing" a process.  Neither your garden
> variety UNIX nor Win32 can do this.  Well, I am guessing on the Win32
> but that's an educated guess, because: especially the network
> connections are really hard, how can you guarantee anything about the
> other end of the connection? 

Its our server its connecting to on the other end... thats about it.

 Even local files are not trivial: in
> effect the files should be locked against any other processes.  And
> considering that you want to save your state to a file, the logical
> thing to do would to make this file locking persisent (reboot-proof) too.

flags in the array structure that checked a connection in or out. kinda
like a broker.

> 
> The next best thing you can hope to do is to save the file and network
> connection open parameters and then restore your connections using those
> parameters.

Hmmm... can you explain this a bit further? how could you save the
parameters without the actual handle and not open another connection in the
process?

> 
> > need all other perl invocations to be able to get at it. 
> > 
> > I tried Eroot.pm with not much success, ObjectStore.pm seems a touch over
> > the top for me, and I haven't bothered with Storable.pm because of the Sys
> > V dependant stuff which I can't have. 
> 
> Huh?  Storable requires no such thing.  The IPC reference means
> _any_ IPC, for example sockets.

I see your point. But all these things simply recreated STRINGS, HASHS and
ARRAYS from 
a serialized string never maintaintaing the original reference(s). I
obviously ran into problems when it tried to recreate the GLOB (because of
the need for the original ref).

Thanks for the reply.

-Josh Blackwell (original poster of msg)
 
> -- 
> $jhi++; # http://www.iki.fi/~jhi/
>         # There is this special biologist word we use for 'stable'.
>         # It is 'dead'. -- Jack Cohen


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

Date: Fri, 17 Jul 1998 16:08:09 -0500
From: Yong Huang <yong@shell.com>
To: David Hemmer <mastered@paclink.com>
Subject: Re: Premature End of Script Header problem
Message-Id: <35AFBD38.5B0C978D@shell.com>

It's not easy to debug CGI scripts by looking at your code. But you can at
least try putting

print "Content-type: text/plain\n\nThis is the temporary end.The WATCH
variable \$xxx right now has a value: $xxx."; exit 0;

somewhere in your script. Move that line to different places.

Another tip: Move your main print "Content-type: text/plain\n\n" line to the
top.

Another guy's harsh reply to your post may be right. But I'm sure you said
all about the error_log: "Premature end of script header" (because I've been
doing CGI and server maintenance for >2 years). Sometimes the error_log
reports line numbers. That could be useful too.

Yong Huang



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

Date: Fri, 17 Jul 1998 15:12:40 -0500
From: Dave Radin <radin@ews.uiuc.edu>
To: Yong Huang <yong@shell.com>
Subject: Re: regexp help?
Message-Id: <Pine.GSO.3.96.980717150955.9839A-100000@eesn32.ews.uiuc.edu>

Thanks for the help to those who responded. I wound up using the
Text::ParseWord library to split each line into a list, then manually
reprinting each line into my out file, and adding commas as necessary.
Clunky, but it worked. Now if I can just get SQL*Loader to like it... :(

Thanks again...
Dave


On Fri, 17 Jul 1998, Yong Huang wrote:

> This is very interesting. My script below manually deals with the commas in
> quotes. They're changed to triple commas as an example.
> 
> #!perl -w
> #I use Perl for Win95. So there's no path after #!. But I want the -w switch.
> 
> open(IN, "file.txt");
> 
> while (<IN>)
>  { #s/\G(".+?),(.+?")/$1,,,$2/g;    #Hope somebody can make this work. I
> can't.
> 
>    $lngth = @tmp = split /"/;
> 
>    for ($i=0; $i<$lngth; $i++)
>     { if ($i%2!=0)    #find the string in quotes; they're after odd number of
> " 's
>        { $tmp[$i] =~ s/,/,,,/g;
>        }
>     }
> 
>    print join("",@tmp);
>  }
> 
> close IN;
> 



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

Date: 17 Jul 1998 13:35:41 +0930
From: Martin Gregory <mgregory@asc.sps.mot.com>
Subject: Re: RegExps: Check if string consists of EXACTLY 3 digits ??
Message-Id: <r8ogupm8a2.fsf@asc.sps.mot.com>

comdog@computerdog.com (brian d foy) writes:
> >> the result is 2.  the dot does not match newlines unless you use
> >> the /s modifier.  the dot matches the d, which is replaced by itself,
> >> and the newline is left as is, leaving a string of length 2.
> >> 
> >> :)
> >
> >Yeah - that's funny!  You are obviously the regex guru - the rest of
> >us are wallowing in our misconceptions!  So
> 
> i think that's facetious, as it should be, but you forgot the smiley :)

No - I was serious!  I was paying homage ... I think you were the one
who picked up the business about $ possibly matching \n in the first
place, weren't you, when everyone else said /^\d\d\d$/ was the correct
answer?

And now you also gave the correct explanation for an example I was
using, in the process showing that it did not actually illustrate what
I was trying to illustrate.

I found it very funny that an example I gave to illustrate how
potentially confusing this thing is was wrong because I had even more
misconceptions than I knew! (I _can_ laugh at myself).  

Cheers,

Martin.


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

Date: 17 Jul 1998 20:13:58 GMT
From: Eli the Bearded <*@qz.to>
Subject: Re: Sendmail ?
Message-Id: <eli$9807171610@qz.little-neck.ny.us>

In comp.lang.perl.misc, - <root.noharvest.\@not_even\here.com> wrote:
> Geez...  I wasn't trying to start a flame war about which editor is
> better.  

That was not a flame war.

> I suggested vi because it's always present and easy enough to figure
> out to make a simple one line change, and in no way suggested that you
> actually CODE in vi.  Hell, that would be rather painfull.

Heh.  I've coded in vi. By which I mean written things to run in vi,
the most complex thing I've written being Conway's Game of Life.

> notepad or wordpad, FTP the file, test it on the command line.  For

Now you are trying to start a flame war.

> And yes, I jump from box to box, so vi is often the only editor in
> common.

vim has been ported to most everything on earth.

Elijah
------
emacs, too, for values of everything with more memory


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

Date: Fri, 17 Jul 1998 15:02:15 -0500
From: Yong Huang <yong@shell.com>
To: snowbird <snowbird@pcisys.net>
Subject: Re: Strangness in for loop ?!
Message-Id: <35AFADC7.BFEB8FA0@shell.com>

> for $i ( 0 .. $#array ) {
>     last if $array[$i] eq 'c';
> }
> print " i = $i\n";

In Programming Perl 2nd ed., "The variable is implicitly local to the loop
and regains its former value upon exiting the loop." (p.100). You have no
former value. So it's undefined.

Yong Huang



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

Date: Fri, 17 Jul 1998 15:11:54 -0500
From: Yong Huang <yong@shell.com>
To: gcoulomb@gpu.srv.ualberta.ca
Subject: Re: system() return values
Message-Id: <35AFB00A.BC04B069@shell.com>

I tried this:

$tmp=system "ls"; #also tried on PC and use "dir"
print $tmp;

and I got 0. On the command line it's also 0. What platform are you using?

Yong

Greg Coulombe wrote:

> I have a perplexing problem: when I call an external program from a
> system call, the return value is ALWAYS -1. After going through the
> number mangling suggested in the Camel book, this turns out to be a
> return code of 255. When I run the same command from the command line,
> it returns 0 (as I expected). Any thoughts on this mystery?
>
> --
> Greg Coulombe
> Programmer, Orlando Project
> Faculty of Arts
> coulombe@cs.ualberta.ca
>
> "It is easier to port a shell than a shell script."
>                         -- Larry Wall





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

Date: Fri, 17 Jul 1998 13:03:32 -0700
From: "Mishra Aditya" <mishra.aditya@emeryworld.com>
Subject: Re: system() return values
Message-Id: <6ooam8$nfu@news.cnf.com>

perdoc -f system

Adi




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

Date: Fri, 17 Jul 1998 16:32:23 -0500
From: Indra Rosadi <rosadi@students.uiuc.edu>
Subject: upload in CGI perl
Message-Id: <Pine.SOL.3.96.980717163012.7915A-100000@ux8.cso.uiuc.edu>

Hi,
I am just wondering if somebody can give me a small example about
uploading files in CGI perl.. I keep getting stuck in this problem.. 
Thanks a bunch..

Indra



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

Date: Fri, 17 Jul 1998 15:42:20 -0500
From: Yong Huang <yong@shell.com>
To: Hans Van Lint <hvanlint@lodestar.be>
Subject: Re: Variables
Message-Id: <35AFB72C.A58A22D2@shell.com>

Other than using cookies, you can use hidden fields. The reason you don't want
to use it is because you're using the method GET and the value is shown in URL.
I use POST to avoid this problem.

However, using cookies is probably the best way. I used to use hidden fields to
pass "secret" variables around between scripts. When the project gets more and
more complicated, it's very cumbersome. So I cp'ed all to ./backup and re-wrote
using cookies. The only 2 minor problem with cookies is some users are nervous
abut accepting them. The other is that some turn on the "Warn me before
accepting cookies" in browser. If somebody is standing by him, his secret info
gets stolen.

Yong Huang


Hans Van Lint wrote:

> Hi,
> I'm writing in Perl:
> When users enter my site (through login.cgi) they need to give their name
> and password. In login.cgi I store their name (with $ENV{REMOTE_USER}) in a
> variable called $gebruiker.
> However, I'm using different .cgi scripts and I want to remember this
> variable in all of them. BUT somehow I think this is very unsafe. Because
> sometimes I'm passing the variables via <a
> href=zoeken.cgi?gebruiker=$gebruiker...
> Is there a way to pass, remember variables in all scripts without the user
> noticing it. So not via the above example and not with a hidden field in a
> form tag.
> I once read I could use an $ENV{} for this in Perl!!
> Thnx





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

Date: Thu, 16 Jul 1998 11:29:02 -0500
From: "Quinn,M" <quinn@phoenix.net>
Subject: Re: WARNING: Newbie Inquiry - PERL Architecture
Message-Id: <35AE2A4E.1E99BAF@phoenix.net>

The answer to this question will be similar
to the one I just posted under MODULES, but I've
posed a question which requests a CONCRETE (vs.
abstact) reply. 
Hoping for help....  Melinda Quinn  melinda@acm.org

Fredrick V. Brock wrote:
----snip----> 
> Is it better to interrelate the 12 individual files that contain sub
> routines using 'do' statements; or,
> 
> Is it better to interrelate the individual files into one (rather long)
> file.  Granted, without PERL knowledge, the concept of a long file is
> nebulous and subjective.  With minimal but adequate use of white space
> to facilitate human interpretation, the resulting single file will be
> approximately 9,000 lines long.
> 
> Fredrick V. Brock
> President
> http://www.mycitypages.com
> My City Enterprises, Inc.


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 3190
**************************************

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