[31847] in Perl-Users-Digest
Perl-Users Digest, Issue: 3110 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 1 21:14:22 2010
Date: Wed, 1 Sep 2010 18:14: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 Wed, 1 Sep 2010 Volume: 11 Number: 3110
Today's topics:
Re: Multidimensional array <ben@morrow.me.uk>
Re: Multidimensional array <NoSpamPleaseButThisIsValid3@gmx.net>
Re: Multidimensional array <cartercc@gmail.com>
Re: Multidimensional array <paul@pstech-inc.com>
Re: Multidimensional array <uri@StemSystems.com>
Re: Multidimensional array <paul@pstech-inc.com>
Re: Multidimensional array (Randal L. Schwartz)
Re: Multidimensional array <uri@StemSystems.com>
Re: Multidimensional array <sherm.pendley@gmail.com>
Re: Multidimensional array <ben@morrow.me.uk>
Re: Multidimensional array <tadmc@seesig.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 1 Sep 2010 11:07:31 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Multidimensional array
Message-Id: <38l1l7-tpa1.ln1@osiris.mauzo.dyndns.org>
Quoth "Paul E. Schoen" <paul@pstech-inc.com>:
> I am trying to construct an array (or possibly a hash) which consists of
> arrays. It is organized as a series of records with four text fields:
>
> Date, Time, Title, Description
>
> I was able to get this to work with the following ugly but functional code:
>
> my @E_Dates = ("20100831", "20100910");
> my $E_Time = "14:00"; #Time in hh:mm format
> my $E_Title = "Example";
> my $E_Descr = "Line 1 \nLine2";
>
> my $Event_DB = [[$E_Dates[0], $E_Time, $E_Title, $E_Descr]];
>
> $E_Time = "18:00"; #Time in hh:mm format
> $E_Title = "Example Title 2";
> $E_Descr = "Example 2 Line 1 \nExample 2 Line2";
>
> @E_Details = ($E_Time, $E_Title, $E_Descr); # Array of three elements
>
> $Event_DB->[1] =[ $E_Dates[1], $E_Time, $E_Title, $E_Descr];
>
> print "$Event_DB->[0][0]"; #prints first Date
> print "$Event_DB->[0][1]"; #prints first Time
> print "$Event_DB->[0][2]"; #prints first Title
> print "$Event_DB->[0][3]"; #prints first Descr
>
> print "$Event_DB->[1][0]"; #prints second Date
> print "$Event_DB->[1][1]"; #prints second Time
> print "$Event_DB->[1][2]"; #prints second Title
> print "$Event_DB->[1][3]"; #prints second Descr
>
> But when I tried to use an array, I could not use the two dimensional
> indexes:
>
> my @E_Dates = ("20100831", "20100910"); #Date in yyyymmdd format
> my $E_Time = "14:00"; #Time in hh:mm format
> my $E_Title = "Title1";
> my $E_Descr = "Descr1-Line1 \nDescr1-Line2";
>
> my @Event_DB = ($E_Dates[0], $E_Time, $E_Title, $E_Descr);
>
> $E_Time = "18:00"; #Time in hh:mm format
> $E_Title = "Title2";
> $E_Descr = "Descr2-Line1 \nDescr2-Line2";
>
> push( @{Event_DB}, $E_Dates[1], $E_Time, $E_Title, $E_Descr );
>
> for (my $i=0; $i<@Event_DB; $i+=4) {
> print "<p>";
> print "<h3>Title $i: $Event_DB[$i+2]</h3>\n";
> print "<br><h4>Date: $Event_DB[$i]</h4>\n";
> print "<br><h4>Time: $Event_DB[$i+1]</h4>\n";
> print "<br><h5>Description: $Event_DB[$i+3]</h5></p><hr>\n";
> }
You are confused about the difference between lists and arrayrefs. You
could rewrite this example so it worked correctly by changing these
lines:
# This creates an array containing a *single* element, which happens
# to be an arrayref.
my @Event_DB = [$E_Dates[0], $E_Time, $E_Title, $E_Descr];
#...
# This pushes another *single* element, which again happens to be an
# arrayref.
push @Event_DB, [$E_Dates[1], $E_Time, $E_Title, $E_Descr];
# Now you have a proper 2D array:
for my $i (0..$#Event_DB) {
print <<HTML;
<p>
<h3>Title $i: $Event_DB[$i][2]</h3>
<br><h4>Date: $Event_DB[$i][0]</h4>
...
HTML
}
> I tried everything I could find and I had no success. I originally tried to
> create a hash with the date as the index and an array for the data, about
> like this:
>
> my @E_Dates = ("20100831", "20100910");
> my $E_Time = "14:00"; #Time in hh:mm format
> my $E_Title = "Example";
> my $E_Descr = "Line 1 \nLine2";
> # Hash with Date as sorting key, Array of Details
> my %Event_DB = (Date=>$E_Dates[0], Details=>[$E_Time, $E_Title,
> $E_Descr]);
No, no, that's quite wrong. I *think* what you mean here is
my %Event_DB = (
$E_Dates[0] => [$E_Time, $E_Title, $E_Descr],
);
This assumes you will never have two Events with the same Date. If you
will you will need an extra level of arrayref.
You might rather store your records as hashrefs (so you can name the
fields instead of numbering them), in which case you want
my %Event_DB = (
$E_Dates[0] => {
Date => $E_Dates[0],
Time => $E_Time,
Title => $E_Title,
Descr => $E_Descr,
},
);
(Notice that I put the date in the record even though it was already
stored as the key. This is usually a good idea, as it makes processing
simpler later.)
> $E_Time = "18:00"; #Time in hh:mm format
> $E_Title = "Example Title 2";
> $E_Descr = "Example 2 Line 1 \nExample 2 Line2";
> @E_Details = ($E_Time, $E_Title, $E_Descr); # Array of three elements
> # Adding second record with push
> push @{ $Event_DB{Date=>$E_Dates[1]}}, Details=>[$E_Time, $E_Title,
> $E_Descr];
$Event_DB{$E_Dates[1]} = [$E_Time, $E_Title, $E_Descr];
> # Alternate method (probably very wrong)
> %Event_DB(Date=>$E_Dates[1]) = Details=>[$E_Time, $E_Title, $E_Descr];
That doesn't even compile.
> I would like to be able to sort the array or hash by date and then format it
> to be printed as HTML. I am more familiar with C and Borland Delphi Pascal
> where this would be simple. It's probably also simple in Perl but I can't
> figure out how to do it.
Using the first model (array-of-arrayrefs):
for my $event (sort { $a->[0] cmp $b->[0] } @Event_DB) {
print <<HTML;
<p>Date: $event->[0]
<p>Title: $event->[2]
HTML
}
Using the second (hash-of-arrayrefs):
for my $date (sort keys %Event_DB) {
print <<HTML;
<p>Date: $date
<p>Title: $Event_DB{$date}[2]
HTML
}
Using the third (hash-of-hashrefs):
for my $event (map $Event_DB{$_}, sort keys %Event_DB) {
print <<HTML;
<p>Date: $event->{Date}
<p>Title: $event->{Title}
HTML
}
Have you read perldoc perldsc, perldoc perllol and perldoc perlreftut?
Ben
------------------------------
Date: Wed, 01 Sep 2010 13:29:35 +0200
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>
Subject: Re: Multidimensional array
Message-Id: <4c7e3920$0$6874$9b4e6d93@newsspool2.arcor-online.net>
On 01.09.2010 11:31, Paul E. Schoen wrote:
> I am trying to construct an array (or possibly a hash) which consists of
> arrays. It is organized as a series of records with four text fields:
>
> Date, Time, Title, Description
>
> I was able to get this to work with the following ugly but functional code:
>
> my @E_Dates = ("20100831", "20100910");
> my $E_Time = "14:00"; #Time in hh:mm format
> my $E_Title = "Example";
> my $E_Descr = "Line 1 \nLine2";
>
> my $Event_DB = [[$E_Dates[0], $E_Time, $E_Title, $E_Descr]];
>
> $E_Time = "18:00"; #Time in hh:mm format
> $E_Title = "Example Title 2";
> $E_Descr = "Example 2 Line 1 \nExample 2 Line2";
>
> @E_Details = ($E_Time, $E_Title, $E_Descr); # Array of three elements
>
> $Event_DB->[1] =[ $E_Dates[1], $E_Time, $E_Title, $E_Descr];
>
> print "$Event_DB->[0][0]"; #prints first Date
> print "$Event_DB->[0][1]"; #prints first Time
> print "$Event_DB->[0][2]"; #prints first Title
> print "$Event_DB->[0][3]"; #prints first Descr
It's a bad idea to store different things (Date, Time, Title, Descr) in
the same array. What happens if you try to read the code next week? Do
you still know that index 3 is the description? So it is probably better
to use a hash here and use "Date", ... as key. Depending on what you
plan to store here, it might be even better to use OO and create a class
which encapsulates this dataset (see perldoc perltoot). With the OO
approach, also your array of arrays goes away, you will only have a
simple array of event objects.
Furthermore I would suggest to store date and time together in a
timestamp. Convert it to your favorite format (hh:mm or whatever) just
before you display it - that makes a lot of things easier (for example,
how would you add 90 minutes to "23:00"? What about time zones?).
Wolf
------------------------------
Date: Wed, 1 Sep 2010 07:43:46 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Multidimensional array
Message-Id: <49aa9690-57fc-4468-b400-bc4c8b084f81@m1g2000yqo.googlegroups.com>
On Sep 1, 5:31=A0am, "Paul E. Schoen" <p...@pstech-inc.com> wrote:
> I am trying to construct an array (or possibly a hash) which consists of
> arrays. It is organized as a series of records with four text fields:
>
> Date, Time, Title, Description
Paul, see the script below and output.
With this kind of task, you first need to consider the format of your
input and output. You want output to be HTML, and I have done so. I
have assumed that your data will be in CSV format, but of course that
depends on your app and in any case is easy enough to change.
It's much, much easier when working with data of this kind to name the
fields rather than use positional notation, which means that you will
use hashes of hashes (or hashes of hash refs to be more accurate).
Accordingly, I have named your fields date, time, title, and desc, and
have used 'date' as the key. Here is a script and output.
------------------script---------------
#! perl
# event_calendar.plx
use strict;
use warnings;
my %events;
while (<DATA>)
{
next unless /\w/;
chomp;
my ($date, $time, $title, $desc) =3D split /,/;
$desc =3D~ s!\\n!<br />!g;
$events{$date}{time} =3D $time;
$events{$date}{title} =3D $title;
$events{$date}{desc} =3D $desc;
}
foreach my $date (sort keys %events)
{
print qq(
<h1>Date: $date</h1>
<ul>
<li>Time: $events{$date}{time}</li>
<li>Title: $events{$date}{title}</li>
<li>$events{$date}{desc}</li>
</ul>);
}
exit(0);
__DATA__
20100831,14:00,Example,Line 1\nLine 2
20100910,18:00,Example Title 2,"Example 2 Line 1\nExample 2 Line 2
17760704,12:00,Revolution!,Break away from Britian\nForm new republic
-------------output-------------------
<h1>Date: 17760704</h1>
<ul>
<li>Time: 12:00</li>
<li>Title: Revolution!</li>
<li>Break away from Britian<br />Form new republic</li>
</ul>
<h1>Date: 20100831</h1>
<ul>
<li>Time: 14:00</li>
<li>Title: Example</li>
<li>Line 1<br />Line 2</li>
</ul>
<h1>Date: 20100910</h1>
<ul>
<li>Time: 18:00</li>
<li>Title: Example Title 2</li>
<li>"Example 2 Line 1<br />Example 2 Line 2</li>
</ul>
------------------------------
Date: Wed, 1 Sep 2010 14:59:15 -0400
From: "Paul E. Schoen" <paul@pstech-inc.com>
Subject: Re: Multidimensional array
Message-Id: <boxfo.164083$1F6.84781@newsfe01.iad>
"Ben Morrow" <ben@morrow.me.uk> wrote in message
news:38l1l7-tpa1.ln1@osiris.mauzo.dyndns.org...
>
> You are confused about the difference between lists and arrayrefs. You
> could rewrite this example so it worked correctly by changing these
> lines:
>
> # This creates an array containing a *single* element, which happens
> # to be an arrayref.
> my @Event_DB = [$E_Dates[0], $E_Time, $E_Title, $E_Descr];
>
> #...
>
> # This pushes another *single* element, which again happens to be an
> # arrayref.
> push @Event_DB, [$E_Dates[1], $E_Time, $E_Title, $E_Descr];
>
> # Now you have a proper 2D array:
> for my $i (0..$#Event_DB) {
> print <<HTML;
> <p>
> <h3>Title $i: $Event_DB[$i][2]</h3>
> <br><h4>Date: $Event_DB[$i][0]</h4>
> ...
> HTML
> }
>
> You might rather store your records as hashrefs (so you can name the
> fields instead of numbering them), in which case you want
>
> my %Event_DB = (
> $E_Dates[0] => {
> Date => $E_Dates[0],
> Time => $E_Time,
> Title => $E_Title,
> Descr => $E_Descr,
> },
> );
>
> (Notice that I put the date in the record even though it was already
> stored as the key. This is usually a good idea, as it makes processing
> simpler later.)
>
> $Event_DB{$E_Dates[1]} = [$E_Time, $E_Title, $E_Descr];
>
> Using the first model (array-of-arrayrefs):
>
> for my $event (sort { $a->[0] cmp $b->[0] } @Event_DB) {
> print <<HTML;
> <p>Date: $event->[0]
> <p>Title: $event->[2]
> HTML
> }
>
> Using the second (hash-of-arrayrefs):
>
> for my $date (sort keys %Event_DB) {
> print <<HTML;
> <p>Date: $date
> <p>Title: $Event_DB{$date}[2]
> HTML
> }
>
> Using the third (hash-of-hashrefs):
>
> for my $event (map $Event_DB{$_}, sort keys %Event_DB) {
> print <<HTML;
> <p>Date: $event->{Date}
> <p>Title: $event->{Title}
> HTML
> }
>
> Have you read perldoc perldsc, perldoc perllol and perldoc perlreftut?
I have downloaded the entire set of documentation, and I see that there is a
lot to learn. But as it explains in the tutorial, perhaps only 10% needs to
be understood and used. It is confusing (to me) and apparently there are
multiple ways to accomplish the same thing (and this is also true in C and
other languages). I find it hard to allow the interpreter to take care of
things that would need to be more formally expressed in a strongly typed
language.
Thanks for your help. I have made the simple changes you showed and the
script works. Now I need to look at the overall design of the project and
write the proper code to do what I want it to do. For now I think I can get
by with a simple text file for the array of events, adding, sorting,
inserting, deleting, and editing as needed, and then convert to HTML for use
in my home page.
Eventually, something like MySQL might be useful, but that's another
learning curve.
I also appreciate the replies from others who have given me other
perspectives on how to proceed.
Paul
------------------------------
Date: Wed, 01 Sep 2010 15:20:27 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Multidimensional array
Message-Id: <87zkw11dac.fsf@quad.sysarch.com>
>>>>> "PES" == Paul E Schoen <paul@pstech-inc.com> writes:
>> Have you read perldoc perldsc, perldoc perllol and perldoc perlreftut?
PES> I have downloaded the entire set of documentation, and I see that
PES> there is a lot to learn. But as it explains in the tutorial, perhaps
why did you download it? if you have perl installed properly, you
already have the docs! this is a core perl skill to use, know where the
docs are, how to scan them and learn what they cover. there are many
perl tutorials in the docs today as well.
PES> only 10% needs to be understood and used. It is confusing (to me) and
PES> apparently there are multiple ways to accomplish the same thing (and
PES> this is also true in C and other languages). I find it hard to allow
PES> the interpreter to take care of things that would need to be more
PES> formally expressed in a strongly typed language.
why? the whole idea is for perl to do the work for you. it means less
coding and fewer bugs on your part. that is more important than how much
cpu is used.
PES> Thanks for your help. I have made the simple changes you showed and
PES> the script works. Now I need to look at the overall design of the
PES> project and write the proper code to do what I want it to do. For now
PES> I think I can get by with a simple text file for the array of events,
PES> adding, sorting, inserting, deleting, and editing as needed, and then
PES> convert to HTML for use in my home page.
you should really switch to a hash for the lower level. arrays of
different types will break eventually. you can't add/delete something
without changing ALL the uses of those integers later on. with a hash
you can change all you want and the existing code will always work (or
require much less changing than with arrays). hashes are the key perl
construct, arrays are usually secondary.
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: Wed, 1 Sep 2010 18:12:35 -0400
From: "Paul E. Schoen" <paul@pstech-inc.com>
Subject: Re: Multidimensional array
Message-Id: <tdAfo.97386$f_3.17179@newsfe17.iad>
"Uri Guttman" <uri@StemSystems.com> wrote in message
news:87zkw11dac.fsf@quad.sysarch.com...
>>>>>> "PES" == Paul E Schoen <paul@pstech-inc.com> writes:
>
> >> Have you read perldoc perldsc, perldoc perllol and perldoc perlreftut?
>
> PES> I have downloaded the entire set of documentation, and I see that
> PES> there is a lot to learn. But as it explains in the tutorial, perhaps
>
> why did you download it? if you have perl installed properly, you
> already have the docs! this is a core perl skill to use, know where the
> docs are, how to scan them and learn what they cover. there are many
> perl tutorials in the docs today as well.
I am working on a Windows Vista machine and Perl is installed on the server.
I use Telnet to access my web space, assign permissions, run test scripts,
and sometimes I even use the pico editor. But I'm using PerlEdit locally to
edit the scripts and HTML/JavaScript files, and I use NCH Classic FTP for
uploads. It's handy to have the docs available off-line.
For developing Windows GUI apps with Borland Delphi I am spoiled by having a
context sensitive help system available and also a sophisticated debugger.
It would be great to have tools like that for Perl. I suppose I could use
the debugging features but I would probably need to run the script from the
command line.
> PES> only 10% needs to be understood and used. It is confusing (to me)
> and
> PES> apparently there are multiple ways to accomplish the same thing (and
> PES> this is also true in C and other languages). I find it hard to allow
> PES> the interpreter to take care of things that would need to be more
> PES> formally expressed in a strongly typed language.
>
> why? the whole idea is for perl to do the work for you. it means less
> coding and fewer bugs on your part. that is more important than how much
> cpu is used.
Perl does seem to be very powerful, but the syntax is difficult for me to
grasp because it is so cryptic. I am used to language that is verbose and
highly readable, while it seems like a rite of passage to be able to read
the various symbols that constitute much of Perl. Of course, it is a
learning curve, and as I build my script I am learning what they mean. I
don't have the time or enthusiasm to learn Perl in a structured manner as a
course in the language. I intend to learn enough to accomplish my immediate
objectives, and then move on to other things. I am primarily a hardware
engineer specializing in high power test equipment, which often involves PIC
programming which is mostly assembly language and some C. So I am more
comfortable with low level programming at the bit and byte and memory
address level. Delphi provides a means for OOP and strict type declarations
which IMHO makes for a more readable source and less chance for bugs.
> PES> Thanks for your help. I have made the simple changes you showed and
> PES> the script works. Now I need to look at the overall design of the
> PES> project and write the proper code to do what I want it to do. For
> now
> PES> I think I can get by with a simple text file for the array of
> events,
> PES> adding, sorting, inserting, deleting, and editing as needed, and
> then
> PES> convert to HTML for use in my home page.
>
> you should really switch to a hash for the lower level. arrays of
> different types will break eventually. you can't add/delete something
> without changing ALL the uses of those integers later on. with a hash
> you can change all you want and the existing code will always work (or
> require much less changing than with arrays). hashes are the key perl
> construct, arrays are usually secondary.
I think I will use the hash. And I will probably use a DateTime variable
type for the key. And I will certainly use names for references rather than
integer array indexes, but I was so confused that I wanted to simplify as
much as possible, just to get something working.
BTW, I have tried adding comments to the following code which was part of
the original mailer.pl I used as a starting point. I think I understand most
of it but there are some areas that seem strange:
foreach ('Full_Name', 'Email', 'Event_Title','Event_Date','Event_Time',
'Event_Description') {
# If a field has newlines, it's probably a block of text; indent it.
# Binary "=~" binds a scalar expression to a pattern match.
# Search $in{$_} for \n newline
if ($in{$_}=~ /\n/) {
# Catenation "." add \n newline ahead of data string
$in{$_}= "\n" . $in{$_} ;
# Substitute \n with \n + four spaces, /g = global, all instances
$in{$_}=~ s/\n/\n /g ;
# Concatenate \n newline at end
$in{$_}.= "\n" ;
}
# comma-separate multiple selections
#************* What is \0 except a null? ***************
$in{$_}=~ s/\0/, /g ; # Substitute \0 with comma and one space ????
# Print fields, aligning columns neatly
# %-8s is 8 character width left justified for $_: (Label+':'),
# followed by $in{$_} (Data) and a newline
printf MAIL "%-${maxlength}s %s\n", "$_:", $in{$_} ;
}
I think I understand it except for the \0. Can a null character appear in
CGI data?
Thanks,
Paul
------------------------------
Date: Wed, 01 Sep 2010 15:26:13 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: "Paul E. Schoen" <paul@pstech-inc.com>
Subject: Re: Multidimensional array
Message-Id: <86k4n53xtm.fsf@red.stonehenge.com>
>>>>> "Paul" == Paul E Schoen <paul@pstech-inc.com> writes:
Paul> I am working on a Windows Vista machine and Perl is installed on
Paul> the server. I use Telnet to access my web space,
Seriously? Telnet? /me looks at calendar
In *September* of *2010*?
/me rolls eyes
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: Wed, 01 Sep 2010 18:43:49 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Multidimensional array
Message-Id: <87aao1xexm.fsf@quad.sysarch.com>
>>>>> "PES" == Paul E Schoen <paul@pstech-inc.com> writes:
PES> "Uri Guttman" <uri@StemSystems.com> wrote in message
PES> news:87zkw11dac.fsf@quad.sysarch.com...
>>>>>>> "PES" == Paul E Schoen <paul@pstech-inc.com> writes:
>>
>> >> Have you read perldoc perldsc, perldoc perllol and perldoc perlreftut?
>>
PES> I have downloaded the entire set of documentation, and I see that
PES> there is a lot to learn. But as it explains in the tutorial, perhaps
>>
>> why did you download it? if you have perl installed properly, you
>> already have the docs! this is a core perl skill to use, know where the
>> docs are, how to scan them and learn what they cover. there are many
>> perl tutorials in the docs today as well.
PES> I am working on a Windows Vista machine and Perl is installed on the
PES> server. I use Telnet to access my web space, assign permissions, run
PES> test scripts, and sometimes I even use the pico editor. But I'm using
PES> PerlEdit locally to edit the scripts and HTML/JavaScript files, and I
PES> use NCH Classic FTP for uploads. It's handy to have the docs available
PES> off-line.
install perl and a web server on your box. makes debugging web stuff
much easier. you can run the perl scripts locally (without the server)
with the CGI.pm module and test them. then run under your local web
server for more testing. only THEN do you upload to your final
server. you are doing 10 times the work to get anything done.
PES> For developing Windows GUI apps with Borland Delphi I am spoiled
PES> by having a context sensitive help system available and also a
PES> sophisticated debugger. It would be great to have tools like that
PES> for Perl. I suppose I could use the debugging features but I
PES> would probably need to run the script from the command line.
that isn't spoiling but lowering your skill levels. real programming is
about design and thinking, not having dinky shortcuts done for you by an
ide.
PES> only 10% needs to be understood and used. It is confusing (to
>> me) and
PES> apparently there are multiple ways to accomplish the same thing (and
PES> this is also true in C and other languages). I find it hard to allow
PES> the interpreter to take care of things that would need to be more
PES> formally expressed in a strongly typed language.
>>
>> why? the whole idea is for perl to do the work for you. it means less
>> coding and fewer bugs on your part. that is more important than how much
>> cpu is used.
PES> Perl does seem to be very powerful, but the syntax is difficult
PES> for me to grasp because it is so cryptic. I am used to language
PES> that is verbose and highly readable, while it seems like a rite
PES> of passage to be able to read the various symbols that constitute
PES> much of Perl. Of course, it is a learning curve, and as I build
PES> my script I am learning what they mean. I don't have the time or
PES> enthusiasm to learn Perl in a structured manner as a course in
PES> the language. I intend to learn enough to accomplish my immediate
PES> objectives, and then move on to other things. I am primarily a
PES> hardware engineer specializing in high power test equipment,
PES> which often involves PIC programming which is mostly assembly
PES> language and some C. So I am more comfortable with low level
PES> programming at the bit and byte and memory address level. Delphi
PES> provides a means for OOP and strict type declarations which IMHO
PES> makes for a more readable source and less chance for bugs.
the syntax is no more cryptic than any other lang. syntax is the least
important issue in a language, semantics is way more important. perl can
do hashes and regex in core, c can't. that is a trump of semantics vs
syntax.
>> you should really switch to a hash for the lower level. arrays of
>> different types will break eventually. you can't add/delete something
>> without changing ALL the uses of those integers later on. with a hash
>> you can change all you want and the existing code will always work (or
>> require much less changing than with arrays). hashes are the key perl
>> construct, arrays are usually secondary.
PES> I think I will use the hash. And I will probably use a DateTime
PES> variable type for the key. And I will certainly use names for
PES> references rather than integer array indexes, but I was so confused
PES> that I wanted to simplify as much as possible, just to get something
PES> working.
don't think about it. it will be much better code and the syntax is very
similar to the array style. in most cases all you will do is change @
for % and [] for {}. and then change the index numbers to string keys.
PES> BTW, I have tried adding comments to the following code which was part
PES> of the original mailer.pl I used as a starting point. I think I
PES> understand most of it but there are some areas that seem strange:
PES> foreach ('Full_Name', 'Email',
PES> Event_Title','Event_Date','Event_Time', 'Event_Description') {
PES> # If a field has newlines, it's probably a block of text; indent it.
PES> # Binary "=~" binds a scalar expression to a pattern match.
no need to comment on ops. the more you use them, the less you need to
comment on them. =~ is a fairly common op
PES> # Search $in{$_} for \n newline
PES> if ($in{$_}=~ /\n/) {
don't use $_ unless you have to. named variables are better. by looking
at this code, you can't tell what kind of data is in $_. a named var
will tell you that.
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: Wed, 01 Sep 2010 19:39:56 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: Multidimensional array
Message-Id: <m239ttkp83.fsf@sherm.shermpendley.com>
"Paul E. Schoen" <paul@pstech-inc.com> writes:
> For developing Windows GUI apps with Borland Delphi I am spoiled by
> having a context sensitive help system available and also a
> sophisticated debugger. It would be great to have tools like that for
> Perl.
<http://www.activestate.com>
sherm--
--
Sherm Pendley
<http://camelbones.sourceforge.net>
Cocoa Developer
------------------------------
Date: Thu, 2 Sep 2010 00:55:21 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Multidimensional array
Message-Id: <9o53l7-gdh1.ln1@osiris.mauzo.dyndns.org>
Quoth "Paul E. Schoen" <paul@pstech-inc.com>:
>
>
> I am working on a Windows Vista machine and Perl is installed on the server.
> I use Telnet to access my web space, assign permissions, run test scripts,
> and sometimes I even use the pico editor. But I'm using PerlEdit locally to
> edit the scripts and HTML/JavaScript files, and I use NCH Classic FTP for
> uploads. It's handy to have the docs available off-line.
>
> For developing Windows GUI apps with Borland Delphi I am spoiled by having a
> context sensitive help system available and also a sophisticated debugger.
> It would be great to have tools like that for Perl. I suppose I could use
> the debugging features but I would probably need to run the script from the
> command line.
http://padre.perlide.org/download.html
(Note that I don't use it myself, but it has a good reputation.)
Ben
------------------------------
Date: Wed, 01 Sep 2010 19:29:27 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Multidimensional array
Message-Id: <slrni7trj5.vo4.tadmc@tadbox.sbcglobal.net>
Paul E. Schoen <paul@pstech-inc.com> wrote:
> I am used to language that is verbose and
> highly readable,
Which one is more readable?
There is a car approaching on the left at high speed, it
will hit you if you do not move.
Move right!
"Verbose" does not imply "readable".
> # comma-separate multiple selections
# convert \0 separated value into a comma separated value
> #************* What is \0 except a null? ***************
It is nothing except a null.
null is the separator.
> $in{$_}=~ s/\0/, /g ; # Substitute \0 with comma and one space ????
> I think I understand it except for the \0.
To represent multiple things (selections) in a single string, you
often include all of the things with a "separator" in between
each one.
\0 is the separator in this case.
> Can a null character appear in
> CGI data?
Yes.
--
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 3110
***************************************