[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

MacPerl-Digest V1 #9




MacPerl-Digest         Friday, March 12 1999         Volume 01 : Number 009



Re: [MacPerl] Off-topic: Use of the 'strict' pragma
[MacPerl] Bit::Vector up on MacPerl Modules Porters page
Re: [MacPerl] Bit::Vector up on MacPerl Modules Porters page
Re: [MacPerl] How do I find the day of the week from a given date (NOT today)
Re: [MacPerl] How do I find the day of the week from a given date(NOT  today)
[MacPerl] Elementary question (I think)
[MacPerl] Elementary question (I think)
Re: [MacPerl] Elementary question (I think)
Re: [MacPerl] How do I find the day of the week from a given date (NOT today)
RE: [MacPerl] How do I find the day of the week from a given date (NOT today)
RE: [MacPerl] How do I find the day of the week from a given date  (NOT today)
Re: [MacPerl] Elementary question (I think)
Re: [MacPerl] Elementary question (I think)
[MacPerl] XML
Re: [MacPerl] How do I find the day of the week from a given date (NOT today)
Re: [MacPerl] Elementary question (I think)

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

Date: Thu, 11 Mar 1999 09:05:25 -0400 (AST)
From: Arved Sandstrom <Arved_37@chebucto.ns.ca>
Subject: Re: [MacPerl] Off-topic: Use of the 'strict' pragma

In response to your questions, to wit:

\Q

1. Am I correct in assuming that the larger the project, the more likely
strict is used? Or, in the real world do some programmers just ignore it? 
2. Is strict, too strict? (This is hinted at, but I value your comments.) 
3. Once development is complete, can you save some (loading|run)time by
commenting out strict?
4. Should one 'use strict;' encompassing 'vars',
refs', and 'subs'? When should a programmer get specific?
5. Is there anything else one should know about the strict pragma? 

\E

Chris Nandor basically already said what I would have, but I figured
comments from another source can't hurt.

Your Q2 ties in with Q4. 'use strict' is indeed too strict at times, but
you address it by selectively using 'no strict' of whatever type you need.

There's more positive control. You turn it off when you know why you're
doing it. A good example is when you're using symbolic references. Just
for the code that uses those, you turn off strict refs. Rest of the time,
strict is saving your bacon.

I'm not the best typist in the world, and I find that with Perl, over half
my typos are legal code. :-) So I'll use -w and 'use strict' until the
cows come home.

The good thing about it, too, is it makes you think about scoping. You
start pre-declaring things with 'use vars' and 'use subs'. You start
thinking more about initializations. You start declaring variables in
fewer places, so it's easier to keep track of them.

And to answer your Q1, not enough programmers use strict. If _you_ do,
you're already a leg up on a lot of coders.

Arved



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 09:09:39 -0400 (AST)
From: Arved Sandstrom <Arved_37@chebucto.ns.ca>
Subject: [MacPerl] Bit::Vector up on MacPerl Modules Porters page

Just what it says. :-) Bit-Vector-5.6 is ported and available as a binary
at URL http://pudge.net/mmp.

Comments, feedback, brickbats etc welcomed (by me) if you download and use
it. Especially CFM68K. I see that Storable has glitches with 68K - this
likely affects anything I build for 68K, too, but feedback would be nice.

Thanks. Arved



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 09:11:45 -0500
From: Chris Nandor <pudge@pobox.com>
Subject: Re: [MacPerl] Bit::Vector up on MacPerl Modules Porters page

At 08.09 -0500 1999.03.11, Arved Sandstrom wrote:
>Just what it says. :-) Bit-Vector-5.6 is ported and available as a binary
>at URL http://pudge.net/mmp.
>
>Comments, feedback, brickbats etc welcomed (by me) if you download and use
>it. Especially CFM68K. I see that Storable has glitches with 68K - this
>likely affects anything I build for 68K, too, but feedback would be nice.

BTW, I tested Bit::Vector for CPAN Testers, and everything passed.  When I
test a binary build for MacPerl, I put a note to go to the MMP page in the
test result.

- --
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 09:10:42 -0500
From: Chris Nandor <pudge@pobox.com>
Subject: Re: [MacPerl] How do I find the day of the week from a given date (NOT today)

I would do:

  #!perl -w
  use Date::Parse;
  print ( (localtime( str2time('15 Mar 1999') ))[6]);

Or for more clarity:

  #!perl -w
  use Date::Parse;
  use Time::localtime;
  print localtime(str2time('15 Mar 1999'))->wday;

Date::Parse is on CPAN.

- --
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 15:27:24 +0100
From: "Lars G. Skjellerup" <stenone@silkeborg.bib.dk>
Subject: Re: [MacPerl] How do I find the day of the week from a given date(NOT  today)

Chris Nandor wrote:
> 
> I would do:
> 
>   #!perl -w
>   use Date::Parse;
>   print ( (localtime( str2time('15 Mar 1999') ))[6]);
> 
> Or for more clarity:
> 
>   #!perl -w
>   use Date::Parse;
>   use Time::localtime;
>   print localtime(str2time('15 Mar 1999'))->wday;
> 
> Date::Parse is on CPAN.

Thanks - just what the doctor ordered (:-)



************************************************************
* Lars G. Skjellerup                                       *
* Web designer/Programmer - Software Tester                * 
*                                                          *
* Silkeborg Bibliotek  Phone:  (+45) 86820233 ext. 380     *
* Hostrupsgade 41 A    Fax:    (+45) 86802679              * 
* DK 8600 Silkeborg    E-mail: stenone@silkeborg.bib.dk    *
* Denmark                      stenone@netscape.net        *
*                              stenone@hotmail.com         *
*                              stenone@yahoo.com           *
*                              stenone@forum.dk            *
*                                                          *
*                      URL:    http://www.silkeborg.bib.dk * 
************************************************************

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 15:34:52 +0000
From: Chris Sansom <chris@highway57.co.uk>
Subject: [MacPerl] Elementary question (I think)

Hi MacPerlers

This is really a general Perl question, but it happens to have cropped up
while I'm testing a CGI script written with MacPerl.

Suppose I have an array @stuff, when can and can't I use this syntax:

for ($i = 0; $i <= @stuff, $i++) {
...
}

I was under the impression that this was perfectly safe, but it seems to
break my script. As soon as I change all those @'s in this type of
construct to $# it works just fine.

 Cheers ... Chris
 ======================================================================
 Chris Sansom    -    Highway 57   -   Designs for the World Wide Web |
 chris@highway57.co.uk                     http://www.highway57.co.uk |
 ======================================================================



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 15:46:31 +0000
From: Chris Sansom <chris@highway57.co.uk>
Subject: [MacPerl] Elementary question (I think)

Oops - I think I sent this to the wrong address. Try again...

Hi MacPerlers

This is really a general Perl question, but it happens to have cropped up
while I'm testing a CGI script written with MacPerl.

Suppose I have an array @stuff, when can and can't I use this syntax:

for ($i = 0; $i <= @stuff, $i++) {
...
}

I was under the impression that this was perfectly safe, but it seems to
break my script. As soon as I change all those @'s in this type of
construct to $# it works just fine.

 Cheers ... Chris
 ======================================================================
 Chris Sansom    -    Highway 57   -   Designs for the World Wide Web |
 chris@highway57.co.uk                     http://www.highway57.co.uk |
 ======================================================================



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 10:57:00 -0500
From: Chris Nandor <pudge@pobox.com>
Subject: Re: [MacPerl] Elementary question (I think)

At 10.46 -0500 1999.03.11, Chris Sansom wrote:
>Oops - I think I sent this to the wrong address. Try again...

The old address is aliased to the new, so no worries.

>Suppose I have an array @stuff, when can and can't I use this syntax:
>
>for ($i = 0; $i <= @stuff, $i++) {
>...
>}
>
>I was under the impression that this was perfectly safe, but it seems to
>break my script. As soon as I change all those @'s in this type of
>construct to $# it works just fine.

@array is the number of elements in @array.  $#array is the last index of
@array.

@array = (0..9);
# scalar @array now is 10
# $#array now is 9

You want the last index, so you want 9.  You can also do this, however:

for my $i (0 .. $#array) {


}

Does the same thing, except that you preallocate a list of 0 .. $#array,
which in perls vefore 5.005 (including MacPerl, which is at 5.004) may
cause memory problems if $#array is huge.

[Also note that if @array is tied (see man perltie), then $#array and
scalar @array may not return reasonable values at all.  But I doubt you are
using a tied array.]

- --
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 11:33:17 -0500 (EST)
From: rjk@linguist.dartmouth.edu (Ronald J. Kimball)
Subject: Re: [MacPerl] How do I find the day of the week from a given date (NOT today)

Lars G. Skjellerup wrote:
> 
> I have a small problem (Yet again). How can I find the day of the week
> from a given date, which is not the date today. If it was the date now
> it is real easy.
> 
> Are there some pearl functions other than localtime(),time() - that
> might be helpful ? Or do I have to construct my own ?
> 

[Is this an FAQ yet? :) ]


use Time::Local;

($mday, $mon, $year) = (11, 3, 1999);             # get date - 11 March 1999

$mon -= 1;  $year -= 1900;
$time = timelocal(0, 0, 12, $mday, $mon, $year);  # convert to tm

$dow = (localtime($time))[6];                     # convert back to date



Ronald

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 08:45:20 -0800
From: Greg Bartlett <gbartlett@metapath.com>
Subject: RE: [MacPerl] How do I find the day of the week from a given date (NOT today)

I think that this can be simplified to:

- -----
#!perl -w 
use Date::Manip;

my $date = ParseDateString("15 Mar 1999");
print UnixDate($date, "%A");
- -----

This is a useful module.

Greg

> -----Original Message-----
> From:	Arved Sandstrom [SMTP:Arved_37@chebucto.ns.ca]
> Sent:	Thursday, March 11, 1999 4:50 AM
> To:	Lars G. Skjellerup
> Cc:	MacPerl - List
> Subject:	Re: [MacPerl] How do I find the day of the week from a given
> date (NOT today)
> 
> On Thu, 11 Mar 1999, Lars G. Skjellerup wrote:
> 
> > I have a small problem (Yet again). How can I find the day of the week
> > from a given date, which is not the date today. If it was the date now
> > it is real easy.
> > 
> > Are there some pearl functions other than localtime(),time() - that
> > might be helpful ? Or do I have to construct my own ?
> > 
> There is always the monolithic, all-capable Date::Manip module. :-)
> 
> I don't use it myself, so the following is a cobble, and parts may be
> round-about, but it works:
> 
> #!perl -w
> 
> use Date::Manip; 
> 
> $date=&ParseDateString("15 Mar 1999");
> $unixdate = &UnixDate($date, "%m %d %y");
> ($m, $d, $y) = split(/ /,$unixdate);
> $day=&Date_DayOfWeek($m,$d,$y); 
> 
> @daynames = ("","Mon","Tue","Wed","Thu","Fri","Sat","Sun"); 
> print "Day = $daynames[$day]\n";
> 
> __END__
> 
> 
> 
> ===== Want to unsubscribe from this list?
> ===== Send mail with body "unsubscribe" to macperl-request@macperl.org

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 13:00:33 -0400 (AST)
From: Arved Sandstrom <Arved_37@chebucto.ns.ca>
Subject: RE: [MacPerl] How do I find the day of the week from a given date  (NOT today)

On Thu, 11 Mar 1999, Greg Bartlett wrote:

> I think that this can be simplified to:
> 
> -----
> #!perl -w 
> use Date::Manip;
> 
> my $date = ParseDateString("15 Mar 1999");
> print UnixDate($date, "%A");
> -----
> 
> This is a useful module.
> 
Thank you, sir. I'll give it a try. I cobbled something together real
quick, and it showed.

I haven't used it much, except as XML::XQL makes use of it, but I've
looked over the manpage for Date::Manip, and I'm impressed with it. That
was sort of another point I wanted to make - it's slower than other Date
modules for a number of things, but for sheer ability and scope it's
unrivalled.

Arved



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 18:39:49 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: [MacPerl] Elementary question (I think)

On Thu, 11 Mar 1999 15:34:52 +0000, Chris Sansom wrote:

>Suppose I have an array @stuff, when can and can't I use this syntax:
>
>for ($i = 0; $i <= @stuff, $i++) {
>...
>}
>
>I was under the impression that this was perfectly safe, but it seems to
>break my script. As soon as I change all those @'s in this type of
>construct to $# it works just fine.

You're doing one loop too many. Result is that $stuff[$i] is undefined
in that last loop.

Either use:

	for ($i = 0; $i < @stuff; $i++) { ... }
or
	for ($i = 0; $i < $#stuff; $i++) { ... }

The last item in @stuff is number $#stuff, @stuff is one more if $]==0
(default/recommended).

	Bart.

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 13:46:20 -0500 (EST)
From: rjk@linguist.dartmouth.edu (Ronald J. Kimball)
Subject: Re: [MacPerl] Elementary question (I think)

Chris Sansom wrote:
> 
> Hi MacPerlers
> 
> This is really a general Perl question, but it happens to have cropped up
> while I'm testing a CGI script written with MacPerl.
> 
> Suppose I have an array @stuff, when can and can't I use this syntax:
> 
> for ($i = 0; $i <= @stuff, $i++) {
> ...
> }
> 
> I was under the impression that this was perfectly safe, but it seems to
> break my script. As soon as I change all those @'s in this type of
> construct to $# it works just fine.
> 


scalar(@stuff) is the number of elements in the array @stuff.  Because the
first index is 0, the last index is @stuff-1.  Your loop goes past the end
of the array.


You should use either

   for ($i = 0; $i < @stuff, $i++) {

or

   for ($i = 0; $i <= $#stuff, $i++) {


Ronald

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 13:15:20 -0600 (CST)
From: w e b s l a v e <PPRODOEHL@qgraph.com>
Subject: [MacPerl] XML

Hello, I've been off the list for a while, can someone clue me into
where MacPerl is with regards XML? (and the XML Parser and Expat?)

thanks...


Pete



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 12:36:46 -0700
From: Eric Dobbs <dobbs@epost.com>
Subject: Re: [MacPerl] How do I find the day of the week from a given date (NOT today)

At 11:33 AM -0500 3/11/99, Ronald J. Kimball wrote:
>Lars G. Skjellerup wrote:
>> Are there some pearl functions other than localtime(),time() - that
>> might be helpful ? Or do I have to construct my own ?
>
>[Is this an FAQ yet? :) ]

Don't know about a FAQ, but there is an entire chapter
devoted to date & time in the _Perl_Cookbook_.

Tho' the details have been covered earlier in this thread
These recipies would be relevant to the discussion.
3.6  Day in a Week/Month/Year or Week Number  p.79
3.7  Parsing Dates and Times from Strings     p.81

_Perl_Cookbook_ is cool!

Eric



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

Date: Thu, 11 Mar 1999 13:38:49 -0600
From: Dave Lorand <davel@src.uchicago.edu>
Subject: Re: [MacPerl] Elementary question (I think)

At 9:57 AM -0600 3/11/99, Chris Nandor wrote:
>At 10.46 -0500 1999.03.11, Chris Sansom wrote:
>>Oops - I think I sent this to the wrong address. Try again...
>
>The old address is aliased to the new, so no worries.
>
>>Suppose I have an array @stuff, when can and can't I use this syntax:
>>
>>for ($i = 0; $i <= @stuff, $i++) {
>>...
>>}
>>
>>I was under the impression that this was perfectly safe, but it seems to
>>break my script. As soon as I change all those @'s in this type of
>>construct to $# it works just fine.
>
>@array is the number of elements in @array.  $#array is the last index of
>@array.
>
>@array = (0..9);
># scalar @array now is 10
># $#array now is 9
>
>You want the last index, so you want 9.  You can also do this, however:
>
>for my $i (0 .. $#array) {
>
>
>}

I would add that you can also use your original syntax, provided you
haven't changed $[ (and you shouldn't - that's deprecated).  You need to
change one thing, though - you need to say "$i < @stuff" rather than "$i <=
@stuff".  The <= breaks your script because on the last time through the
loop it uses an array index which is one greater than the biggest one.

I'm only pointing this out because I find @stuff more readable than
$#stuff.  To each their own.

Regards,

Dave
 ____________________________________________________________
| Dave Lorand, Programmer/Analyst   | davel@src.uchicago.edu |
| Social Science Research Computing | 773-702-3792           |
| University of Chicago             | 773-702-2101 (fax)     |
+-----------------------------------+------------------------+
 ---> finger davel@cicero.src.uchicago.edu for my PGP key <--

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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

End of MacPerl-Digest V1 #9
***************************


==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to
==== macperl-digest-request@macperl.org