[18011] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 171 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 29 21:06:51 2001

Date: Mon, 29 Jan 2001 18:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <980820308-v10-i171@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 29 Jan 2001     Volume: 10 Number: 171

Today's topics:
    Re: [Q] Character / string analysis. <bcaligari@my-deja.com>
    Re: [Q] Character / string analysis. (Richard J. Rauenzahn)
        A simple question about using Braces <sysdba@pacbell.net>
    Re: Cron task (Rob - Rock13.com)
    Re: Finding a char in string <godzilla@stomp.stomp.tokyo>
    Re: HELP: localtime, days of a month <godzilla@stomp.stomp.tokyo>
        idea for extension of perldoc and CPAN shell (=?iso-8859-1?Q?J=F6rg?= Ziefle)
    Re: idea for extension of perldoc and CPAN shell (Steven Smolinski)
    Re: idea for extension of perldoc and CPAN shell <elijah@workspot.net>
    Re: Newbie Question:  Can I compile a Perl Script? <carvdawg@patriot.net>
    Re: Newbie Question:  Can I compile a Perl Script? <carvdawg@patriot.net>
    Re: Newbie Question:  Can I compile a Perl Script? (Eric Bohlman)
    Re: Problem renaming under Win32 (at)msn.(dot)(deletethis)
        Seeking timezone conversion advice (James Weisberg)
    Re: simple, simple question (Damian James)
    Re: substituting "@" with regexp <elijah@workspot.net>
        Using Braces <sysdba@pacbell.net>
    Re: Using global var in subroutine <wyzelli@yahoo.com>
    Re: Win32ChangeNotify problems w/WinNT while Win98 is O <carvdawg@patriot.net>
    Re: Win32ChangeNotify problems w/WinNT while Win98 is O <dprovac1@twcny.rr.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 29 Jan 2001 23:15:30 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: [Q] Character / string analysis.
Message-Id: <954tia$nej$1@nnrp1.deja.com>

In article <Pine.A41.4.21.0101191655120.18502-
100000@dante39.u.washington.edu>,
  Anshuman Pandey <apandey@u.washington.edu> wrote:
>
> Hello,
>
> I would like to parse a text string and find all the possible linear
> combinations of the characters in the string. Since I'm not a computer
> scientist, I am ignorant of theories of performing string scansion.
>

Another solution using recursion........although I prefer the one using
a binary fill-in.

recur(split('','ABCDE'));

sub recur	{
	my ($prefix, $infix, @suffix) = @_;
	unless (@suffix)	{
		print "$prefix$infix\n";
		print "$prefix+$infix\n";
		return;
	}
	recur("$prefix$infix", @suffix);
	recur("$prefix+$infix", @suffix);
}

Brendon


Sent via Deja.com
http://www.deja.com/


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

Date: 29 Jan 2001 21:55:45 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: [Q] Character / string analysis.
Message-Id: <980805344.361665@hpvablab.cup.hp.com>

Anshuman Pandey <apandey@u.washington.edu> writes:
>
>Hello,
>
>I would like to parse a text string and find all the possible linear
>combinations of the characters in the string. Since I'm not a computer
>scientist, I am ignorant of theories of performing string scansion.

I believe this provides a correct answer.  String length is limited by
the number of bits that represents an integer on your hardware.  It uses
the computer's binary representation to create the permutations.  (i.e.,
pretend there is a bit between each letter, and cycle over 0 ..  N to
turn them on/off -- and write out a + when the bit is true.)

I'd love to see other solutions...

#!/usr/bin/perl -w

use strict;

while(<STDIN>) {
   print "---\n";
   chomp $_;
   my @letters = split(//, $_);
   foreach (0 .. (2**(length($_)-1) - 1)) {
      for(my $l = 0; $l < $#letters; $l++) {
         print $letters[$l];
         print "+" if((1 << $l) & $_);
      }
      print $letters[-1] ."\n";
   }
}
__END__


$ ./foo
ABCD
---
ABCD
A+BCD
AB+CD
A+B+CD
ABC+D
A+BC+D
AB+C+D
A+B+C+D

>To illustrate what I mean, take, for example, the string "abcd", of which 
>there are 8 possible linear combinations:
>
>	A+B+C+D	(3 dividers)
>	A+B+CD  (2 dividers)
>	A+BC+D
>	AB+C+D
>	A+BCD   (1 divider)
>	AB+BC
>	ABC+D
>	ABCD    (0 dividers)


Rich
-- 
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant     | I speak for me,     |   19055 Pruneridge Ave. 
Development Alliances Lab|            *not* HP |                MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014


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

Date: Mon, 29 Jan 2001 17:53:41 -0800
From: "Vik" <sysdba@pacbell.net>
Subject: A simple question about using Braces
Message-Id: <kcpd6.111$mq6.155341@news.pacbell.net>

This may be trivial, but has me stuck. What does the following construct do
in perl:

$sql=q{select sysdate from dual};

I put this in a script by itself followed by a print $sql statement and ran
it. It echoed the select statement back at me. Looking at the camel book, it
seems that the q adds single quotes to the select statement. But what is not
clear to me is the use of { }. Why braces??

Appreciate your help!

-Vik





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

Date: 29 Jan 2001 23:54:19 GMT
From: rob_13@excite.com (Rob - Rock13.com)
Subject: Re: Cron task
Message-Id: <9038C9097rock13com@207.91.5.10>

 <jean@ematic.com>:

>Now, I want run "script.cgi" in a cron task, must I setup crontab
>with: (for every days at 7 AM)...

Uhm, perhaps you posted to the wrong group on accident. Try man cron.
-- 

Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/


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

Date: Sun, 28 Jan 2001 15:56:30 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Finding a char in string
Message-Id: <3A74B1AE.FDB71B78@stomp.stomp.tokyo>

amonotod wrote:
 
> Godzilla! wrote:
> > amonotod wrote:
> > >  Godzilla! wrote:
> > > > Mark Jason Dominus wrote:

> > > > > >A substring method for this case example is significantly
> > > > > >faster,

> > > > > That does not appear to be true.

> > > > > My earlier benchmark was in error.  I was benchmarking

> > > > > The conclusion of my article is the same however.  An amended
> > > > > version follows.  My apologies for any confusion.

> > > > My benchmark results made prior to posting
> > > > my initial article directly contradict your
> > > > own results.

> > > Believe it or not, but moronzilla appears to be correct... At least,
> > > the code included below endorses her claim (unfortunately... :-< ).

> > (snipped intellectually insulting tests)

> Okay, whatever... Tests that validated the claims made by moronzilla,
> and in no way *intellectually* insulted anyone.

(snipped)

Your logic displayed within the remainder of your article
is as flawed as your test methodolgy and results. These
testing methods and results of Dominus, are so seriously
flawed, they are unworthy of comment. Yours however, are
somewhat childishly better.

Your methodology is analogous to measuring ambient air
temperature over Los Angeles for a twenty-four hour period,
then compensating for meteorological conditions, greenhouse
effect, ambient reflected radiant heat along with other
external factors, then calculating the average radiant
energy of our sun and announcing your results as absolute
fact beyond question. You have too many external factors
and too few controls for your tests. You have not strictly
and directly addressed the question at hand.

The question is,

"Which is faster and more efficient to eliminate all
characters after a semicolon within a string?"

You have unscientifically meandered far from the
question to be tested. Your methods and results
are invalid.

This razor held by Sir William of Ockham, not only
trims away excess fat of explanation, it also trims
away excess ignorance of Scientific Method. Your
methods insult the intelligence of this well trained
and seasoned scientist. I am well credentialed.

A test, in this case a question, is to be addressed
directly and strictly, employing factual data and
making use of the strictest of controls, especially
for a comparison methodology.

You know the question. Factual data is simply an
input string which is precisely duplicated for
each method of comparison. Strict controls are
simply no external factors. Each method is
addressed directly, precisely and exactly. My
method is to compare two very common methods,
two methods most often employed and, only
those under strict controls.

Your method has too many externalities, too few controls,
does not address the question directly and displays 
changing parameters, although each test case more than
validates what I have stated and Dominus ignorantly
claims is untrue. Nevertheless, your article is invalid
although your basic premises are moderately valid.

Below my signature you will discover very exacting
scientific method, with strict controls and repeating
tests to validate results beyond quirk or quark.

I believe this standard method of publishing a
hypothesis, calling for data input from our scientific
community, test replication and discussion, before
publishing a theory to test, can be dismissed for
something this simple.


Godzilla!
--

TEST SCRIPT:
____________

#!perl

print "Content-type: text/plain\n\n";

use Benchmark;


print "Test Run One:\n\n";

timethese(1000000,  {
    'Name1' => '$string ="Save This Info; Toss This Info";
                $string =~ s/;.*/;/s;',
    'Name2' => '$string ="Save This Info; Toss This Info";
                $string = substr ($string, 0, index ($string, ";") + 1);',
    });


print "\n\nTest Run Two:\n\n";

timethese(1000000,  {
    'Name1' => '$string ="Save This Info; Toss This Info";
                $string =~ s/;.*/;/s;',
    'Name2' => '$string ="Save This Info; Toss This Info";
                $string = substr ($string, 0, index ($string, ";") + 1);',
    });


print "\n\nTest Run Three:\n\n";

timethese(1000000,  {
    'Name1' => '$string ="Save This Info; Toss This Info";
                $string =~ s/;.*/;/s;',
    'Name2' => '$string ="Save This Info; Toss This Info";
                $string = substr ($string, 0, index ($string, ";") + 1);',
    });


print "\n\nTest Run Four:\n\n";

timethese(1000000,  {
    'Name1' => '$string ="Save This Info; Toss This Info";
                $string =~ s/;.*/;/s;',
    'Name2' => '$string ="Save This Info; Toss This Info";
                $string = substr ($string, 0, index ($string, ";") + 1);',
    });

exit;



PRINTED RESULTS:
________________

Test Run One:

Benchmark: timing 1000000 iterations of Name1, Name2...
Name1:  5 wallclock secs ( 4.45 usr +  0.00 sys =  4.45 CPU) @ 224719.10/s
(n=1000000)
Name2:  3 wallclock secs ( 2.92 usr +  0.00 sys =  2.92 CPU) @ 342465.75/s
(n=1000000)


Test Run Two:

Benchmark: timing 1000000 iterations of Name1, Name2...
Name1:  4 wallclock secs ( 4.45 usr +  0.00 sys =  4.45 CPU) @ 224719.10/s
(n=1000000)
Name2:  3 wallclock secs ( 2.91 usr +  0.00 sys =  2.91 CPU) @ 343642.61/s
(n=1000000)


Test Run Three:

Benchmark: timing 1000000 iterations of Name1, Name2...
Name1:  4 wallclock secs ( 4.45 usr +  0.00 sys =  4.45 CPU) @ 224719.10/s
(n=1000000)
Name2:  3 wallclock secs ( 2.91 usr +  0.00 sys =  2.91 CPU) @ 343642.61/s
(n=1000000)


Test Run Four:

Benchmark: timing 1000000 iterations of Name1, Name2...
Name1:  5 wallclock secs ( 4.39 usr +  0.00 sys =  4.39 CPU) @ 227790.43/s
(n=1000000)
Name2:  3 wallclock secs ( 2.91 usr +  0.00 sys =  2.91 CPU) @ 343642.61/s
(n=1000000)


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

Date: Sun, 28 Jan 2001 15:23:17 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: HELP: localtime, days of a month
Message-Id: <3A74A9E5.B329891A@stomp.stomp.tokyo>

Nigel wrote:

(some snippage)

> I need to find out how many days there are in a given month.
 
> $epoch_seconds_1 = (0,0,0,0,$month1,$year);
> $epoch_seconds_2 = (0,0,0,0,$month2,$year);

 
Below my signature, you will find a simple plain English
test script which accomplishes your task and a few extras.

Godzilla!
--

TEST SCRIPT:
____________


#!perl

print "Content-type: text/plain\n\n";

($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = localtime(time);

if ($hour < 12)
 { $hour = "0$hour";}
if ($min < 10)
 { $min = "0$min"; }
if ($sec < 10)
 { $sec = "0$sec"; }

@Array_Days = qw (0¦January¦31 1¦February¦28 2¦March¦31 3¦April¦30
                  4¦May¦31 5¦ 5¦June¦30 6¦July¦31 7¦August¦31
                  8¦September¦30 9¦October¦31 10¦November¦30
                  11¦December¦31);

@Array_Leap = (12 .. 96);

$leap_year = substr ($year, -2, 2);

if (($leap_year eq "00") ||
    ($leap_year eq "04") ||
    ($leap_year eq "08"))
 { $Array_Days[1] = "1¦February¦29"; }
else
 {
  foreach $leap (@Array_Leap)
   {
    if ($leap_year == $leap)
      { $Array_Days[1] = "1¦February¦29"; last; }
   }
 }

$year = $year + 1900;

foreach $days (@Array_Days)
 {
  ($local_mon, $month_name, $num_days) = split (/¦/, $days);
  if ($mon == $local_mon)
   { 
    print "$month_name Has $num_days Days.\n\n";
    print "Current Date And Time Is:\n\n",
          "  $month_name $mday, $year At $hour:$min:$sec Hours\n\n",
          "  It Is Day $mday Of $num_days For The Month of $month_name.";
    last;
   }
 }

exit;


PRINTED RESULTS:
________________


January Has 31 Days.

Current Date And Time Is:

  January 28, 2001 At 15:13:13 Hours

  It Is Day 28 Of 31 For The Month of January.


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

Date: 29 Jan 2001 23:29:59 GMT
From: gt4556a@acmez.gatech.edu (=?iso-8859-1?Q?J=F6rg?= Ziefle)
Subject: idea for extension of perldoc and CPAN shell
Message-Id: <slrn97bv7n.88e.gt4556a@acmez.gatech.edu>

I think that it would be nice to have the possibility to read the
perldocs (and README file) from modules not locally installed via
perldoc and even the CPAN shell.  The files could be retrieved via a
request to CPAN or to one of the numerous frontends like WAIT.

Is anyone interested in the implementation of this or (horrors) does
this facility already exist?
-- 
Jörg Ziefle


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

Date: Tue, 30 Jan 2001 00:37:54 GMT
From: sjs@linux.ca (Steven Smolinski)
Subject: Re: idea for extension of perldoc and CPAN shell
Message-Id: <slrn97c7jj.lr.sjs@ragnar.stevens.gulch>

Jörg Ziefle <gt4556a@acmez.gatech.edu> wrote:
> I think that it would be nice to have the possibility to read the
> perldocs (and README file) from modules not locally installed via
> perldoc and even the CPAN shell.  The files could be retrieved via a
> request to CPAN or to one of the numerous frontends like WAIT.
> 
> Is anyone interested in the implementation of this or (horrors) does
> this facility already exist?

Well, after starting the shell and typing "help," you get (in part):

 ...
 look                       open subshell in these dists' directories
 readme                     display these dists' README files
 ...

look <module|dist|bundle> downloads the dist and dumps you at a shell
prompt in the directory tree of the distribution.  You can find all the
docs in the world there. 

readme <module|dist|bundle> downloads and displays the readme file for a
module or dist.

It's not exactly what you're talking about, but darned close. :-)

Steve
-- 
Steven Smolinski => http://www.steven.cx/


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

Date: 30 Jan 2001 01:31:19 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: idea for extension of perldoc and CPAN shell
Message-Id: <eli$0101292026@qz.little-neck.ny.us>

In comp.lang.perl.misc, Steven Smolinski <sjs@linux.ca> wrote:
> Jörg Ziefle <gt4556a@acmez.gatech.edu> wrote:
> > I think that it would be nice to have the possibility to read the
> > perldocs (and README file) from modules not locally installed via
> > perldoc and even the CPAN shell.
> Well, after starting the shell and typing "help," you get (in part):
> ...
>  look                       open subshell in these dists' directories
>  readme                     display these dists' README files
> ...
> 
> look <module|dist|bundle> downloads the dist and dumps you at a shell
> prompt in the directory tree of the distribution.  You can find all the
> docs in the world there. 

Yes, but that requires downloading the whole module first. Often
I'd like to know if the module can solve my problem before I do
that. It simplifies my disk space maintainance. (I like to keep
the source to the modules I install, but usually don't care about
the ones I don't install.)

> readme <module|dist|bundle> downloads and displays the readme file for a
> module or dist.

Pity so many readme files merely discuss installation or changes since
the last release, and don't give a decent overview of what the module
actually can do.

Elijah
------
with the CPAN shell, typically installation is the least of my concerns


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

Date: Mon, 29 Jan 2001 18:50:11 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: Newbie Question:  Can I compile a Perl Script?
Message-Id: <3A7601B3.A3B2F207@patriot.net>



> Keep trying.

Trying to do what?  Understand?  Every time I think I have it, some long-time
denizen of the group pushes the line a little more...

> It doesn't stand for anything. I stutter.

Stuttering is a speech impediment.  You were typing at the time.

> Because if someone else with a similar question learns through such a reply
> that the answer to the query is in the FFAQ (there goes that ddamn stutter
> again) he/she won't bother the group with the same question.

This supposition doesn't hold up.  This same question appears over and over
again.  Of course, we have no way of knowing if someone did learn, as such
posts are rarely seen..."I saw how you abused this guy when he asked this
question, so I thought I'd better not ask...."

> If that someone learns that he/she won't get a different reply to a FAQ
> he/she won't bother the group again with stupid questions (hopefully).

What, really, is a stupid question?

> Isn't all of this painfully obvious?

Rather obviously not.  If it were, I wouldn't have asked.

> You don't need to be a genius to
> figure all of this out for yourself, you know.

No.  But many times, particularly for those such as myself who are new to
Perl, and for those who may be using only...say....the Win32 platform, for
example, a little friendly help may be all that's needed.

> Now let's get back to Perl, hmmm?

Well, for someone who wants to get back to Perl, you certainly took a lot
of effort to respond...which was greatly appreciated, by the way.




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

Date: Mon, 29 Jan 2001 18:54:05 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: Newbie Question:  Can I compile a Perl Script?
Message-Id: <3A76029D.E41A766B@patriot.net>

Tried it, on a file called "name.pl", located in the c:\perl directory...output
below:

I'm using ActiveState build 618, on NT Server 4.0 SP6a.

C:\perl>perlcc -b name.pl

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

Compiling name.pl:
--------------------------------------------------------------------------------

Making Bytecode(name.plc) for name.pl!
C:\perl\bin\Perl.exe -IC:/perl/lib -IC:/perl/site/lib -I. -MB::Stash -c  name.pl

C:\perl\bin\Perl.exe -IC:/perl/lib -IC:/perl/site/lib -I. -MO=Bytecode,-umain,-u
Exporter,-uExporter::Heavy,-uWin32,-ustrict,-uattributes,-u<none>,-uSocket,-uDB,
-uwarnings,-uwarnings::register,-uCarp,-uCarp::Heavy name.pl
The system cannot find the file specified.
ERROR: In generating code for name.pl!

Daniel Berger wrote:

> Well, after my little rant, I finally found it.  See the "perlcompile" faq.
>
> To generate C code:
>
> perlcc myperlprogram.pl
>
> To generate byte code:
>
> perlcc -b myperlprogram.pl
>
> The module that handles this is called "B".
>
> James And Tess Hawks wrote:
>
> > Is it possible to compile a Perl script so I can use it on computers without
> > Perl installed?

--
Q: Why is Batman better than Bill Gates?
A: Batman was able to beat the Penguin.




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

Date: 29 Jan 2001 23:55:14 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Newbie Question:  Can I compile a Perl Script?
Message-Id: <954vt2$84b$2@bob.news.rcn.net>

H C <carvdawg@patriot.net> wrote:

> No.  But many times, particularly for those such as myself who are new to
> Perl, and for those who may be using only...say....the Win32 platform, for
> example, a little friendly help may be all that's needed.

Telling someone "a carefully peer-reviewed answer to your question can be 
found in the extensive *completely free* documentation that comes with 
every proper installation of Perl; in fact, it's such a common question 
that's it's been specially indexed to make the answer easy to find" 
strikes me as being within the definition of "a little friendly help."



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

Date: Mon, 29 Jan 2001 19:49:51 -0500
From: "Richard Muller" <rlmuller(at)msn.(dot)(deletethis).com>
Subject: Re: Problem renaming under Win32
Message-Id: <#dJKjYliAHA.237@cpmsnbbsa07>

Eric & Bart,

Many thanks.

I should have printed out $RevisedName ... heck, I printed out darn near
everything else in the course of debugging.

Regards,
Richard

"Richard Muller" <rlmuller(at)msn.(dot)(deletethis).com> wrote in message
news:OMtDLUZiAHA.281@cpmsnbbsa07...
> Hi all,
>
> Sorry for posting so many questions, but I just decided to concentrate
more
> Perl than my "native language" C++, hence more questions as I try to come
up
> to speed.
>
> The following code is intended to rename files I downloaded in the past
when
> two-digit years were adequate. But names like that don't sort
> satisfactorily.  I decided to try and rename them automatically.  But my
> rename  command failed.
>
> Can anyone suggest why rename failed?
>
> ...
> while ( glob($dir . "\\*") )
> {
>      if( /WDJ-099/i )
>     {
>           print "$_\n";
>           $RevisedName = s/WDJ-099/WDJ1999./i;
>           my $nRet = rename($_, $RevisedName);
>           print "$_ <== " . ($nRet?"":"not") . " changed\n";
>           $nFilesChanged++ if( $RevisedName !~ /WDJ-099/i );
>     }
> }
>
> This produced:
>
> K:\_Downloads\_Publications\WDJ\WDJ-09901.zip
> K:\_Downloads\_Publications\WDJ\WDJ1999.01.zip <== not changed
> K:\_Downloads\_Publications\WDJ\WDJ-09902.zip
> K:\_Downloads\_Publications\WDJ\WDJ1999.02.zip <== not changed
>
> Windows Explorer confirms that the rename failed.
>
> Regards,
> Richard
>
>




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

Date: Tue, 30 Jan 2001 01:24:04 GMT
From: chadbour@wwa.com (James Weisberg)
Subject: Seeking timezone conversion advice
Message-Id: <UIod6.13898$Sl.606099@iad-read.news.verio.net>

Hello,

   This isn't strictly a perl question, per se, and I apologize in
advance for the length, but I'm looking for some advice using perl
to calculate a timezone offset. Let me start by describing the idea.
Imagine you have a file with configuration info for four sites in
different timezones:

   [site:1100]                  # Chicago
      timezone = CST
      daylightsavings = 1

   [site:1200]                  # New York
      timezone = EST
      daylightsavings = 1

   [site:1300]                  # Parts of Indiana
      timezone = EST
      daylightsavings = 0

   [site:1400]                  # Parts of Arizona
      timezone = MST
      daylightsavings = 0

   Each site has a database associated with it and there will be some
script which comes along and wants to combine records of one database
with those of another, but perhaps the combination wants to take into
account the timezone difference between the sites. What I have above
is a description of the standard timezone (Eastern, Central, Mountain)
and a flag (0/1) which determines if Daylight Savings Time is applied.
   Okay, now let me describe a function which I will call tzconvert()
whose job is to take a date and a time from one timezone and convert
it to a date and a time in another timezone:

# date= YYYYMMDD
# time= hour and minute in military time
# tz1 = reference *Standard* timezone
# dst1= DST applied to tz1 (0 or 1)
# tz2 = destination *Standard* timezone
# dst2= DST applied to tz2 (0 or 1)
sub tzconvert {
   my($date, $time, $tz1, $dst1, $tz2, $dst2) = @_;

   # code here.
}
   And also imagine the following simple hash which converts a
standard timezone to a GMT offset (for basic North American TZs):

   $GMT{EST} = -5;
   $GMT{CST} = -6;
   $GMT{MST} = -7;
   $GMT{PST} = -8;
   $GMT{ALA} = -9;
   $GMT{HAW} = -10;

========================================================================
   Now let me put forward a few examples:

Ex 1: tzconvert(20010129, 1200, CST, 1, EST, 1)

      Jan 29th 2001 at 12:00pm -> Jan 29th 2001 at 01:00pm

   This is the simplest example, which has us converting from CST to
EST with Daylight Savings Time (henceforth DST) applicable in both
regions (e.g. site 1100 and site 1200). Here, we could have coded
tzconvert() to do the following:

   ($GMT{$tz2} + $dst2) - ($GMT{$tz1} + $dst1) = (-5 + 1) - (-6 + 1) = +1

   and we could have then calculated 20010129 at 12:00pm + 1hrs. And
similarly if we had written: tzconvert(20010129, 1200, EST, 1, CST, 1).
Note also that tzconvert() will require a methodology for advancing or
substracting dates if a daily boundary is crossed; but this part I have
already tackled.

Ex 2: tzconvert(20010129, 1200, MST, 0, EST, 0)

      Jan 29th 2001 at 12:00pm -> Jan 29th 2001 at 02:00pm

   This is another simple example where DST does not apply in either
the source or the destination (e.g. site 1300 and site 1400). Again,
we can straightforward calculate the offset as:

   ($GMT{$tz2} + $dst2) - ($GMT{$tz1} + $dst1) = (-5 + 0) - (-7 + 0) = +2

   and similarly for tzconvert(20010129, 1200, EST, 0, MST, 0).

Ex 3: tzconvert(20010129, 1200, EST, 0, CST, 1)

   This example is where things start getting tricky because DST is not
observed at the source but is observed at the destination. But whether or
not DST is applicable depends on the date in question. In the example
above, on Jan 29th 2001, DST is not applicable in the Central Time Zone
so there should be a time difference between the two sites. That is,

      Jan 29th 2001 at 12:00pm -> Jan 29th 2001 at 01:00pm

   However, if instead we were to run this command for 20010501 at 1200,
DST would apply and the times should be identical.
   Therefore, it seems to me that tzconvert() can be written in its
simple form for all cases where $dst1 = $dst2; otherwise, we need to
find out if $date and $time are in DST for a given timezone. So next
imagine a function isdst(), whose jobs is to tell us if a given date
and time is part of DST for a given timezone:
# return 1 if date/time is in DST for tz; else return 0.
sub isdst {
   my($date, $time, $tz) = @_;

   # code here
}

   and imagine we have the following code embedded in tzconvert():

   if($dst1 != $dst2) {
      $dst1  = isdst($date, $time, $tz1) if ($dst1);
      $dst2  = isdst($date, $time, $tz2) if ($dst2);
   }

   Since $dst1 is 0 in Ex 3, isdst() will not be called. It will be
called for $dst2, however, and if $date and $time were 20010129/1200,
then isdst() should return 0. Using the same calculations above, we
then get:

   ($GMT{$tz2} + $dst2) - ($GMT{$tz1} + $dst1) = (-5 + 0) - (-6 + 0) = +1

   and Jan 29th 2001 at 12:00pm -> Jan 29th 2001 at 01:00pm. But if
we had instead used 20010501/1200, isdst() should return 1 and the
calculation then becomes:

   ($GMT{$tz2} + $dst2) - ($GMT{$tz1} + $dst1) = (-5 + 0) - (-6 + 1) = +0

   and Jan 29th 2001 at 12:00pm -> Jan 29th 2001 at 12:00pm.

=========================================================================

   So assuming my reasoning above is correct, I believe all I need is
an isdst() function. There may be some problem above when the date/time
in question falls right at the 2:00am boundary of Spring Forward or
Fall Behind, but I'm willing to live with a potential hole there for
right now. I also know there is an implicit assumption that all sites
convert to DST at the same time because I want a centrally located
server, not affliated with any particular site, to run isdst() and
determine when the conversion takes place.
   Can someone suggest a way of making the isdst() calculation using
standard timelocal.pl functions and/or pointing me in the direction of
a module which has tackled this issue?

   Much appreciated.


-- 
World's Greatest Living Poster


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

Date: 30 Jan 2001 01:28:55 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: simple, simple question
Message-Id: <slrn97c67a.2fq.damian@puma.qimr.edu.au>

Please have regard to these points: [
	
	- When you reply to a post, do so AFTER the text you are quoting.
	- Choose an APPROPRIATE subject line.
	- Try to explain PRECISELY what it is you are trying to do.
	- Try to work it out for yourself first, and give some indication
	  that you have done this.
	- Don't quote .sigs
]

[Jeopardy response fixed]

Thus spake Jason Wong on Mon, 29 Jan 2001 15:00:55 -0500:
><nobull@mail.com> wrote in message news:u9wvbeuqrs.fsf@wcl-l.bham.ac.uk...
>> "Jason Wong" <wo_ah_ho@yahoo.com> writes:
>>
>> > Subject: simple, simple question
>>
>> We read this as "I am selfish and lazy - please flame me".
>>
[snip reason why this is the case]
>>
>> > How to load a website in cgi script
>>
>> Do you perhps mean "fetch a document from a website in a Perl script"?
>>
>> LWP
>>

>ok...
>
>my script edited a webpage
>i just wanna find a Perl function like
>load(url)
>
>so as to bring up that updated page directly, instead of making another
>hyperlink

OK -- what you mean is something like this: You have a CGI program written
in Perl which has generated HTML, in which you wish to include another web
page, not as a reference, but as part of the generated page.

You have probably already investigated the HTML options for this?
Framesets? This side of the question is not related to Perl.

You have also probably already read some of the Perl documentation related
to CGI programming, such as the manual for the CGI module? You have
searched the documentation that is installed along with Perl on your
computer? What you will have surmised from this is that you need to a)
fetch the HTML document from the other web server, and b) include this HTML
in the HTML you pass to your web server via CGI.

In that case, nobull has already answered your question. You should look at
the documentation for the LWP module, which is in the standard
distribution. Go to a command prompt and type 'perldoc LWP'.

Cheers,
Damian
-- 
#requires 5.6.0 ## my first attempt at one of these...
$;=ord$%,$:=$;-ord q,.,,$_=q,3346:3366:3276:3326:3386:546:566:966:3396:3376:,.
q,3386:546:;96:3326:3336:3386:3266:3236:3366:546::26:3236:3366:32:6:546:3266,.
q,:;96:;;6:3296:3236:3366:326:56,,s,.,ord($&)-$;-$:,eg,s,$;,chr$&-$:,eg,
eval eval;


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

Date: 30 Jan 2001 01:25:57 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: substituting "@" with regexp
Message-Id: <eli$0101292024@qz.little-neck.ny.us>

In comp.lang.perl.misc, Todd Ahlstrom  <todda@xmission.com> wrote:
> I take it back, I thought all the hex was being converted, but I threw
> this line in
> to see what would happen:
> $form{email}=~s/%40/\@/;
> and it fixed the problem.

It fixed the problem you saw, but still leaves you with problems.

Use the CGI module.

Elijah
------
don't trust yourself to write a replacement if you haven't read the RFCs


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

Date: Mon, 29 Jan 2001 17:56:55 -0800
From: <sysdba@pacbell.net>
Subject: Using Braces
Message-Id: <ycpd6.112$mq6.155300@news.pacbell.net>

This may be trivial, but has me stuck. What does the following construct do
in perl:

$sql=q{select sysdate from dual};

I put this in a script by itself followed by a print $sql statement and ran
it. It echoed the select statement back at me. Looking at the camel book, it
seems that the q adds single quotes to the select statement. But what is not
clear to me is the use of { }. Why braces??

Appreciate your help!

-Vic





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

Date: Tue, 30 Jan 2001 09:51:44 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Using global var in subroutine
Message-Id: <aFnd6.11$gG5.2848@vic.nntp.telstra.net>

"Steve Yates" <steve@teamITS.com> wrote in message
news:t7bsai40pbbm04@corp.supernews.com...
>
> The "open" call falls through to the die (not shown) since the file
> "c:/folder//file.txt" isn't found, which tells me that $userCode isn't
being
> recognized (assume $TEMPLATES == "c:/folder/").  $userCode is set at
the

What message are you getting from $! in the die?  c:/folder//file.txt is
probably not a valid path (the double slash).

Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;




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

Date: Mon, 29 Jan 2001 18:57:02 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: Win32ChangeNotify problems w/WinNT while Win98 is OK
Message-Id: <3A76034E.B3CBDD1E@patriot.net>

Dave,

Looks like you might have one too many backslashes in your $path...

Dave wrote:

> Hi,
> I have a simple program using Win32::ChangeNotify that
> works on my Win98 machine but does not work on the
> same
> machine when booted as a Win NT Server.
>
> The code dies on the Win32::ChangeNotify->new line.
> (No error message is displayed, is just says
> "monitorDir.pl die on line 14". So I guess $! must be blank?)
>
> If I change the $path to "C:" under Win NT, it runs,
> but acts "funny".  By "funny" I mean that it does not
> stop the monitoring when I place a file in "C:".
> Meanwhile, once again, on a Win98 machine, everything
> works.  Help!!!  What the heck is wrong?
>
>  use strict;
>  use Win32::ChangeNotify;
> # Look for any changes in the watched Dir.
> # Changes include renames, deletions and creations.
>  my $filter = "FILE_NAME";
>
>  my ($notify);
>  my $path =  "C:\\\\Timothymarsch\\SHARE";
>
>  my $subTree = 1;
>  my $retValue;  # return value
>
>  $notify = Win32::ChangeNotify->new($path, $subTree,
> $filter) || die $!;
>  $retValue = $notify -> wait or die "Something failed:
> $!\n";
>
>  if ($retValue == 1) {
>      print "hip, hip horaay!\n";
>  } else {
>  print STDERR "$notify\n";
>  }
>
> TIA,
> Dave

--
Q: Why is Batman better than Bill Gates?
A: Batman was able to beat the Penguin.




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

Date: Tue, 30 Jan 2001 01:33:42 GMT
From: "Dave" <dprovac1@twcny.rr.com>
Subject: Re: Win32ChangeNotify problems w/WinNT while Win98 is OK
Message-Id: <WRod6.96910$ju6.10615255@typhoon.nyroc.rr.com>

The backslashes in the path have to be escaped, therefore
"C:\\\\Timothymarsch\\SHARE" resolves to
C:\\Timothymarsch\SHARE.

In addition, if there were too many slashes, wouldn't that also
be the case when I run it under Win98 and it runs correctly?



"H C" <carvdawg@patriot.net> wrote in message
news:3A76034E.B3CBDD1E@patriot.net...
> Dave,
>
> Looks like you might have one too many backslashes in your $path...
>
> Dave wrote:
>
> > Hi,
> > I have a simple program using Win32::ChangeNotify that
> > works on my Win98 machine but does not work on the
> > same
> > machine when booted as a Win NT Server.
> >
> > The code dies on the Win32::ChangeNotify->new line.
> > (No error message is displayed, is just says
> > "monitorDir.pl die on line 14". So I guess $! must be blank?)
> >
> > If I change the $path to "C:" under Win NT, it runs,
> > but acts "funny".  By "funny" I mean that it does not
> > stop the monitoring when I place a file in "C:".
> > Meanwhile, once again, on a Win98 machine, everything
> > works.  Help!!!  What the heck is wrong?
> >
> >  use strict;
> >  use Win32::ChangeNotify;
> > # Look for any changes in the watched Dir.
> > # Changes include renames, deletions and creations.
> >  my $filter = "FILE_NAME";
> >
> >  my ($notify);
> >  my $path =  "C:\\\\Timothymarsch\\SHARE";
> >
> >  my $subTree = 1;
> >  my $retValue;  # return value
> >
> >  $notify = Win32::ChangeNotify->new($path, $subTree,
> > $filter) || die $!;
> >  $retValue = $notify -> wait or die "Something failed:
> > $!\n";
> >
> >  if ($retValue == 1) {
> >      print "hip, hip horaay!\n";
> >  } else {
> >  print STDERR "$notify\n";
> >  }
> >
> > TIA,
> > Dave
>
> --
> Q: Why is Batman better than Bill Gates?
> A: Batman was able to beat the Penguin.
>
>




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

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


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

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 V10 Issue 171
**************************************


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