[31836] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3099 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 26 14:09:29 2010

Date: Thu, 26 Aug 2010 11:09:11 -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           Thu, 26 Aug 2010     Volume: 11 Number: 3099

Today's topics:
        Help writing 'simple' loop JoeyF1276@earthlink.net
    Re: Help writing 'simple' loop <sherm.pendley@gmail.com>
    Re: Help writing 'simple' loop (Randal L. Schwartz)
    Re: Help writing 'simple' loop JoeyF1276@earthlink.net
    Re: Help writing 'simple' loop (Randal L. Schwartz)
    Re: Help writing 'simple' loop <ben@morrow.me.uk>
    Re: Help writing 'simple' loop <cartercc@gmail.com>
    Re: Help writing 'simple' loop <sherm.pendley@gmail.com>
    Re: Odd file test behaviour on 64 bit windows <nospam-abuse@ilyaz.org>
    Re: perl split <jwkrahn@example.com>
        report graphing <jtbutler1978@gmail.com>
    Re: report graphing <smallpond@juno.com>
    Re: report graphing <sherm.pendley@gmail.com>
    Re: report graphing <jtbutler1978@gmail.com>
    Re: report graphing <glex_no-spam@qwest-spam-no.invalid>
    Re: report graphing <cartercc@gmail.com>
    Re: Writing or copying file to another directory <sherm.pendley@gmail.com>
    Re: Writing or copying file to another directory <tadmc@seesig.invalid>
    Re: Writing or copying file to another directory <paul@pstech-inc.com>
    Re: Writing or copying file to another directory <paul@pstech-inc.com>
    Re: Writing or copying file to another directory <ben@morrow.me.uk>
    Re: Writing or copying file to another directory <mvdwege@mail.com>
    Re: Writing or copying file to another directory <sherm.pendley@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 26 Aug 2010 08:45:44 -0700
From: JoeyF1276@earthlink.net
Subject: Help writing 'simple' loop
Message-Id: <3k2d761qidbnp0ho9njbc05hao6nvdtjh1@4ax.com>

$h1_right through $h10_right are 10 independent integer values. 

$hTotalRight = $h1_right + $h2_right + $h3_right + $h4_right + $h5_right +
$h6_right + $h7_right + $h8_right + $h9_right + $h10_right;

I can't figure out the syntax for $XXX to write a loop to do the addition.
$hTotalRight = 0;
for ($i=1;$i<11;$i++) {
$hTotalRight = $hTotalRight + $XXX;
}

What is the syntax for $XXX?

TIA,

Joey


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

Date: Thu, 26 Aug 2010 12:04:03 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: Help writing 'simple' loop
Message-Id: <m28w3tpdho.fsf@sherm.shermpendley.com>

JoeyF1276@earthlink.net writes:

> $h1_right through $h10_right are 10 independent integer values. 

That's your problem right there.

> $hTotalRight = $h1_right + $h2_right + $h3_right + $h4_right + $h5_right +
> $h6_right + $h7_right + $h8_right + $h9_right + $h10_right;

When you find yourself using variable names like $h1, $h2, ... $hN,
that's a VERY good sign you should be using an array @n instead.

> I can't figure out the syntax for $XXX to write a loop to do the addition.
> $hTotalRight = 0;
> for ($i=1;$i<11;$i++) {
> $hTotalRight = $hTotalRight + $XXX;
> }

  my $hTotalRight;
  foreach my $h (@hRight) {
    $hTotalRight += $h;
  }

sherm--

-- 
Sherm Pendley                
										 <camelbones.sourceforge.net>
Cocoa Developer


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

Date: Thu, 26 Aug 2010 09:13:31 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: JoeyF1276@earthlink.net
Subject: Re: Help writing 'simple' loop
Message-Id: <86mxs9xsgk.fsf@red.stonehenge.com>

>>>>> "JoeyF1276" == JoeyF1276  <JoeyF1276@earthlink.net> writes:

JoeyF1276> $h1_right through $h10_right are 10 independent integer
JoeyF1276> values. 

And yet, they're related, and you'll want to do something to all of
them, which means they should be in an array instead.

That will simplify your final step.

In general, variables that contain "1" "2" "3" in their name are
mis-structured... and should be refactored into being elements of an
array, or possibly a hash.

I've seen policies that take this to an extreme, forbidding the use of
*all* digits in variable names.   But then you end up with
thedailwtf.com-worthy entries like "$foo_three" and "$foo_four". :)

print "Just another Perl hacker,"; # the original

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


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

Date: Thu, 26 Aug 2010 09:32:49 -0700
From: JoeyF1276@earthlink.net
Subject: Re: Help writing 'simple' loop
Message-Id: <pm5d769u3rdhdss6a0e7hnbg8oes4r2s91@4ax.com>

Sherm Pendley wrote:

>JoeyF1276@earthlink.net writes:
>
>> $h1_right through $h10_right are 10 independent integer values. 
>
>That's your problem right there.
>
>> $hTotalRight = $h1_right + $h2_right + $h3_right + $h4_right + $h5_right +
>> $h6_right + $h7_right + $h8_right + $h9_right + $h10_right;
>
>When you find yourself using variable names like $h1, $h2, ... $hN,
>that's a VERY good sign you should be using an array @n instead.
>
>> I can't figure out the syntax for $XXX to write a loop to do the addition.
>> $hTotalRight = 0;
>> for ($i=1;$i<11;$i++) {
>> $hTotalRight = $hTotalRight + $XXX;
>> }
>
>  my $hTotalRight;
>  foreach my $h (@hRight) {
>    $hTotalRight += $h;
>  }
>
Thank you, but I don't understand how you are defining @hRight.
-- 
Joey


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

Date: Thu, 26 Aug 2010 09:51:15 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Help writing 'simple' loop
Message-Id: <86d3t5xqpo.fsf@red.stonehenge.com>


>>>>> "JoeyF1276" == JoeyF1276  <JoeyF1276@earthlink.net> writes:
[some stuff]

By the way, "Joey", it's not cool to impersonate an email address
that doesn't belong to you (since it just bounced when I tried).

If you want an invalid address, please use a domain of ".invalid", so
that we don't try to start an email conversation with you.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


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

Date: Thu, 26 Aug 2010 17:56:54 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Help writing 'simple' loop
Message-Id: <mviik7-34o2.ln1@osiris.mauzo.dyndns.org>


Quoth JoeyF1276@earthlink.net:
> Sherm Pendley wrote:
> >JoeyF1276@earthlink.net writes:
> >
> >> $h1_right through $h10_right are 10 independent integer values. 
> >
> >That's your problem right there.
> >
> >> $hTotalRight = $h1_right + $h2_right + $h3_right + $h4_right + $h5_right +
> >> $h6_right + $h7_right + $h8_right + $h9_right + $h10_right;
> >
> >When you find yourself using variable names like $h1, $h2, ... $hN,
> >that's a VERY good sign you should be using an array @n instead.
> >
> >> I can't figure out the syntax for $XXX to write a loop to do the addition.
> >> $hTotalRight = 0;
> >> for ($i=1;$i<11;$i++) {
> >> $hTotalRight = $hTotalRight + $XXX;
> >> }
> >
> >  my $hTotalRight;
> >  foreach my $h (@hRight) {
> >    $hTotalRight += $h;
> >  }
> >
> Thank you, but I don't understand how you are defining @hRight.

Go through your program. Wherever you have $h1_right replace it with
$hRight[0]. Wherever you have $h2_right replace it with $hRight[1]. And
so on. Declare @hRight wherever it was you declared those $h*_right
variables originally.

Yes, this might be quite a bit of work, but that's what happens whn you
make a fundamental mistake up-front. Any decent editor will be able to
do the bulk of it for you.

Ben



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

Date: Thu, 26 Aug 2010 10:20:24 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Help writing 'simple' loop
Message-Id: <1197c4e7-6e92-436e-87a1-9c85573cf60e@v8g2000yqe.googlegroups.com>

On Aug 26, 11:45=A0am, JoeyF1...@earthlink.net wrote:
> I can't figure out the syntax for $XXX to write a loop to do the addition=
 .

Here is a simple Perl script that adds numbers four different ways.
Note that shift() returns the first element of the array and
destructively alters the array,

CC.

#! perl

use strict;
use warnings;

my @numbers =3D (4, 65, 23, 12, 5, 3, 11, -23);
my $rv;
print "My numbers are [@numbers]\n";

$rv =3D rec_sum(@numbers);
print "recursive rv is $rv\n";

$rv =3D iter_sum(@numbers);
print "iterative rv is $rv\n";

$rv =3D while_sum(@numbers);
print "while_sum rv is $rv\n";

$rv =3D for_sum(@numbers);
print "for_sum rv is $rv\n";

sub rec_sum
{
   my @n =3D @_;
   if (scalar(@n) =3D=3D 0) { return 0; }
   else { return shift(@n) + rec_sum(@n); }
}

sub iter_sum
{
   my @n =3D @_;
   my $acc =3D 0;
   foreach my $num (@n) { $acc +=3D $num; }
   return $acc;
}

sub while_sum
{
    my @n =3D @_;
    my $acc =3D 0;
    while (scalar(@n) > 0) { $acc +=3D shift(@n); }
    return $acc;
}

sub for_sum
{
    my @n =3D @_;
    my $acc =3D 0;
    for (my $i =3D 0; $i < scalar(@n); $i++) { $acc +=3D $n[$i]; }
    return $acc;
}


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

Date: Thu, 26 Aug 2010 13:48:16 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: Help writing 'simple' loop
Message-Id: <m24oehp8nz.fsf@sherm.shermpendley.com>

JoeyF1276@earthlink.net writes:

> Sherm Pendley wrote:
>
>>JoeyF1276@earthlink.net writes:
>>
>>> $h1_right through $h10_right are 10 independent integer values. 
>>
>>That's your problem right there.
>>
>>> $hTotalRight = $h1_right + $h2_right + $h3_right + $h4_right + $h5_right +
>>> $h6_right + $h7_right + $h8_right + $h9_right + $h10_right;
>>
>>When you find yourself using variable names like $h1, $h2, ... $hN,
>>that's a VERY good sign you should be using an array @n instead.
>>
>>> I can't figure out the syntax for $XXX to write a loop to do the addition.
>>> $hTotalRight = 0;
>>> for ($i=1;$i<11;$i++) {
>>> $hTotalRight = $hTotalRight + $XXX;
>>> }
>>
>>  my $hTotalRight;
>>  foreach my $h (@hRight) {
>>    $hTotalRight += $h;
>>  }
>>
> Thank you, but I don't understand how you are defining @hRight.

Sorry, I can only make suggestions regarding the code I can see. Post
the code you're currently using to define $h1_right, $h2_right, etc.,
and then I can help convert that part to use an array too.

sherm--

-- 
Sherm Pendley                
										 <camelbones.sourceforge.net>
Cocoa Developer


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

Date: Wed, 25 Aug 2010 22:31:31 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Odd file test behaviour on 64 bit windows
Message-Id: <slrni7b6e3.pua.nospam-abuse@powdermilk.math.berkeley.edu>

On 2010-08-25, Malcolm Hoar <malch@malch.com> wrote:
> In article <7bc0ff5a-ac92-49b1-972c-ca09429b139a@w30g2000yqw.googlegroups.com>, Simon Andrews <simon.andrews@bbsrc.ac.uk> wrote:
>>I'm assuming this is some magic I've not seen before, but I don't know
>>if it's perl or windows which is messing this up.
>
> I'm pretty sure you're seeing some Windows magic that
> takes place with 32-bit apps on a 64-bit O.S.
>
> You are running Perl compiled in 32-bit, right?
>
> If you want to see a true and accurate picture of the
> system disk file system on 64-bit Windows, you need to
> run a version of Perl compiled in 64-bit.
>
> It's not just a Perl issue; you'll see this weirdness
> with other 32 bit apps on 64-bit Windows.

And it is not just that: programs run with elevated privileges may see
more or fewer files in the same directory than programs run with
normal privileges (even on 32bit Win).  "Less" may be explained due to
virtualization.  I did not find any explanation why "more" is
legitimate.

So I think one may need several flavors of perl, compiled with
different manifests...

Ilya


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

Date: Wed, 25 Aug 2010 20:25:52 -0700
From: "John W. Krahn" <jwkrahn@example.com>
Subject: Re: perl split
Message-Id: <c9ldo.1371$rC7.1174@newsfe10.iad>

Klaus wrote:
> On 25 août, 19:56, James<hslee...@yahoo.com>  wrote:
>> But why this behavior?
>> $ perl -le '@a=split/(.)/,"abc"; print $#a; print for(@a)'
>> 5
>>
>> a
>>
>> b
>>
>> c
>
> Looks normal to me: you split with any character as separator, so you
> get:
>
> - an empty string before the separator 'a'
> - then, because you have put brackets into the regex, the separator
> ('a' in this case) is added
> - then another empty string between the two separators 'a' and 'b'
> - then, again, you have put brackets into the regex, so you get the
> second separator ('b' in this case)
> - then yet another empty string between the two separators 'b' and 'c'
> - finally you get the last separator 'c'

And finally you get the last empty string between 'c' and the 
end-of-string, which is discarded because it is a trailing empty string. 
  If you want to see it use a negative number as the third argument to 
split:

$ perl -le '@a=split/(.)/,"abc",-1; print $#a; print for(@a)'
6

a

b

c




John
-- 
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein


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

Date: Thu, 26 Aug 2010 06:35:11 -0700 (PDT)
From: androidUser78 <jtbutler1978@gmail.com>
Subject: report graphing
Message-Id: <31488a8f-1f85-4e6a-be2a-2d2b4b7555d5@k10g2000yqa.googlegroups.com>

I am not sure where else to post this but I am running a LAMP
environment and my users now want historical graphical reporting. For
instance, normally the user would have a web interface and submit a
bunch of parameters to it and I would spit back a report. But now they
want this report to be graphical and they want it to keep historical
information of their parameters. So for instance at 9am they want to
see how many hits a site got (assume for example purposes we store in
the DB). Then at 9:10, the report is refreshed and they see how many
hits we have gotten since 9am, then 9:20, etc, etc. The interface and
backend stuff is already done but does anyone use or know of any tools
that would help me plot this stuff? I looked at Cacti but it seems
like it only takes a script that you need to enter into the web
interface.

Any input is appreciated.

Jim


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

Date: Thu, 26 Aug 2010 10:08:14 -0400
From: Steve C <smallpond@juno.com>
Subject: Re: report graphing
Message-Id: <i55sgo$dc2$1@news.eternal-september.org>

On 08/26/2010 09:35 AM, androidUser78 wrote:
> I am not sure where else to post this but I am running a LAMP
> environment and my users now want historical graphical reporting. For
> instance, normally the user would have a web interface and submit a
> bunch of parameters to it and I would spit back a report. But now they
> want this report to be graphical and they want it to keep historical
> information of their parameters. So for instance at 9am they want to
> see how many hits a site got (assume for example purposes we store in
> the DB). Then at 9:10, the report is refreshed and they see how many
> hits we have gotten since 9am, then 9:20, etc, etc. The interface and
> backend stuff is already done but does anyone use or know of any tools
> that would help me plot this stuff? I looked at Cacti but it seems
> like it only takes a script that you need to enter into the web
> interface.
>


use Chart;
if you want to have the db and just want to roll your own graphics.

use rrdtool if you want to set up something new to store the data for you and
to generate plots.



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

Date: Thu, 26 Aug 2010 10:11:16 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: report graphing
Message-Id: <m21v9lwjjv.fsf@sherm.shermpendley.com>

androidUser78 <jtbutler1978@gmail.com> writes:

> backend stuff is already done but does anyone use or know of any tools
> that would help me plot this stuff?

You might have a look at GD::Graph:

  <http://search.cpan.org/perldoc?GD::Graph>

It's worked well enough for me in the past, but my graphing needs were
pretty simple. YMMV.

sherm--

-- 
Sherm Pendley                
										 <camelbones.sourceforge.net>
Cocoa Developer


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

Date: Thu, 26 Aug 2010 08:09:34 -0700 (PDT)
From: androidUser78 <jtbutler1978@gmail.com>
Subject: Re: report graphing
Message-Id: <68b2a95e-c200-4ad0-9c89-3d2f3d2305b8@f6g2000yqa.googlegroups.com>

On Aug 26, 10:08=A0am, Steve C <smallp...@juno.com> wrote:
> On 08/26/2010 09:35 AM, androidUser78 wrote:
>
> > I am not sure where else to post this but I am running a LAMP
> > environment and my users now want historical graphical reporting. For
> > instance, normally the user would have a web interface and submit a
> > bunch of parameters to it and I would spit back a report. But now they
> > want this report to be graphical and they want it to keep historical
> > information of their parameters. So for instance at 9am they want to
> > see how many hits a site got (assume for example purposes we store in
> > the DB). Then at 9:10, the report is refreshed and they see how many
> > hits we have gotten since 9am, then 9:20, etc, etc. The interface and
> > backend stuff is already done but does anyone use or know of any tools
> > that would help me plot this stuff? I looked at Cacti but it seems
> > like it only takes a script that you need to enter into the web
> > interface.
>
> use Chart;
> if you want to have the db and just want to roll your own graphics.
>
> use rrdtool if you want to set up something new to store the data for you=
 and
> to generate plots.

I am reading about rrdtool. Will it be able to handle a result set
from a DB and be able to store it in its own DB?


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

Date: Thu, 26 Aug 2010 10:23:21 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: report graphing
Message-Id: <4c7686ea$0$89386$815e3792@news.qwest.net>

androidUser78 wrote:
> I am not sure where else to post this but I am running a LAMP
> environment and my users now want historical graphical reporting. For
> instance, normally the user would have a web interface and submit a
> bunch of parameters to it and I would spit back a report. But now they
> want this report to be graphical and they want it to keep historical
> information of their parameters. So for instance at 9am they want to
> see how many hits a site got (assume for example purposes we store in
> the DB). Then at 9:10, the report is refreshed and they see how many
> hits we have gotten since 9am, then 9:20, etc, etc. The interface and
> backend stuff is already done but does anyone use or know of any tools
> that would help me plot this stuff? I looked at Cacti but it seems
> like it only takes a script that you need to enter into the web
> interface.
> 
> Any input is appreciated.
> 
> Jim

If the same thing was to run every x minutes and you wanted to see 
trends over time, for example:

http://cricket.sourceforge.net/

I know it's not a perl solution, however since you mention a Web
interface, there are plenty of Javascript based graphing libraries:
dygraph, Eastwood Charts, Google Charts, ExtJS, etc..  You could
have a simple CGI that stores the parameters, calculate/fetch the
results, then provide it as XML, CSV, JSON, name/value pairs, etc. to
one of those interfaces to create some very, very nice graphs/charts.


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

Date: Thu, 26 Aug 2010 09:55:33 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: report graphing
Message-Id: <6af508fa-eee1-4059-99c4-d2a1df72687a@j18g2000yqd.googlegroups.com>

On Aug 26, 9:35=A0am, androidUser78 <jtbutler1...@gmail.com> wrote:
> I am not sure where else to post this but I am running a LAMP
> environment and my users now want historical graphical reporting. For
> instance, normally the user would have a web interface and submit a
> bunch of parameters to it and I would spit back a report. But now they
> want this report to be graphical

I routinely produce a large number of visualizations of historical
data.
(1) Run a database query, which means that you store your data in a DB
(2) Run a Perl script using your query results as the input data
(3) I use GD::Graph to produce GIFs.

I format my output as PDF files, I normally produce several dozen at a
time graphing different things and my report is typically over ten
pages long with six GIFs on each page.

It would be easy to create a link (or input button) that runs the
query, formats the data, creates the GIF dynamically, and displays it
on your web page. As others may point out, there are tools that do
this for you, but if you use Perl (which you do on your LAMP stack)
it's probably just as well to roll your own.

GD::Graph isn't too difficult if you only want simple stuff. I haven't
mastered it but I can certainly use it to create as many simple charts
as I want.

CC.


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

Date: Wed, 25 Aug 2010 18:29:34 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: Writing or copying file to another directory
Message-Id: <m2hbiimilt.fsf@sherm.shermpendley.com>

Ben Morrow <ben@morrow.me.uk> writes:

> ? Have you read the Posting Guidelines? (The fact you didn't write this
> doesn't excuse you.)

More to the point, the fact that you didn't write this script doesn't
make its many problems any less problematic. It needs a *lot* of work,
so unless you want to dive in and become a Perl developer yourself,
my best advice to you is to find a better one.

NMS formmail has a good reputation:

  <http://nms-cgi.sourceforge.net/>

I think I recall you mentioning DreamHost in another group - they have
a built-in formmail script you can use:

  <http://wiki.dreamhost.com/Formmail>

sherm--

-- 
Sherm Pendley                
										 <camelbones.sourceforge.net>
Cocoa Developer


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

Date: Wed, 25 Aug 2010 18:16:35 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Writing or copying file to another directory
Message-Id: <slrni7b8qf.3or.tadmc@tadbox.sbcglobal.net>

Paul E. Schoen <paul@pstech-inc.com> wrote:

> $recipient= "paul\@peschoen.com" ;      # make sure to \ escape the @


$recipient= 'paul@peschoen.com'; # make sure to use the appropriate quotes...


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


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

Date: Thu, 26 Aug 2010 02:44:37 -0400
From: "Paul E. Schoen" <paul@pstech-inc.com>
Subject: Re: Writing or copying file to another directory
Message-Id: <I3odo.1380$rC7.182@newsfe10.iad>

"Ben Morrow" <ben@morrow.me.uk> wrote in message 
news:jeggk7-7hb2.ln1@osiris.mauzo.dyndns.org...
>
>
> Where is
>
>    use warnings;
>    use strict;

It works with warnings, but strict causes it to fail

> ? Have you read the Posting Guidelines? (The fact you didn't write this
> doesn't excuse you.)

Yes, I have read the guidelines, and I think I followed them to the best of 
my ability as a newbie.


>> # Get the CGI input variables
>> %in= &getcgivars ;
>
> Don't call subs with '&'.

It did not work when I removed the &


>> open(MAIL, "|$mailprog $recipient")
>>     || &HTMLdie("Couldn't send the mail (couldn't run $mailprog).") ;
>
> Use multi-arg open.
> Use lexical filehandles.
>
>    open(my $MAIL, "|-", $mailprog, $recipient)
>        || HTMLdie("...");

It does not work with "my".


>> close(MAIL) ;
>
> You are writing to MAIL, so you need to check the return value of close.

Yes, that is good practice. I will need to check the details of the 
function. Boolean?


>> #chdir('/home/pstech/www/SCGBG/'); #still writes to cgi-bin
>
> Does this directory exist? Can the CGI process see it? Is the CGI
> process running chrooted?

The directory exists and I can go there using Telnet "cd 
/home/pstech/www/SCGBG/". I don't know what "chrooted" means.


>> #open DATA1, '>', "/home/pstech/www/SCGBG/output.txt" or HTMLdie ("File
>> error: $!"); #No such file/dir
>
> ...apparently not.

It works in Telnet if I use "pico /home/pstech/www/SCGBG/output.txt"


> Case matters. It's File::Copy.

use File::Copy;     #was Internal server error - Changed case - PES
$file1="output.htm";
$file2="output.txt"; #this works, copies in same directory
copy($file1, $file2) or HTMLdie ("File error: $file2 $!");
$file2="/home/pstech/www/SCGBG/output.htm"; #this fails, no such file or dir
copy($file1, $file2) or HTMLdie ("File error: $file2 $!");

I made the following changes to a test script, ran it directly using Telnet, 
corrected the errors, and now it compiles and works:

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

#!/usr/bin/perl
#
#   TestCopy.pl
#   Written in 2010 by Paul E. Schoen

use warnings;
use strict;

use File::Copy;     #was Internal server error - Changed case - PES
my $file1="output.htm";
my $file2="output.txt"; #this works, copies in same directory
copy($file1, $file2) or HTMLdie ("File error: $file2 $!");
$file2="/home/pstech/www/SCGBG/output.htm"; #this works, copies in other dir
copy($file1, $file2) or HTMLdie ("File error: $file2 $!");

exit ;

# Die, outputting HTML error page
# If no $title, use a default title
sub HTMLdie {
    my($msg, $title)= @_ ;
    $title= "CGI Error" if $title eq '' ;
    print <<EOF ;
Content-type: text/html

<html>
<head>
<title>$title</title>
</head>
<body>
<h1>$title</h1>
<h3>$msg</h3>
</body>
</html>
EOF

    exit ;
}

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

Thanks for your help. I need to learn more about how to debug a script. The 
error messages were very helpful. But I'm not sure if I can run the mailer 
script from Telnet. Is there a way to see the compiler error messages, 
perhaps in an error log?

Paul 



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

Date: Thu, 26 Aug 2010 03:49:28 -0400
From: "Paul E. Schoen" <paul@pstech-inc.com>
Subject: Re: Writing or copying file to another directory
Message-Id: <u0pdo.21120$st2.9990@newsfe09.iad>

I found that, after making corrections to the mailer.js script so it would 
compile from the Telnet command line, it would perform the file copy to the 
other directory where the HTML file is located, outside of cgi-bin. But when 
I run it, or the TestCopy.pl, from the browser, it gives the CGI error:

File error: /home/pstech/www/SCGBG/output.htm No such file or directory

That is a confusing message, as the file does exist in that directory. I 
think it must be something to do with the server configuration. I do need to 
use a different URL:

http://www.smart.net/pstech-cgi-bin/TestCopy.pl

to run the script. If I use the normal URL:

http://www.smart.net/~pstech/cgi-bin/TestCopy.pl

I just get the text of the TestCopy.pl script.

Paul




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

Date: Thu, 26 Aug 2010 09:52:52 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Writing or copying file to another directory
Message-Id: <4kmhk7-f2i2.ln1@osiris.mauzo.dyndns.org>


Quoth "Paul E. Schoen" <paul@pstech-inc.com>:
> "Ben Morrow" <ben@morrow.me.uk> wrote in message 
> news:jeggk7-7hb2.ln1@osiris.mauzo.dyndns.org...
> >
> > Where is
> >
> >    use warnings;
> >    use strict;
> 
> It works with warnings, but strict causes it to fail

So fix the errors. That's the whole point of turning 'strict' on.

> > ? Have you read the Posting Guidelines? (The fact you didn't write this
> > doesn't excuse you.)
> 
> Yes, I have read the guidelines, and I think I followed them to the best of 
> my ability as a newbie.
> 
> 
> >> # Get the CGI input variables
> >> %in= &getcgivars ;
> >
> > Don't call subs with '&'.
> 
> It did not work when I removed the &

Read the docs on how to call subs. In this case you want

    my %in = getcgivars();

> >> open(MAIL, "|$mailprog $recipient")
> >>     || &HTMLdie("Couldn't send the mail (couldn't run $mailprog).") ;
> >
> > Use multi-arg open.
> > Use lexical filehandles.
> >
> >    open(my $MAIL, "|-", $mailprog, $recipient)
> >        || HTMLdie("...");
> 
> It does not work with "my".

In what sense 'does not work'? You did notice the '$', right? That needs
to be added everywhere else you use the filehandle, too (the whole point
is to get a filehandle in a normal variable, rather than the
globally-scoped named filehandles you were using before).

> >> close(MAIL) ;
> >
> > You are writing to MAIL, so you need to check the return value of close.
> 
> Yes, that is good practice. I will need to check the details of the 
> function. Boolean?

perldoc -f close

> >> #chdir('/home/pstech/www/SCGBG/'); #still writes to cgi-bin
> >
> > Does this directory exist? Can the CGI process see it? Is the CGI
> > process running chrooted?
> 
> The directory exists and I can go there using Telnet "cd 
> /home/pstech/www/SCGBG/". I don't know what "chrooted" means.

man 2 chroot

Check the permissions on all the directories in that path. I suspect
that's more likely the problem than chroot.

You can see what user the CGI ends up running as by printing $>. You can
convert that number to a name with

    use User::pwent;

    print getpwuid($>)->name;

> > Case matters. It's File::Copy.
> 
> use File::Copy;     #was Internal server error - Changed case - PES
> $file1="output.htm";
> $file2="output.txt"; #this works, copies in same directory
> copy($file1, $file2) or HTMLdie ("File error: $file2 $!");
> $file2="/home/pstech/www/SCGBG/output.htm"; #this fails, no such file or dir
> copy($file1, $file2) or HTMLdie ("File error: $file2 $!");

This is failing the same as before. You need to find out why the CGI
process can't see the /home/pstech/www/SCGBG directory.

You could try something like

    for (qw(
        / /home /home/pstech /home/pstech/www /home/pstech/www/SCGBG
    )) {
        print "$_: " . (-d $_) . "\n";
    }

which might show you where the problem is.

> Thanks for your help. I need to learn more about how to debug a script. The 
> error messages were very helpful. But I'm not sure if I can run the mailer 
> script from Telnet. Is there a way to see the compiler error messages, 
> perhaps in an error log?

There ought to be. Talk to your provider if you don't know where you
should be looking. You can't possibly debug something if you can't see
the error message.

You can also use the CGI::Carp module to send errors and warnings to the
browser, but remember to turn it off before you put the script into
production (warning messages like that are valuable information for
attackers).

Ben



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

Date: Thu, 26 Aug 2010 13:51:52 +0200
From: Mart van de Wege <mvdwege@mail.com>
Subject: Re: Writing or copying file to another directory
Message-Id: <86r5hlfv6v.fsf@gareth.avalon.lan>

"Paul E. Schoen" <paul@pstech-inc.com> writes:

> "Ben Morrow" <ben@morrow.me.uk> wrote in message
> news:jeggk7-7hb2.ln1@osiris.mauzo.dyndns.org...
>>
>>
>> Where is
>>
>>    use warnings;
>>    use strict;
>
> It works with warnings, but strict causes it to fail
>
This is a bad sign.

If the fix is trivial, fix it, but otherwise, if the script isn't built
to run under 'strict', it's a waste of time to try and rewrite it so it
does.[1]

Mart

[1] And before someone chimes in: yes, that's a rule of thumb, I'm sure
    you can think of exceptions. That's not the point.

-- 
"We will need a longer wall when the revolution comes."
    --- AJS, quoting an uncertain source.


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

Date: Thu, 26 Aug 2010 09:14:25 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: Writing or copying file to another directory
Message-Id: <m2d3t5jz2m.fsf@sherm.shermpendley.com>

"Paul E. Schoen" <paul@pstech-inc.com> writes:

> "Ben Morrow" <ben@morrow.me.uk> wrote in message
> news:jeggk7-7hb2.ln1@osiris.mauzo.dyndns.org...
>>
>>
>> Where is
>>
>>    use warnings;
>>    use strict;
>
> It works with warnings, but strict causes it to fail

Strict doesn't "cause" failures, it simply shows you the failures that
would otherwise have been overlooked.

Like I said, this code is horrid. Kudos to you if you're looking to
learn Perl, but don't start with this script as a basis - you'll learn
some *awful* habits if you do.

sherm--

-- 
Sherm Pendley                
										 <camelbones.sourceforge.net>
Cocoa Developer


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

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


Administrivia:

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

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3099
***************************************


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