[31750] in Perl-Users-Digest
Perl-Users Digest, Issue: 3013 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 1 00:19:30 2010
Date: Wed, 30 Jun 2010 21:19:23 -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 Wed, 30 Jun 2010 Volume: 11 Number: 3013
Today's topics:
Re: Path to another server <jruffino@gailborden.info>
Re: Path to another server <smallpond@juno.com>
Re: Path to another server <ben@morrow.me.uk>
Re: reading from a file into an array in perl <jurgenex@hotmail.com>
The daemon helper, dh is its name <jak@isp2dial.com>
Re: The daemon helper, dh is its name <ben@morrow.me.uk>
Re: The daemon helper, dh is its name <tadmc@seesig.invalid>
Re: The daemon helper, dh is its name <uri@StemSystems.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 30 Jun 2010 18:28:09 -0700 (PDT)
From: Joe <jruffino@gailborden.info>
Subject: Re: Path to another server
Message-Id: <781b8523-688e-4af2-bbbe-4029e57fab5c@s9g2000yqd.googlegroups.com>
On Jun 30, 7:47=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Joe <jruff...@gailborden.info>:
>
> > We are switching from one server to another for our PERL Scripts, and
> > so far everything is working, but I am having problems with on program
> > which works on the old server but not the new one.
>
> > The problem I have is creating a file in a directory on another
> > server. =A0I use "\\\\gailbapps\\cybraryn\\TDmenu\\A-Cyb_Stats\\" as my
> > path to the serever, and to create it, I use open (TOT_TXT,
> > '>{servername and filename}').
>
> > But when I try to write print TOT_TXT "Hello\n";, it does not work.
>
> In what way does it not work?
>
> > Can anyone help? =A0I print out the path and put it in Windows Explorer
> > and it goes right there, so I do not know why it cannot be accessed.
>
> > The code is below:
> > <code>
> > $relative_addy =3D "\\\\gailbapps\\cybraryn\\TDmenu\\A-Cyb_Stats\\";
>
> Are you using 'strict'? If not, why not? If you are, where is this
> variable declared?
>
> Use forward slashes. With a few exceptions (notably paths passed to
> cmd.exe and paths passed to Win32::Process) they work perfectly well on
> Win32 perl.
>
> =A0 =A0 my $relative_addy =3D "//gailbapps/cybraryn/TDmenu/A-Cyb_Stats/";
>
> > $month_year =3D $date_month . "_" . $date_year . ".txt";
>
> > $tot_file =3D $relative_addy . $month_year;
>
> =A0 =A0 my $tot_file =3D "$relative_addy$date_month\_$date_year.txt";
>
> > open (TOT_TXT, '>$tot_file') || die "$tot_file open failed: $!";
>
> Presumably this line succeeds? It does not, however, do what you think
> it does: single quotes don't interpolate, so you are trying to open a
> file called (literally) '$tot_file' in the current directory. I didn't
> think Win32 allowed filenames to have '$' in, but I may be
> misremembering.
>
> You should be using lexical filehandles and 3-arg open:
>
> =A0 =A0 open(my $TOT_TXT, ">", $tot_file)
> =A0 =A0 =A0 =A0 || die "$tot_file open failed: $!";
>
> > print "File: $tot_file<p>";
>
> > print TOT_TXT "Hello\n";
>
> > close(TOT_TXT);
>
> You also need to check the return value of close, to make sure the data
> was actually written successfully. (Checking print is neither necessary
> nor sufficient.)
>
> =A0 =A0 close($TOT_TXT) || die "writing $tot_file failed: $!";
>
> Ben
I would love to use strict, but I have &FormInput; and when I put my
in front of it, I get an error.
But I do get the following error: \\gailbapps\cybraryn\TDmenu\A-
Cyb_Stats\05_2009.txt open failed: Invalid argument at C:\Inetpub
\wwwroot\cgi-bin\CybraryN\test.pl line 50.
Which led me here to ask for help. Below is the complete code:
#!/usr/bin/perl -w
use CGI qw(:standard :html3);
use CGI::Carp qw(fatalsToBrowser);
#use strict;
#Library file that will read the form data and store in
formdata{'value'} form
require '../lib/forminput.lib';
&FormInput;
#$comps =3D "ercomps_test.txt"; # Holder for computer txt file.
my $comps =3D "ercomps.txt"; # Holder for computer txt file.
my $date_month =3D "08"; # Holder for Testing Month.
my $date_year =3D "2009"; # Holder for Testing Year.
my $tot_file =3D $date_month . "_" . $date_year . ".txt";
my $month_year;
my $relative_addy =3D "\\\\gailbapps\\cybraryn\\TDmenu\A-Cyb_Stats\\";
my $cnt =3D 0;
my $dir_cnt =3D 0;
my $dir;
my $dirtoget;
my $formdata;
my @comps;
print "Content-type: text/html\n\n";
print "<html><body>";
print "<head><title>CybraryN ER Computer Statistics</title></head>";
$date_month =3D $formdata{'month'};
$date_year =3D $formdata{'year'};
$month_year =3D $date_month . "_" . $date_year . ".txt";
$tot_file =3D $relative_addy . $month_year;
print "<h2>CybraryN ER Computer Stats</h2>";
print "<h3>For Month-Year of: $date_month-$date_year</h3>";
print "<h3>Get Data for Excel File from <a href=3D'file://V:/TDmenu/A-
Cyb_Stats/'>V:\\TDmenu\\A-Cyb_Stats\\$month_year</a></h3>";
##########################################################################
# Read in text file for the computers to be used, and set to an array.
#
open (COMPSLIST, $comps) || die "$comps open failed: $!";
while (<COMPSLIST>) {
chomp;
$comps[$cnt] =3D $_;
++$cnt;
}
close (COMPSLIST);
# open (TOT_TXT, '>$tot_file') || die "$tot_file open failed: $!";
open (TOT_TXT, '>\\\\gailbapps\\cybraryn\\TDmenu\\A-Cyb_Stats\\
$month_year') || die "$tot_file open failed: $!";
print "File: $tot_file<p>";
print TOT_TXT "Hello\n";
foreach $dir (@comps) {
$dirtoget =3D "\\\\gailbapps\\cybraryn\\TDmenu\\" . $dir . "\
\Meter.dba";
print "Directory: $dirtoget<br />";
++$dir_cnt;
print TOT_TXT $dir_cnt . "\n";
open (METER, '$dirtoget') || die "$dirtoget open failed: $!";
while (<METER>) {
chomp;
print "Record: $_<br />";
}
}
close(METER);
close($TOT_TXT) || die "writing $tot_file failed: $!";
------------------------------
Date: Wed, 30 Jun 2010 19:11:35 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: Path to another server
Message-Id: <f1b20a26-e74f-4138-88e0-63d00ccccc14@5g2000yqz.googlegroups.com>
On Jun 30, 9:28=A0pm, Joe <jruff...@gailborden.info> wrote:
> On Jun 30, 7:47=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
>
>
>
> > Quoth Joe <jruff...@gailborden.info>:
>
> > > We are switching from one server to another for our PERL Scripts, and
> > > so far everything is working, but I am having problems with on progra=
m
> > > which works on the old server but not the new one.
>
> > > The problem I have is creating a file in a directory on another
> > > server. =A0I use "\\\\gailbapps\\cybraryn\\TDmenu\\A-Cyb_Stats\\" as =
my
> > > path to the serever, and to create it, I use open (TOT_TXT,
> > > '>{servername and filename}').
>
> > > But when I try to write print TOT_TXT "Hello\n";, it does not work.
>
> > In what way does it not work?
>
> > > Can anyone help? =A0I print out the path and put it in Windows Explor=
er
> > > and it goes right there, so I do not know why it cannot be accessed.
>
> > > The code is below:
> > > <code>
> > > $relative_addy =3D "\\\\gailbapps\\cybraryn\\TDmenu\\A-Cyb_Stats\\";
>
> > Are you using 'strict'? If not, why not? If you are, where is this
> > variable declared?
>
> > Use forward slashes. With a few exceptions (notably paths passed to
> > cmd.exe and paths passed to Win32::Process) they work perfectly well on
> > Win32 perl.
>
> > =A0 =A0 my $relative_addy =3D "//gailbapps/cybraryn/TDmenu/A-Cyb_Stats/=
";
>
> > > $month_year =3D $date_month . "_" . $date_year . ".txt";
>
> > > $tot_file =3D $relative_addy . $month_year;
>
> > =A0 =A0 my $tot_file =3D "$relative_addy$date_month\_$date_year.txt";
>
> > > open (TOT_TXT, '>$tot_file') || die "$tot_file open failed: $!";
>
> > Presumably this line succeeds? It does not, however, do what you think
> > it does: single quotes don't interpolate, so you are trying to open a
> > file called (literally) '$tot_file' in the current directory. I didn't
> > think Win32 allowed filenames to have '$' in, but I may be
> > misremembering.
>
> > You should be using lexical filehandles and 3-arg open:
>
> > =A0 =A0 open(my $TOT_TXT, ">", $tot_file)
> > =A0 =A0 =A0 =A0 || die "$tot_file open failed: $!";
>
> > > print "File: $tot_file<p>";
>
> > > print TOT_TXT "Hello\n";
>
> > > close(TOT_TXT);
>
> > You also need to check the return value of close, to make sure the data
> > was actually written successfully. (Checking print is neither necessary
> > nor sufficient.)
>
> > =A0 =A0 close($TOT_TXT) || die "writing $tot_file failed: $!";
>
> > Ben
>
>
> But I do get the following error: \\gailbapps\cybraryn\TDmenu\A-
> Cyb_Stats\05_2009.txt open failed: Invalid argument at C:\Inetpub
> \wwwroot\cgi-bin\CybraryN\test.pl line 50.
>
'>\\\\gailbapps\\cybraryn\\TDmenu\\A-Cyb_Stats\\$month_year'
I don't know about PERL, but in Perl variables are not
expanded inside single quotes, so your error does not match
the code which you included.
------------------------------
Date: Thu, 1 Jul 2010 03:26:59 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Path to another server
Message-Id: <j0btf7-31v.ln1@osiris.mauzo.dyndns.org>
Quoth Joe <jruffino@gailborden.info>:
>
> I would love to use strict, but I have &FormInput; and when I put my
> in front of it, I get an error.
Err... you mean like
my &FormInput;
? That is not what 'my' is used for, so it's not surprising you got an
error.
> But I do get the following error: \\gailbapps\cybraryn\TDmenu\A-
> Cyb_Stats\05_2009.txt open failed: Invalid argument at C:\Inetpub
> \wwwroot\cgi-bin\CybraryN\test.pl line 50.
Is this with the old version, open(..., '>$tot_file'), or the new,
open(..., '>\\\\gailbapps\\...') ? If, as I suspect, it is with the old,
then this is telling you that you can't open a file with a '$' in the
name. If it is with the new then I'm not sure what is going on, but you
have some sort of permissions or network problem.
> Which led me here to ask for help. Below is the complete code:
>
> #!/usr/bin/perl -w
>
> use CGI qw(:standard :html3);
> use CGI::Carp qw(fatalsToBrowser);
> #use strict;
>
> #Library file that will read the form data and store in
> formdata{'value'} form
> require '../lib/forminput.lib';
>
> &FormInput;
Good Lord. Where on Earth did you get this from? Replace these two lines
with
my %formdata = CGI::Vars();
and throw away forminput.lib.
> #$comps = "ercomps_test.txt"; # Holder for computer txt file.
> my $comps = "ercomps.txt"; # Holder for computer txt file.
> my $date_month = "08"; # Holder for Testing Month.
> my $date_year = "2009"; # Holder for Testing Year.
> my $tot_file = $date_month . "_" . $date_year . ".txt";
What is the purpose of this line? You reset these three variables below
before you use these values.
> my $month_year;
> my $relative_addy = "\\\\gailbapps\\cybraryn\\TDmenu\A-Cyb_Stats\\";
> my $cnt = 0;
> my $dir_cnt = 0;
> my $dir;
> my $dirtoget;
> my $formdata;
> my @comps;
There is no need to declare all your variables up-top like this. Declare
them as you need them.
> print "Content-type: text/html\n\n";
> print "<html><body>";
> print "<head><title>CybraryN ER Computer Statistics</title></head>";
Heredocs were invented for exactly this sort of situation (this code
should not be indented):
print <<CGI;
Content-type: text/html
<html><body>
<head><title>...</title></head>
CGI
(Better still would be a template system, but one step at a time.)
Current best practice is that text/html should always include a
'charset' parameter, usually 'text/html; charset=iso8859-1', to avoid
ambiguity and browser bugs.
> $date_month = $formdata{'month'};
> $date_year = $formdata{'year'};
> $month_year = $date_month . "_" . $date_year . ".txt";
> $tot_file = $relative_addy . $month_year;
> print "<h2>CybraryN ER Computer Stats</h2>";
> print "<h3>For Month-Year of: $date_month-$date_year</h3>";
> print "<h3>Get Data for Excel File from <a href='file://V:/TDmenu/A-
> Cyb_Stats/'>V:\\TDmenu\\A-Cyb_Stats\\$month_year</a></h3>";
Presumably you are aware that the URL and the text of the link do not
match? Also, strictly speaking, a file: URL should begin with three
slashes, but there is no spec and current practice is vague and
contradictory, so it may not matter.
> ##########################################################################
> # Read in text file for the computers to be used, and set to an array.
> #
> open (COMPSLIST, $comps) || die "$comps open failed: $!";
> while (<COMPSLIST>) {
> chomp;
> $comps[$cnt] = $_;
> ++$cnt;
perldoc -f push
Better would be
chomp( my @comps = <COMPSLIST> );
but that may be considered too confusing.
> }
> close (COMPSLIST);
>
> # open (TOT_TXT, '>$tot_file') || die "$tot_file open failed: $!";
> open (TOT_TXT, '>\\\\gailbapps\\cybraryn\\TDmenu\\A-Cyb_Stats\\
> $month_year') || die "$tot_file open failed: $!";
You are *still* trying to interpolate variables into single-quoted
strings. You have also ignored my advice about 3-arg open and lexical
filehandles.
> close($TOT_TXT) || die "writing $tot_file failed: $!";
The filehandle you opened was called TOT_TXT. Why are you trying to
close one called $TOT_TXT?
Ben
------------------------------
Date: Wed, 30 Jun 2010 19:32:00 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: reading from a file into an array in perl
Message-Id: <0fvn26dl5favmja9vosakl42fqrou0e6ir@4ax.com>
Peter Valdemar Mørch <4ux6as402@sneakemail.com> wrote:
>On Jun 30, 5:00 pm, J rgen Exner <jurge...@hotmail.com> wrote:
>> Where is this array coming from? You never declared it (are you using
>> warnings and strictures? You absolutely should!!!) and never defined it,
>> therefore it is empty and this loop will never be executed.
>
>Uhm, didn't he in fact declare it explicitly?:
You are right, sorry.
Still, he doesn't put any values in it.
jue
------------------------------
Date: Thu, 01 Jul 2010 02:26:17 +0000
From: John Kelly <jak@isp2dial.com>
Subject: The daemon helper, dh is its name
Message-Id: <aqun261fiucu564rk6rvhdgsdt8og45rku@4ax.com>
The daemon helper, dh is its name.
It's a small C program that starts any program or shell command as a
daemon, then gets out of the way.
Yes I know there are various others. But this is one I wrote, and I
gave it an Apache license.
If you don't like the name "dh" for whatever reason, you can patch the
Makefile and source to give it whatever name you like. Perhaps "dprime"
(daemon primer), or "dp" for a short name.
ftp://ftp.beewyz.com/users/jar/etcetera/computer/programming/project/dh/
Yes I know you can fork,setsid,exec in Perl too. But the daemon helper
covers some bases you might not think of, when throwing your Perl script
together. And a tool that already does the job for you, saves time.
--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php
------------------------------
Date: Thu, 1 Jul 2010 04:32:00 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: The daemon helper, dh is its name
Message-Id: <gqetf7-7fv.ln1@osiris.mauzo.dyndns.org>
Quoth John Kelly <jak@isp2dial.com>:
>
> The daemon helper, dh is its name.
>
> It's a small C program that starts any program or shell command as a
> daemon, then gets out of the way.
Why are you posting this here?
Ben
------------------------------
Date: Wed, 30 Jun 2010 23:06:33 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: The daemon helper, dh is its name
Message-Id: <slrni2o4q8.9jd.tadmc@tadbox.sbcglobal.net>
Ben Morrow <ben@morrow.me.uk> wrote:
>
> Quoth John Kelly <jak@isp2dial.com>:
>>
>> The daemon helper, dh is its name.
>>
>> It's a small C program that starts any program or shell command as a
>> daemon, then gets out of the way.
>
> Why are you posting this here?
Maybe because it is "news", as in Network News Transfer Protocol?
:-)
--
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, 01 Jul 2010 00:07:44 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: The daemon helper, dh is its name
Message-Id: <87zkybc0a7.fsf@quad.sysarch.com>
>>>>> "BM" == Ben Morrow <ben@morrow.me.uk> writes:
BM> Quoth John Kelly <jak@isp2dial.com>:
>>
>> The daemon helper, dh is its name.
>>
>> It's a small C program that starts any program or shell command as a
>> daemon, then gets out of the way.
BM> Why are you posting this here?
because he doesn't like how i paTROL the group? :)
but a good question that he is not likely to answer. asking him
questions about his reasoning is taken as a personal insult.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
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 3013
***************************************