[24938] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7188 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 28 21:07:03 2004

Date: Tue, 28 Sep 2004 18:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 28 Sep 2004     Volume: 10 Number: 7188

Today's topics:
    Re: (Win32) Timing out a process while reading process' <kalinaubears@iinet.net.au>
    Re: CGI scripts and modular design? <postmaster@castleamber.com>
    Re: CGI scripts and modular design? <gifford@umich.edu>
    Re: CGI scripts and modular design? <noreply@gunnar.cc>
    Re: CGI scripts and modular design? <postmaster@castleamber.com>
    Re: CGI scripts and modular design? <noreply@gunnar.cc>
    Re: How to check size of harddisk? <mikee@mikee.ath.cx>
    Re: How to check size of harddisk? <abigail@abigail.nl>
    Re: How to check size of harddisk? <tadmc@augustmail.com>
        How to embed javascript functionality into a Perl CGI s (Vibhu)
    Re: How to embed javascript functionality into a Perl C <bcaligari@nospam.fireforged.com>
    Re: Loop through scalar? <abigail@abigail.nl>
    Re: Loop through scalar? <someone@example.com>
    Re: Loop through scalar? <abigail@abigail.nl>
        modifying scripts for mod_perl? <raven_at@home.domonet.ru>
    Re: modifying scripts for mod_perl? <noreply@gunnar.cc>
        Number of Days Between 2 Dates. <ackcomm@JUNKcomcast.net>
    Re: Number of Days Between 2 Dates. <bcaligari@nospam.fireforged.com>
    Re: Number of Days Between 2 Dates. <noreply@gunnar.cc>
    Re: Number of Days Between 2 Dates. <noreply@gunnar.cc>
    Re: Number of Days Between 2 Dates. <abigail@abigail.nl>
    Re: Perl vs PHP <dformosa@zeta.org.au>
    Re: Perl vs PHP <tadmc@augustmail.com>
        pipes problem <b-patton@ti.com>
    Re: pipes problem <gifford@umich.edu>
    Re: Precedence of exponentiation <abigail@abigail.nl>
    Re: references to filehandle? <tadmc@augustmail.com>
        unicode: is decode-process-encode a "good" aproach? <pilsl@goldfisch.at>
        What is this error? (Binny V A)
    Re: What is this error? <spamtrap@dot-app.org>
    Re: What is this error? <mjcarman@mchsi.com>
    Re: What is this error? <bcaligari@nospam.fireforged.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 29 Sep 2004 08:05:53 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: (Win32) Timing out a process while reading process' output?
Message-Id: <4159e177$0$25146$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

rtm wrote:
> I am interested in running a process with a timeout.  Also I'm
> interested in analyzing the output of this process.
> 
> Under Unix, the solution is described clearly in the Perl Cookbook
> "16.10:  Communicating between related processes" and 16.24 "Timing
> out an Operation".   Enclosed below is an example showing what I want
> to do under Unix.
> 
> I need to do this under Windows XP.  As others have pointed out
> "alarm" works under 5.8+ and fork sorta works under 5.8+ under
> windows.  But the unix example code below just hangs.
> 
> So the best thing I have found is Win32::Job.
> 
> ------------------------------------------------------------------------
> #!/usr/bin/env perl
> # -*- cperl -*-
> BEGIN { $^W = 1; }
> use strict;
> 
> use Win32::Job;
> my $job = Win32::Job->new();
> 
> my $r = $job->spawn("z:\t\junk.exe", "junk", {
>                                               stdin  => 'NUL', # the NUL device
>                                               stdout => 'stdout.log',
>                                               stderr => 'stdout.log',
>                                              });
> $job->run(20);
> ------------------------------------------------------------------------
> 
> The only problem is that I can't see how you read the output while the
> process is running when using Win32::Job. 

my $r = $job->spawn("z:/t/junk.exe", "junk");

Now you will see anything (and everything) that junk.exe writes to STDOUT.

Only puzzle for me is that, afaict, junk.exe doesn't write *anything* to 
STDOUT ... which makes me wonder if I've missed the point :-)

Also, it's better to use forward slashes inside double quotes. Does the 
script actually run with those backslashes ?

Cheers,
Rob

-- 
To reply by email u have to take out the u in kalinaubears.



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

Date: 28 Sep 2004 18:25:41 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: CGI scripts and modular design?
Message-Id: <Xns957288987CC75castleamber@130.133.1.4>

shrike@cyberspace.org (psyshrike) wrote in 
news:79485f9d.0409280741.340cba6b@posting.google.com:

> Howdy, 
> 
> I've been poking through some different shopping cart software, trying
> to decide which one to use. All of them use piped filehandles or
> backticks to handle modularization.
> 
> I will be modifying my store with some very custom requirements. It
> will be about a dozen modules before it is complete.
> 
> My question is, Is there are reason why CGI scripts don't: 
> 
> use lib "./lib" ;

What is . ? I remember that there was (is?) no guarantee that it's the 
cwd of your script. You can use FindBin to solve this problem though.

> and use modular code instead of backticking everything? My virtual
> hosting ISP permits calling locally installed libraries. Is it common
> practice for ISP's to not allow this?

Some don't give shell access.

> If I use modular design am I
> hurting my portability if I decide to go with another webhosting
> service?

There is so much choice in webhosting those days that it's not that 
difficult to find one that meets your requirements.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                           personal page:       http://johnbokma.com/
        Experienced programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html


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

Date: Tue, 28 Sep 2004 15:06:00 -0400
From: Scott W Gifford <gifford@umich.edu>
Subject: Re: CGI scripts and modular design?
Message-Id: <qszbrfqnrhj.fsf@tetris.gpcc.itd.umich.edu>

shrike@cyberspace.org (psyshrike) writes:

[...]

> I have the hardest darned time sorting through the bazillion scripts
> in my cgi-bin. If I can't come up with a reason not to, I am turning
> half of them into object libraries, and sticking them in  /cgi-bin/lib

Sticking them in cgi-bin/lib might make them directly executable,
depending on Web server configuration, which may not be what you want
(especially if including the file has side-effects).

I usually create a cgi-lib directory outside of the Web server's root,
and put all CGI libraries in there.  That way they can't be read or
executed directly by the Web server.

I sometimes also set the PERL5LIB environment variable in Apache to
specify where my libraries are, then use this code to untaint it and
pull it in:

    BEGIN {
      if ($ENV{PERL5LIB} and $ENV{PERL5LIB} =~ /^(.*)$/)
      {
        # Blindly untaint.  Taintchecking is to protect from Web data;
        # the environment is under our control.
        eval "use lib '$_';"
            foreach (reverse split(/:/,$1));
      }
    }

That makes it easier to use the same script in different locations, by
just changing the Apache config (with .htaccess if you don't control
the entire server).

Overall, this is a very good idea.  It should make your code easier to
maintain, encourage you to re-use code, and ensure that when you fix a
bug in one place it is fixed everywhere.

-----ScottG.


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

Date: Tue, 28 Sep 2004 21:47:59 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI scripts and modular design?
Message-Id: <2rttfiF1e66a7U1@uni-berlin.de>

John Bokma wrote:
>> My virtual hosting ISP permits calling locally installed
>> libraries. Is it common practice for ISP's to not allow this?
> 
> Some don't give shell access.

Assuming we are talking about pure Perl modules, why would you need
shell access to upload them to a local library?

Possible providers who permit that you run your own CGI scripts
written in Perl, but don't 'permit' the use of own modules, are
ignorant and not worth to take into consideration.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 28 Sep 2004 21:16:31 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: CGI scripts and modular design?
Message-Id: <Xns9572A58E5D3DBcastleamber@130.133.1.4>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in news:2rttfiF1e66a7U1@uni-
berlin.de:

> John Bokma wrote:
>>> My virtual hosting ISP permits calling locally installed
>>> libraries. Is it common practice for ISP's to not allow this?
>> 
>> Some don't give shell access.
> 
> Assuming we are talking about pure Perl modules, why would you need
> shell access to upload them to a local library?

make? Unless you have exact the same environment as your hosting provider. 
There was a time I developed stuff on IRIX :-D

> Possible providers who permit that you run your own CGI scripts
> written in Perl, but don't 'permit' the use of own modules, are
> ignorant and not worth to take into consideration.

Sometimes you can get a "shell" via CGI :-D, but I prefer the real thing.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                           personal page:       http://johnbokma.com/
        Experienced programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html


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

Date: Tue, 28 Sep 2004 23:34:14 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI scripts and modular design?
Message-Id: <2ru3msF1eom8pU1@uni-berlin.de>

John Bokma wrote:
> Gunnar Hjalmarsson wrote:
>> John Bokma wrote:
>>> Some don't give shell access.
>> 
>> Assuming we are talking about pure Perl modules, why would you
>> need shell access to upload them to a local library?
> 
> make?

Okay, but make isn't necessary. Simply uploading the .pm files to the
right directories is sufficient. I did that successfully for several
years as long as I had a hosting account without shell access.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Tue, 28 Sep 2004 18:27:58 -0000
From: Mike <mikee@mikee.ath.cx>
Subject: Re: How to check size of harddisk?
Message-Id: <10ljb9ea0kho305@corp.supernews.com>

In article <1s9jl09ohl16egnj3b9h8aedd9uuib88eo@4ax.com>, Jason Quek wrote:
> Hi
> 
> How can I use Perl to check the size of the harddisk and the amount of
> space left?
> 
> Any help would be appreciated.

What platform? For *nix do a (call-with-input-file "df -k"). For
windows load kernel32.dll and .... I forget the function, but it's
there.

Mike


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

Date: 28 Sep 2004 22:41:01 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: How to check size of harddisk?
Message-Id: <slrncljq3t.hv.abigail@alexandra.abigail.nl>

Jason Quek (qjason@starhub.net.sg) wrote on MMMMXLVI September MCMXCIII
in <URL:news:1s9jl09ohl16egnj3b9h8aedd9uuib88eo@4ax.com>:
||  Hi
||  
||  How can I use Perl to check the size of the harddisk and the amount of
||  space left?

What exactly do you mean? There's no such thing as "space left on
a harddisk".  As far as the OS (and the disk) is concerned, a disk is
filled with data. All of the disk.

How to check the size of a disk depends on the OS, and on the type of bus
(SCSI, fibre-channel, IDE, ...) being used.

Perhaps you mean you want to check the size of a filesystem, and the
amount of unused space of the filesystem?



Abigail
-- 
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
           ${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'


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

Date: Tue, 28 Sep 2004 17:47:14 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to check size of harddisk?
Message-Id: <slrncljqfi.frq.tadmc@magna.augustmail.com>

Jason Quek <qjason@starhub.net.sg> wrote:

> How can I use Perl to check the size of the harddisk and the amount of
> space left?
> 
> Any help would be appreciated.


Managing the filesystem is the job of the Operating System,
not of a programming language.

How would you check the size of a harddisk without using Perl?

You can likely do it whatever way that is from within Perl too,
but we don't even know what OS you need this for...


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 28 Sep 2004 13:59:19 -0700
From: vbontala9@yahoo.com (Vibhu)
Subject: How to embed javascript functionality into a Perl CGI script?
Message-Id: <b3d950bf.0409281259.26ada413@posting.google.com>

I have this fundamental problem where I am trying to generate some
HTML content using Perl CGI script. Currently, my CGI script uses some
variables to calculate and value retrieval stuff and throws that onto
a HTML format. In addition to this, I want to add dynamic capability
to my CGI script.

For example, I generate a HTML web-page using Perl CGI code. In that
generated page, if I have some checkboxes/radio buttons/select windows
etc, I want to generate some dynamic content if I select one of those
elements. This means as soon as I select an item, one of the perl
functions should be invoked. Similarly, how could I do "onMouseOver",
"onClick" etc kind of stuff with Perl CGI scripts? Please help me.

Thanks
-Vibhu


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

Date: Tue, 28 Sep 2004 21:15:44 +0000
From: Brendon Caligari <bcaligari@nospam.fireforged.com>
Subject: Re: How to embed javascript functionality into a Perl CGI script?
Message-Id: <4159d483$0$94918$bed64819@news.gradwell.net>

Vibhu wrote:

> I have this fundamental problem where I am trying to generate some
> HTML content using Perl CGI script. Currently, my CGI script uses some
> variables to calculate and value retrieval stuff and throws that onto
> a HTML format. In addition to this, I want to add dynamic capability
> to my CGI script.
> 
> For example, I generate a HTML web-page using Perl CGI code. In that
> generated page, if I have some checkboxes/radio buttons/select windows
> etc, I want to generate some dynamic content if I select one of those
> elements. This means as soon as I select an item, one of the perl
> functions should be invoked. Similarly, how could I do "onMouseOver",
> "onClick" etc kind of stuff with Perl CGI scripts? Please help me.
> 
> Thanks
> -Vibhu

CGI scripts are executed at the server side.  And server side code can 
only be executed when page in question is requested from the server.  To 
achieve what you are after you need code that can execute within the 
browser itself...such as JavaScript.

B.


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

Date: 28 Sep 2004 22:32:04 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Loop through scalar?
Message-Id: <slrncljpj4.hv.abigail@alexandra.abigail.nl>

Jason Kinkade (jkinkade@datashelter.net) wrote on MMMMXLVI September
MCMXCIII in <URL:news:7aa71c67.0409272302.197da8c6@posting.google.com>:
))  I have a scalar/variable ($var) that looks like:
))  
))  Line1
))  Line2
))  Line3
))  Line4
))  etc.
))  
))  Theres obviously a new line after each Line#.  I would like to loop
))  through this variable line by line with something like
))  
))  foreach ($var)
))  {
))     print "Current Line: $_";
))  }
))  
))  This reads the entire $var in.  I want it line by line instead.
))  
))  Any idea? 


Unlike others in this thread, I wouldn't use split, but m//g:

    while ($var =~ /(.*\n)/g) {
        print "Current line: $!";
    }


Abigail
-- 
perl -wle '(1 x $_) !~ /^(11+)\1+$/ && print while ++ $_'


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

Date: Tue, 28 Sep 2004 22:50:27 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Loop through scalar?
Message-Id: <TUl6d.130$eq.19@edtnps84>

Abigail wrote:
> 
> Unlike others in this thread, I wouldn't use split, but m//g:
> 
>     while ($var =~ /(.*\n)/g) {
>         print "Current line: $!";
>     }

So you are saying that $! contains the current line?  :-)


John
-- 
use Perl;
program
fulfillment


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

Date: 28 Sep 2004 23:20:55 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Loop through scalar?
Message-Id: <slrncljsen.hv.abigail@alexandra.abigail.nl>

John W. Krahn (someone@example.com) wrote on MMMMXLVI September MCMXCIII
in <URL:news:TUl6d.130$eq.19@edtnps84>:
**  Abigail wrote:
** > 
** > Unlike others in this thread, I wouldn't use split, but m//g:
** > 
** >     while ($var =~ /(.*\n)/g) {
** >         print "Current line: $!";
** >     }
**  
**  So you are saying that $! contains the current line?  :-)


Just a case of bitrot....


Abigail
-- 
perl -Mstrict -we '$_ = "goto O.print chop;\n=rekcaH lreP rehtona tsuJ";O1:eval'


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

Date: Wed, 29 Sep 2004 03:07:56 +0400
From: "Sergei Shelukhin" <raven_at@home.domonet.ru>
Subject: modifying scripts for mod_perl?
Message-Id: <2ru958F1dv6rlU1@uni-berlin.de>

I get variable error when I try to use procedure in a module to connect to
db.
=== common.pm
sub connect
  {
  return DBI->connect( "DBI:mysql:blogbase:localhost", "something",
"something" ) or croak "MySQL seems to be down.";
  }
== index.pl
use common;
#...
$db = Common::connect() or croak "woops";

If I access it on my testbox running Apache without mod_perl, it works.
If I type perl index.pl in console on the working server, it works.
When I try to access it on the server, with Apache with mod_perl, it croaks.

What's the problem? How do I fix it? I seem to be pretty much out of any
clue...

I was also wondering if there's something like "HOWTO migrate to mod_perl"
guide somewhere.




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

Date: Wed, 29 Sep 2004 01:14:00 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: modifying scripts for mod_perl?
Message-Id: <2ru9i0F1dq7imU1@uni-berlin.de>

Sergei Shelukhin wrote:
> I was also wondering if there's something like "HOWTO migrate to
> mod_perl" guide somewhere.

There is: http://perl.apache.org/docs/1.0/guide/porting.html

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Tue, 28 Sep 2004 15:54:47 -0500
From: Fred Goldberg <ackcomm@JUNKcomcast.net>
Subject: Number of Days Between 2 Dates.
Message-Id: <Xns9572AB89B85CCackcommcomcastnet@216.196.97.142>

I have the current releace of ActiveState for Win32.

I'm confused by the shear number of time and date modules and exactly what 
they are capable of doing. I need help calculating the number of days 
(including weekends) between two dates. All dates are in the format of 
mm/dd/yyyy. This format can be changed if needed.

What module is best to use and what is the format of the function. Thanks.

Fred



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

Date: Tue, 28 Sep 2004 21:11:39 +0000
From: Brendon Caligari <bcaligari@nospam.fireforged.com>
Subject: Re: Number of Days Between 2 Dates.
Message-Id: <4159d38b$0$94918$bed64819@news.gradwell.net>

Fred Goldberg wrote:

> I have the current releace of ActiveState for Win32.
> 
> I'm confused by the shear number of time and date modules and exactly what 
> they are capable of doing. I need help calculating the number of days 
> (including weekends) between two dates. All dates are in the format of 
> mm/dd/yyyy. This format can be changed if needed.
> 
> What module is best to use and what is the format of the function. Thanks.

Time::Local should do the trick

The docs are pretty straight forward.  timelocal is most likely the 
function you're after.

B.




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

Date: Tue, 28 Sep 2004 23:14:15 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Number of Days Between 2 Dates.
Message-Id: <2ru2hcF1ehc8uU1@uni-berlin.de>

Fred Goldberg wrote:
> I'm confused by the shear number of time and date modules and
> exactly what they are capable of doing. I need help calculating the
> number of days (including weekends) between two dates. All dates
> are in the format of mm/dd/yyyy. This format can be changed if
> needed.
> 
> What module is best to use

Probably Date::Calc.

> and what is the format of the function.

See the docs for the module. Reading the docs doesn't confuse you,
does it?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Tue, 28 Sep 2004 23:44:41 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Number of Days Between 2 Dates.
Message-Id: <2ru4aeF1d8a6sU1@uni-berlin.de>

Brendon Caligari wrote:
> Fred Goldberg wrote:
>> I need help calculating the number of days (including weekends)
>> between two dates.
>> 
>> What module is best to use
> 
> Time::Local should do the trick

Well, I agree, even if I suggested Date::Calc in another message.
Reminds me of another thread in this group:
http://groups.google.com/groups?selm=2pcclbFj9gkjU1%40uni-berlin.de

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 28 Sep 2004 23:00:08 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Number of Days Between 2 Dates.
Message-Id: <slrncljr7o.hv.abigail@alexandra.abigail.nl>

Brendon Caligari (bcaligari@nospam.fireforged.com) wrote on MMMMXLVI
September MCMXCIII in <URL:news:4159d38b$0$94918$bed64819@news.gradwell.net>:
__  Fred Goldberg wrote:
__  
__ > I have the current releace of ActiveState for Win32.
__ > 
__ > I'm confused by the shear number of time and date modules and exactly what 
__ > they are capable of doing. I need help calculating the number of days 
__ > (including weekends) between two dates. All dates are in the format of 
__ > mm/dd/yyyy. This format can be changed if needed.
__ > 
__ > What module is best to use and what is the format of the function. Thanks.
__  
__  Time::Local should do the trick


Well, it can do the trick, and so can Math::BigInt. 

__  The docs are pretty straight forward.  timelocal is most likely the 
__  function you're after.

Really? If I look at the pretty straight forward docs, the docs tell me
that timelocal takes a date/time value which is broken down in seconds,
minutes, hours, day of month, month and year (with the month counted 
as January 0, February 1, etc, and some complicated rules on what the
year should be), and returns an integer giving us seconds
since January 1, 1970 GMT. (It falsely says midnight, but it's actually
about half a minute past midnight, due to leap seconds).

It takes some extra work to use this to calculate the difference between
two dates correctly. The docs also say it may not work for dates before
Jan 1, 1970. Nor will it, according to the docs, work on most systems
for dates before Dec 1901, or after Jan 2038.

I'd say that while it's not impossible to use Time::Local, it's awkward,
and will only work for a limited set of dates.

Date::Calc on the other hand has a function, Delta_Days() that does
exactly what the OP wants.


Abigail
-- 
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()


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

Date: 29 Sep 2004 07:18:48 +1000
From: ? the Platypus {aka David Formosa} <dformosa@zeta.org.au>
Subject: Re: Perl vs PHP
Message-Id: <m3hdpiccsn.fsf@dformosa.zeta.org.au>

"Jürgen Exner" <jurgenex@hotmail.com> writes:

[...]

> How do you call the opposite of a tautology (i.e always false)?

A contradiction.

-- 
Please excuse my spelling as I suffer from agraphia. See
http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more.
Free the Memes.


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

Date: Tue, 28 Sep 2004 17:50:21 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl vs PHP
Message-Id: <slrncljqld.frq.tadmc@magna.augustmail.com>

? the Platypus {aka David Formosa} <dformosa@zeta.org.au> wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> writes:
> 
> [...]
> 
>> How do you call the opposite of a tautology (i.e always false)?
> 
> A contradiction.


David, why are you answering 4-month old posts?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 28 Sep 2004 14:51:25 -0500
From: "Billy N. Patton" <b-patton@ti.com>
Subject: pipes problem
Message-Id: <cjcfbu$3jf$1@home.itg.ti.com>

I have this bit of code:

The followfing sets $stat correctly : to 0
   my $stat = 0;
   $ret = undef;
   $ret = `$command`;
   $stat = $? >> 8;


The follow sets $stat to 1, Incorrect.
#  open PIPE , "$command 2>&1 |";
#  while (<PIPE>)
#  {
#    Lis($_);
#    $ret .= $_;
#  }
#  $stat = close PIPE;

in book "Programming Perl"  @nd Edition , Covers perl5
Page 342.  Last 5 lines
the exit sataus of the child process is haaarvested by the parent 
process when it eventually doeas a wait(2) system call.  But this 
happens in the close function, not in the open function.  And that's why 
you have to check the return vallue of your close function.


I tried this and got the proper return code:
   close PIPE;
   $stat = $? >> 8;

Even this worked:
   close PIPE;
   $stat = $?;


I don't understand?????

My goal here is to execute a system command and be able to capture the 
stdout/stderr as it is happening.  I don't like programs that simply sit 
and give you no indication anything is happening.


-- 
    ___  _ ____       ___       __  __
   / _ )(_) / /_ __  / _ \___ _/ /_/ /____  ___
  / _  / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/   \_,_/\__/\__/\___/_//_/
            /___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455,  b-patton@ti.com


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

Date: Tue, 28 Sep 2004 18:11:35 -0400
From: Scott W Gifford <gifford@umich.edu>
Subject: Re: pipes problem
Message-Id: <qsz7jqeniw8.fsf@tetris.gpcc.itd.umich.edu>

"Billy N. Patton" <b-patton@ti.com> writes:

[...]

> The follow sets $stat to 1, Incorrect.
> #  open PIPE , "$command 2>&1 |";
> #  while (<PIPE>)
> #  {
> #    Lis($_);
> #    $ret .= $_;
> #  }
> #  $stat = close PIPE;

The answer is in the documentation for the close function:

               If the file handle came from a piped open "close" will
               additionally return false if one of the other system
               calls involved fails or if the program exits with
               non-zero status.  (If the only problem was that the
               program exited non-zero $!  will be set to 0.)  Closing
               a pipe also waits for the process executing on the pipe
               to complete, in case you want to look at the output of
               the pipe afterwards, and implicitly puts the exit
               status value of that command into $?.

So your only guarantee is that close will return true if $command
didn't start or exited nonzero.  To find out why it failed, you need
to look at $! and $?.

----ScottG.


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

Date: 28 Sep 2004 20:09:23 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Precedence of exponentiation
Message-Id: <slrncljh7j.hv.abigail@alexandra.abigail.nl>

David Frauzel (nemo@weathersong.net) wrote on MMMMXLVI September MCMXCIII
in <URL:news:1096358481.+REFL6EXh2AXJkQo5lHw+g@teranews>:
:)  Joe Smith <Joe.Smith@inwap.com> wrote in
:)  news:3v86d.122127$MQ5.77934@attbi_s52: 
:)  
:) > Perl cannot be parsed simply by looking at tokens.
:) > My favorite example is this:
:) > 
:) > cat temp.pl
:) >    print time / 2 ; # / ; die "This die() is *not* executed!!";
:) >    print sort / 2 ; # / ; warn "This warn() *is* executed.";
:) > perl -l temp.pl
:)  
:)  The lexer catches that, though, not the parser. :) It's still all a matter 
:)  of tokens - but / / must be recognized as m// in the lexer. A recursive 
:)  character-based (state machine) lexical analyzer should be able to handle 
:)  such situations.

The lexer can only catch that if it gets feedback from the parser.
Without knowing what to expect, a lexer can't know whether a token
that starts with a / is a division, or a regex.



Abigail
-- 
perl -wle '$, = " "; sub AUTOLOAD {($AUTOLOAD =~ /::(.*)/) [0];}
           print+Just (), another (), Perl (), Hacker ();'


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

Date: Tue, 28 Sep 2004 17:57:46 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: references to filehandle?
Message-Id: <slrncljr3a.frq.tadmc@magna.augustmail.com>

Abhinav <matrix_calling@yahoo.dot.com> wrote:
> Michele Dondi wrote:
>> On 27 Sep 2004 13:41:22 GMT, "A. Sinan Unur"
>> <usa1@llenroc.ude.invalid> wrote:
>> 
>> 
>>>>      open my $fh, '>', $m or
>>>>        die "Can't write to `$m': $!\n";

>>>I am going to suggest dropping the \n 
>>>from the error message. 
>> 
>> Hehe! Opinions tend to vary here... IMHO the user should not be
>> interested in the additional info that omitting \n supplies,


> That was interesting behaviour(for me..). Where can I find more about this ?


If you are interested in the die() function, an offbeat place to
look might be the documentation for the die() function...

   perldoc -f die

Please stop asking hundreds of people around the world to read
the docs to you, simply read them yourself and post only if you
still have questions after that.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 29 Sep 2004 00:31:59 +0200
From: peter pilsl <pilsl@goldfisch.at>
Subject: unicode: is decode-process-encode a "good" aproach?
Message-Id: <4159e6df$1@e-post.inode.at>


Thnx to Alan and Shawn for their reply to my last posting. I read a lot 
of docs before, after and still do, but its all very confusing.

Finally I found an aproach that is actually working to me and I wanted 
to ask you if this makes sense and *might* even work for longer or if it 
just cries for troubles.

I read parameters delivered by the webbrowser (html-header is always 
UTF-8 !!), and want to sort and lowercase them and print them out again.
I dont set STDIN and STDOUT to ":utf8", cause this does not work with 
mod_perl.


 ....
my $input=$cgi->param('myfield');
utf8::decode($input);
utf8::downgrade($input);     # otherwise sort will not sort according to
	 		     # my LC_COLLATE-setting and I need 

                              # localized sort (mainly german data)


my $value=do_a_lot($input);  # do some dataprocessing including sorting

utf8::upgrade($value);       # otherwise the lc() in the next line would
                              # not lower chars like german umlauts
$value=lc($value);
utf8::downgrade($value);     # to make sort work again

$value=do_a_lot_more($value); # do some more dataprocessing and sorting

utf8::encode($value);
print $value;


So is it ok to get the data somehow "raw" from the webinterface, then 
decode it, process it and encode it again to print it out or is this a 
rather stupid approach?

Is it normal that I need to decode values delivered by an webpage that 
has UTF-8 charset in its header?

Is it ok to clear the utf-8 flag to make sorting work in a locale-way 
and set the flag again to make lc() work?  Or does this just show that 
there is something wrong in my script?
If I use Unicode::Collate I would not need this fiddling with utf-8, but 
this is very slow (cause it loads the big allkeys.txt - file) and might 
cause troubles in multithreaded applications (as I read somewhere)

I did not provide a full script, cause this posting is long enough that 
way. Hope this is ok.


I also tried to replace the utf8::encode/decode with Encode::from_to but 
failed so far, cause I actually dont know from what to what I like to 
convert. One side is utf8 but what is the other side?


thnx a lot,
peter





-- 
http://www2.goldfisch.at/know_list
http://leblogsportif.sportnation.at


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

Date: 28 Sep 2004 12:19:29 -0700
From: binnyva@hotmail.com (Binny V A)
Subject: What is this error?
Message-Id: <68cd8f94.0409281119.66d56f0b@posting.google.com>

Hello Everyone,

I have made many shell scripts using perl. Some of them are available
at http://www.geocities.com/binnyva/code/perl/shell_scripts/index.html.
When I user perl to create shell scripts, I get a error message that I
don't understand.

It appears when this code is used

# Get a list of all matching files
my $list;
$list = `dir /b *.htm`;
my @LIST = split(/\s+/, $list);

This script shows the error...
dir: /b: No such file or directory (ENOENT)

Anyway the script works fine and does everything I would expect of it
- except for showing the error. I just want to know what that error is
and how to avoid it.

Thank You,
Binny V A.
http://www.geocities.com/binnyva


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

Date: Tue, 28 Sep 2004 15:51:18 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: What is this error?
Message-Id: <gtudnVzfafoqXcTcRVn-vQ@adelphia.com>

Binny V A wrote:

> # Get a list of all matching files
> my $list;
> $list = `dir /b *.htm`;
> my @LIST = split(/\s+/, $list);
> 
> This script shows the error...
> dir: /b: No such file or directory (ENOENT)

The "dir" command is often aliased to "ls -l" - that's a fairly common 
alias on UNIX systems, and the "-l" option gives the long-format listing 
similar to that produced by "dir" on DOS.

But an alias is a simple beast; it does a simple text substitution, and 
doesn't know how to translate the "/b" switch to the correct "ls" 
option. So the result after the alias is expanded is "ls -l /b" - which 
attempts to list the contents of a non-existant directory /b.

To correct the problem, use the UNIX "ls" command directly. Check the 
man page for ls to see what the option is that corresponds to the DOS 
"dir /b" option.

This has *nothing* to do with Perl, by the way - you'd get precisely the 
same results calling "dir /b" from a bash, Python, or Ruby script, or a 
compiled C/C++ program.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Tue, 28 Sep 2004 15:08:13 -0500
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: What is this error?
Message-Id: <cjcgbe$53f1@onews.rockwellcollins.com>

Binny V A wrote:
> 
> When I user perl to create shell scripts, I get a error message that 
> I don't understand.

If you get an error from _perl_ that you don't understand, look it up in
the perldiag manpage. (Type "perldoc perldiag" at a command prompt.)

> $list = `dir /b *.htm`;
> [...]
> dir: /b: No such file or directory (ENOENT)

This is not a perl error, it's an error from the program that you're
calling (dir). If you don't understand it, you should read the
documentation (if any) for the program, or ask in a forum that discusses
the program.

At any rate, the error appears to be perfectly descriptive -- it's
telling you that there are no files matching the provided pattern: *.htm

> Anyway the script works fine and does everything I would expect of it
> - except for showing the error. I just want to know what that error is
> and how to avoid it.

The reason the error isn't causing problems is that (as an error
message) it's being printed on STDERR -- backticks only capture STDOUT.
Maybe you should leave the error as-is. After all, it might be important
to the user that no matching files were found. If you really want to
suppress the error, you'll have to look up how to redirect STDERR for
your shell. (This is not a perl issue.)

For this particular case, the simple solution is to not go to the shell
at all. You can get the file directly within Perl:

    my @LIST = glob('*.htm');

See 'perldoc -f glob' (type it at a command prompt) for more information.

-mjc


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

Date: Tue, 28 Sep 2004 21:26:26 +0000
From: Brendon Caligari <bcaligari@nospam.fireforged.com>
Subject: Re: What is this error?
Message-Id: <4159d704$0$94918$bed64819@news.gradwell.net>

Binny V A wrote:

> Hello Everyone,
> 
> I have made many shell scripts using perl. Some of them are available
> at http://www.geocities.com/binnyva/code/perl/shell_scripts/index.html.
> When I user perl to create shell scripts, I get a error message that I
> don't understand.
> 
> It appears when this code is used
> 
> # Get a list of all matching files
> my $list;
> $list = `dir /b *.htm`;
> my @LIST = split(/\s+/, $list);
> 
> This script shows the error...
> dir: /b: No such file or directory (ENOENT)

:-)  The '/b' parameter is valid on MS-DOS but not on Linux or whatever 
is being used.  Also, to list the directory contents use 'ls' over 'dir'

In perl you can open a directory with 'opendir' and read the contents 
with 'readdir'.

perldoc -f readdir

B


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

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


Administrivia:

#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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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