[31851] in Perl-Users-Digest
Perl-Users Digest, Issue: 3114 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 3 18:09:26 2010
Date: Fri, 3 Sep 2010 15:09:06 -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 Fri, 3 Sep 2010 Volume: 11 Number: 3114
Today's topics:
Re: Multidimensional array <rvtol+usenet@xs4all.nl>
Re: Multidimensional array <ben@morrow.me.uk>
Re: Multidimensional array <ben@morrow.me.uk>
Re: Multidimensional array <rvtol+usenet@xs4all.nl>
Re: Multidimensional array <bugbear@trim_papermule.co.uk_trim>
Re: Multidimensional array <cartercc@gmail.com>
Re: Multidimensional array <stevem_@nogood.com>
Re: Multidimensional array <jimsgibson@gmail.com>
Re: Multidimensional array <bugbear@trim_papermule.co.uk_trim>
Re: Multidimensional array <tadmc@seesig.invalid>
Re: Multidimensional array <uri@StemSystems.com>
Question about using WWW::Google::Contacts <jegan473@comcast.net>
Re: Regex help <tadmc@seesig.invalid>
Re: Regex help <tadmc@seesig.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 03 Sep 2010 12:16:24 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Multidimensional array
Message-Id: <4c80caf8$0$22936$e4fe514c@news.xs4all.nl>
On 2010-09-03 11:20, Paul E. Schoen wrote:
> my $E_Date = $in{'Event_Date'}; #Date in yyyymmdd format
> my $E_Time = $in{'Event_Time'}; #Time in hh:mm format
> my $E_Title = $in{'Event_Title'};
> my $E_Descr = $in{'Event_Description'}; #Description may have newlines
Why copy these to new variables?
> for my $row ( @$all ) {
> ( $E_DT, $E_Title, $E_Descr ) = @$row;
> my @dt = split "T", $E_DT;
> my $d = $dt[ 0 ];
> my $t = $dt[ 1 ];
No need to set up @dt first, you could just do
my ( $d, $t ) = split "T", $E_DT;
Or forget about $d ad $t, and just use the @dt.
> print "$E_Title\n$d $t\n$E_Descr\n";
printf "%s\n%s %s\n%s\n", $E_Title, @dt, $E_Descr;
--
Ruud
------------------------------
Date: Fri, 3 Sep 2010 11:29:17 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Multidimensional array
Message-Id: <t8v6l7-gla2.ln1@osiris.mauzo.dyndns.org>
Quoth "Paul E. Schoen" <paul@pstech-inc.com>:
>
> The server that will most likely host this is Apache. But as mentioned
> elsewhere setting it up is non-trivial and one more thing I don't want to
> mess with at this point. I can run the script locally but I had to use goto
> statements to spaghetti code around the CGI stuff and simulate the data from
> the HTML page.
No, you didn't have to use goto. You *never* have to use goto in
Perl[0]. Whatever you were doing, you could have done it better some
other way.
[0] goto &sub doesn't count, though it's still hideously ugly.
> Maybe there is a way to detect that there is no CGI data and provide the
> simulated stuff without having to change the source code for local or remote
> (live server?) use.
CGI.pm will do this for you.
> I have finally achieved most of my goal for this script, and I am now using
> a DBI database connection. It seems much easier to me than using hashes and
> worrying about data separators and \n newlines in some fields. Here is
> roughly what I've done:
>
> use warnings;
> use strict;
> use DBI;
> use Fcntl;
> use DateTime;
> ... Get CGI data and mail a copy to me
> my $E_Date = $in{'Event_Date'}; #Date in yyyymmdd format
> my $E_Time = $in{'Event_Time'}; #Time in hh:mm format
> my $E_Title = $in{'Event_Title'};
> my $E_Descr = $in{'Event_Description'}; #Description may have newlines
> #This will replace the $E_Date and $E_Time; using "now" to simulate
> my $E_DT = DateTime->now;
>
> my $dbfile = "events.db";
> my $db = DBI->connect( # connect to your database, create if
> needed
> "dbi:SQLite:dbname=$dbfile", # DSN: dbi, driver, database file
> "", # no user
> "", # no password
> { RaiseError => 1, AutoCommit => 1 } # complain if something goes wrong
> ) or die $DBI::errstr;
>
> unless (-e $dbfile) { #check for exist
DON'T DO THAT. You have a race condition between the check and the
create. Just create the table beforehand (either with perl or with the
sqlite command-line tool).
> $db->do("CREATE TABLE tEvents (dt DATETIME PRIMARY KEY, tl TEXT, de
> TEXT)");
> }
> $db->do("PRAGMA foreign_keys = OFF");
> $db->do("INSERT INTO tEvents (dt,tl,de) VALUES ('$E_DT', '$E_Title',
> '$E_Descr')");
>
> my $all = $db->selectall_arrayref("SELECT * FROM tEvents");
>
> # Print the data for debugging purposes
> foreach my $row (@$all) {
> ($E_DT, $E_Title, $E_Descr) = @$row;
> my @dt = split('T',$E_DT); #I tried using $E_DT->mdy with no joy
> my $d = $dt[0]; #Extract the date portion yyyy-mm-dd
> my $t = $dt[1]; #Extract the time portion hh:mm:ss
> print "$E_Title\n$d $t\n$E_Descr\n";
> }
>
> # Print the data in HTML to the user
> [snip]
>
> # Print to the HTML file (write, append, create)
> # Yes I know I need to change the HTML format
> open (DATA1, '>', "output.htm")
If you're not going to listen I don't know why I bother replying. Don't
use global bareword filehandles.
> Up until now all events were submitted to the webmasters of the various
> chapters and local groups and they had to update the content. I think our
> Greater Baltimore Group's site has been maintained manually and the events
> were often delayed by weeks or months. The other sites that we might want to
> emulate appear to use a CMS of some kind, and for a while I used Atomz for
> the Maryland site, but I found it difficult to use, and now I think Atomz is
> no longer available.
At this point I would be inclined to seriously recommend you find a
decent, well-supported CMS (like Movable Type or Wordpress) and stick to
that. I don't get the impression you're taking this programming job
terribly seriously, and you *will* get into serious trouble if you put
something up and it turns out to have a security hole.
Ben
------------------------------
Date: Fri, 3 Sep 2010 11:31:38 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Multidimensional array
Message-Id: <adv6l7-gla2.ln1@osiris.mauzo.dyndns.org>
Quoth "Dr.Ruud" <rvtol+usenet@xs4all.nl>:
> On 2010-09-03 11:20, Paul E. Schoen wrote:
>
> > print "$E_Title\n$d $t\n$E_Descr\n";
>
> printf "%s\n%s %s\n%s\n", $E_Title, @dt, $E_Descr;
Uh, in what way is that better? :)
local ($", $,, $\) = (" ", "\n", "\n");
print $E_Title, "@dt", $E_Descr;
Or, you know, use a heredoc.
Ben
------------------------------
Date: Fri, 03 Sep 2010 12:46:59 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Multidimensional array
Message-Id: <4c80d223$0$22933$e4fe514c@news.xs4all.nl>
On 2010-09-03 12:31, Ben Morrow wrote:
>
> Quoth "Dr.Ruud"<rvtol+usenet@xs4all.nl>:
>> On 2010-09-03 11:20, Paul E. Schoen wrote:
>>
>>> print "$E_Title\n$d $t\n$E_Descr\n";
>>
>> printf "%s\n%s %s\n%s\n", $E_Title, @dt, $E_Descr;
>
> Uh, in what way is that better? :)
It was in the context of getting rid of the separate $d and $t.
(So I was tempted to write the @dt as @dt[0,1]. :)
> local ($", $,, $\) = (" ", "\n", "\n");
> print $E_Title, "@dt", $E_Descr;
>
> Or, you know, use a heredoc.
Yes, many alternatives available.
--
Ruud
------------------------------
Date: Fri, 03 Sep 2010 12:17:27 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Multidimensional array
Message-Id: <aJWdnZ_sb_PaRB3RnZ2dnUVZ7rSdnZ2d@brightview.co.uk>
ccc31807 wrote:
> On Sep 2, 11:02 am, Sherm Pendley <sherm.pend...@gmail.com> wrote:
>> Once again, you're assigning new meaning to terms that disagree with
>> the meaning used by the rest of us, and then trying to argue that it's
>> everyone else's meaning that is wrong. Please stop doing that.
>
> Not so, I merely take words in their literal meaning unless they are
> obviously meant to be taken non literally.
Have you considered the possibility of "jargon meanings", words
which have a general meaning in normal conversation, but
have more specific meaning in a specific technical context?
BugBear
------------------------------
Date: Fri, 3 Sep 2010 08:11:22 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Multidimensional array
Message-Id: <bb335eac-f7f5-41fd-9290-ecd5bfc82bfd@m17g2000prl.googlegroups.com>
On Sep 2, 9:11=A0pm, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> In the context of this thread obviously we are discussing CGI
> development.
>
> So you were not working on the live server application, were you?
>
> I did. I explicitely said live server.
>
> No he isn't. He is interpreting my words exactly as I intended them and
> exactly as is customary in the relevant industry.
> If you are not familiar with those terms then that is your problem, not
> mine or Sherm's.
I have several stand alone machines where I have Apache and a DB
server running. I have a small (4 machines) home network on which I
have Apache and a DB server running. At work, I have both an internal
network with Apache and a DB server, and an extranet with the same
thing. I also have a personal server that runs around 60 production
sites.
I develop CGI scripts on all of these machines. Typically, I will
develop on a standalone machine, and then upload the directory tree to
a server and configure httpd.conf to serve it, using the local code as
the 'source' and the remote code as a 'backup.' However, from time to
time I find myself developing directly on production servers for one
reason or another.
I don't do contract work for web sites (and do very little in any
case) but I do a fair amount of database interfaces via CGI at work,
and maintain a web/database server for a group. I got my start as a
web/database/system administrator (on BSD) in 1999.
Your statement that "it is quite stupid to do any development work on
a live web server" struck me as reasonable in general but as an
overstatement. If you do 'development work' you HAVE to use a 'live
web server.' That doesn't mean that you screw around with production
code, although sometimes you will, either by necessity or by
convenience or sometimes by sheer stupidity.
Words have meanings, and we need to pay attention to the clear and
plain meanings of words. If we want to communicate with others, we
can't insist on idiosyncratic usage, but need to use words in their
generally understood meaning. If I'm guilty of anything, it's a
reluctance to use jargon and a preference for common usage as opposed
to technical usage.
CC.
------------------------------
Date: Fri, 03 Sep 2010 08:30:03 -0500
From: Steve <stevem_@nogood.com>
Subject: Re: Multidimensional array
Message-Id: <px8go.856$f24.6@newsfe05.iad>
On 09/03/2010 04:20 AM, Paul E. Schoen wrote:
>
> $db->do("INSERT INTO tEvents (dt,tl,de) VALUES ('$E_DT', '$E_Title',
> '$E_Descr')");
>
You may be setting yourself up for an SQL Injection Attack since it
appears you are working with unchecked user input.
This is a *very* serious security hole.
If you do not know what an SQL Injection Attack is, you need to google
the term and do some reading.
It is relatively easy to solve the problem, especially with DBI, but you
*must* discover and implement the solution yourself so you will
(hopefully) understand what it is you are doing why you are doing it.
hth,
\s
------------------------------
Date: Fri, 03 Sep 2010 09:01:09 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Multidimensional array
Message-Id: <030920100901092434%jimsgibson@gmail.com>
In article <jbg18695fd08g0nfb7h1l5j3tm8eq9g9fr@4ax.com>, Jürgen Exner
<jurgenex@hotmail.com> wrote:
> "Paul E. Schoen" <paul@pstech-inc.com> wrote:
>
> >The server that will most likely host this is Apache. But as mentioned
> >elsewhere setting it up is non-trivial and one more thing I don't want to
> >mess with at this point. I can run the script locally but I had to use goto
> >statements to spaghetti code around the CGI stuff and simulate the data from
> >the HTML page.
>
> ???
> You did read the section "DEBUGGING" in "perldoc CGI", didn't you?
As far as I can tell, Paul is not using the CGI module.
--
Jim Gibson
------------------------------
Date: Fri, 03 Sep 2010 17:05:42 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Multidimensional array
Message-Id: <icednT03eLJLgRzRnZ2dnUVZ8nydnZ2d@brightview.co.uk>
ccc31807 wrote:
> If I'm guilty of anything, it's a
> reluctance to use jargon and a preference for common usage as opposed
> to technical usage.
In a technical group, the "common usage" *is* the "technical usage".
BugBear
------------------------------
Date: Fri, 03 Sep 2010 12:03:43 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Multidimensional array
Message-Id: <slrni82a6f.6j3.tadmc@tadbox.sbcglobal.net>
Jim Gibson <jimsgibson@gmail.com> wrote:
> In article <jbg18695fd08g0nfb7h1l5j3tm8eq9g9fr@4ax.com>, Jürgen Exner
><jurgenex@hotmail.com> wrote:
>
>> "Paul E. Schoen" <paul@pstech-inc.com> wrote:
>>
>> >The server that will most likely host this is Apache. But as mentioned
>> >elsewhere setting it up is non-trivial and one more thing I don't want to
>> >mess with at this point. I can run the script locally but I had to use goto
>> >statements to spaghetti code around the CGI stuff and simulate the data from
>> >the HTML page.
>>
>> ???
>> You did read the section "DEBUGGING" in "perldoc CGI", didn't you?
>
> As far as I can tell, Paul is not using the CGI module.
Despite being shown how it can be a drop-in replacement for
what he is using with only 2 lines of code.
If Paul feels free to ignore the advice given here, then it will likely
become the case that folks will feel free to ignore his posts
altogether...
You reap what you sow.
--
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: Fri, 03 Sep 2010 17:54:12 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Multidimensional array
Message-Id: <87lj7ize63.fsf@quad.sysarch.com>
>>>>> "c" == ccc31807 <cartercc@gmail.com> writes:
c> Your statement that "it is quite stupid to do any development work on
c> a live web server" struck me as reasonable in general but as an
c> overstatement. If you do 'development work' you HAVE to use a 'live
c> web server.' That doesn't mean that you screw around with production
c> code, although sometimes you will, either by necessity or by
c> convenience or sometimes by sheer stupidity.
c> Words have meanings, and we need to pay attention to the clear and
c> plain meanings of words. If we want to communicate with others, we
c> can't insist on idiosyncratic usage, but need to use words in their
c> generally understood meaning. If I'm guilty of anything, it's a
c> reluctance to use jargon and a preference for common usage as opposed
c> to technical usage.
as other said, technical jargon is real and should be used to
communicate with technical people. try talking natural english to a
lawyer and watch you lose all your lawsuits. live means production, not
just running. ALL servers are live by your silly definition. live means
exposed to the real ugly dirty nasty cracking masses out there. this
could be internal to your shop or on the net, it is still live. live
means it does actual production work and it can't be broken or played
with.
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: Fri, 03 Sep 2010 13:49:03 GMT
From: James Egan <jegan473@comcast.net>
Subject: Question about using WWW::Google::Contacts
Message-Id: <j17go.103107$Is6.87632@en-nntp-13.dc1.easynews.com>
I'm using the google contacts API here:
http://search.cpan.org/~merixzon/WWW-Google-Contacts-0.11/
The script below will retrieve your google contacts "full name", albeit with
some errors. Can I'm now trying to retrieve other parameters such as the
contact phone number. Can someone explain to me how to get the phone number
along with the name?
-Thanks
#!/usr/bin/perl -w
use strict;
use warnings;
use WWW::Google::Contacts;
use WWW::Google::Contacts::Type::PhoneNumber;
my $google = WWW::Google::Contacts->new( username => "myacct\@gmail.com", password => "mypass" );
my $contacts = $google->contacts;
while ( my $cont = $contacts->next ) {
print "Name: " . $cont->full_name . "\n";
## print "Phone: " . $cont->phone_number . "\n";
}
------------------------------
Date: Fri, 03 Sep 2010 09:33:15 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Regex help
Message-Id: <slrni821cd.6bh.tadmc@tadbox.sbcglobal.net>
king <hara.acharya@gmail.com> wrote:
> open C1, "<C1.txt";
You should not use bareword filehandles.
You should use a lexical filehandle.
You should use the 3-argument form of open().
You should always, yes *always*, check the return value from open():
open my $c1, '<', 'C1.txt' or die "could not open 'C1.txt' $!";
Then use <$c1> instead of <C1>
--
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: Fri, 03 Sep 2010 09:37:56 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Regex help
Message-Id: <slrni821l5.6bh.tadmc@tadbox.sbcglobal.net>
king <hara.acharya@gmail.com> wrote:
> I have a script as below.
>
> "
> #!/c/perl/bin
> system("typeperf \"\\Processor\(\*\)\\% C1 Time\" -sc 1 > C1.txt");
> system("typeperf \"\\Processor\(\*\)\\% C2 Time\" -sc 1 > C2.txt");
> system("typeperf \"\\Processor\(\*\)\\% C3 Time\" -sc 1 > C3.txt");
> sleep 1;
> #open(C1,"C1.txt");
> #$C1_ARR=<C1>;
> #close(C1);
> open C1, "<C1.txt";
> $C1_CONTENT = do { local $/; <C1> };
> print "$C1_CONTENT\n";"
>
> Now in the $C1_CONTENT the content is as below.
So, we did not need to see any of that code.
Why did you include it then?
Have you seen the Posting Guidelines that are posted here frequently?
> ""(PDH-CSV 4.0)","\\Test_PC\Processor(0)\% C1 Time","\\HACHARYX-MOBL
> \Processor(1)\% C1 Time","\\HACHARYX-MOBL\Processor(_Total)\% C1 Time"
> "09/03/2010 09:58:36.052","9.797092","11.412473","10.604782"
> Exiting, please wait...
> The command completed successfully."
You establish the contents of a variable in Perl with an
assignment statement.
$C1_CONTENT = '"(PDH-CSV 4.0)","\\Test_PC\Processor(0)\% C1 Time"...';
Have you seen the Posting Guidelines that are posted here frequently?
> I am trying to find a regex so that I can extract the exact three
> values
> In this case the values are:
> "9.797092","11.412473","10.604782"
---------------------------
#!/usr/bin/perl
use warnings;
use strict;
$_ = '"(PDH-CSV 4.0)","\\Test_PC\Processor(0)\% C1
Time","\\HACHARYX-MOBL
\Processor(1)\% C1 Time","\\HACHARYX-MOBL\Processor(_Total)\% C1 Time"
"09/03/2010 09:58:36.052","9.797092","11.412473","10.604782"
Exiting, please wait...
The command completed successfully.';
my @values = /"([\d.]+)"/g;
print "$_\n" for @values;
---------------------------
But you really should be using a module that understands CSV
format if you are processing data that is in a CSV format!
--
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: 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 3114
***************************************