[17395] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4816 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 5 18:10:30 2000

Date: Sun, 5 Nov 2000 15:10:13 -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: <973465813-v9-i4816@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 5 Nov 2000     Volume: 9 Number: 4816

Today's topics:
        Newbie question: Get date of 3rd Friday in a given year <davesisk@ipass.net>
    Re: Newbie question: Get date of 3rd Friday in a given  <eric@urbanrage.com>
    Re: Newbie question: Get date of 3rd Friday in a given  <bart.lateur@skynet.be>
    Re: Newbie question: Get date of 3rd Friday in a given  (Clay Irving)
    Re: OT: Yes there _are_ stupid questions.  Anyone colle <nospam@david-steuber.com>
        Passing hash to perl module spcman@my-deja.com
    Re: Passing hash to perl module (Tad McClellan)
        Performance/scaleablility question:  Perl/CGI vs. Java  <davesisk@ipass.net>
    Re: Perl syntax and beyond (was: Re: Perl style and mod (Abigail)
        script: many very similar letters (emails) to many  dif <krupa@mel222.sggw.waw.pl>
        Translating Perl to English birgitt@my-deja.com
        Using file with procedures <ildar@mera.ru>
    Re: What i'm i doing wrong help!! <nospam@david-steuber.com>
    Re: Why would subs not get the right args? (Tad McClellan)
    Re: Why would subs not get the right args? <uri@sysarch.com>
    Re: Why would subs not get the right args? <jeff@vpservices.com>
    Re: Why would subs not get the right args? (Martien Verbruggen)
    Re: Zone to host data <peter.sundstrom@eds.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 05 Nov 2000 17:05:57 GMT
From: "David Sisk" <davesisk@ipass.net>
Subject: Newbie question: Get date of 3rd Friday in a given year/month?
Message-Id: <VrgN5.20261$%j.6372783@typhoon.southeast.rr.com>

Any ideas on how to easily do this in a CGI script?  Please post or email?

Best regards,
Dave





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

Date: Sun, 05 Nov 2000 13:15:24 -0600
From: eric <eric@urbanrage.com>
Subject: Re: Newbie question: Get date of 3rd Friday in a given year/month?
Message-Id: <3A05B1CC.74779EBD@urbanrage.com>

David Sisk wrote:
> 
> Any ideas on how to easily do this in a CGI script?  Please post or email?
> 
> Best regards,
> Dave

a cheesy way to do it on a system with cal

@info = `cal $month $year`;
$fri = (split(' ', $info[4]))[5];

print "third friday of $month/$year is the $fri\n";

Eric
 eric@urbanrage.com
 Brainbench MVP for Unix Programming
 http://www.brainbench.com


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

Date: Sun, 05 Nov 2000 19:57:11 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Newbie question: Get date of 3rd Friday in a given year/month?
Message-Id: <p8eb0tsoqasvc4632ue9jh4dh8manrcs1r@4ax.com>

David Sisk wrote:

>Any ideas on how to easily do this in a CGI script?  Please post or email?

No, but I have an idea on how to do it in a Perl script.

You can ask what day of the week the first of the month (for example)
is. Turn the date into a time number (long integer, seconds since
epoch), using the standard module Time::Local. No need  to install it,
it is ALWAYS part ofthe standard distribution. Now, asking again for
localtime() for this time number in a list context, will tell you, as
item #6 (seventh item), what day of the week that is. (You may use
gmtime() and timegm(), which may even be safer.) Since friday is day #5,
you can calculate the difference with what you got, add two weeks, and
that's the third friday.

Now, code:

	use Time::Local;
	my $firstofmonth = timegm(0, 0, 0, 1, 10, 100);
	  # 1st of november 2000
        my $wday = (gmtime($firstofmonth))[6];
	my $thirdfriday = 1 + (7 + 5 - $wday) % 7 + 14;
	print "The third friday of november 2000 is on $thirdfriday\n";

This tells me "17".

-- 
	Bart.


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

Date: 5 Nov 2000 20:10:32 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: Newbie question: Get date of 3rd Friday in a given year/month?
Message-Id: <slrn90bflo.4g0.clay@panix3.panix.com>

On Sun, 05 Nov 2000 13:15:24 -0600, eric <eric@urbanrage.com> wrote:
>David Sisk wrote:

>> Any ideas on how to easily do this in a CGI script?  Please post or email?
>> 
>> Best regards,
>> Dave
>
>a cheesy way to do it on a system with cal
>
>@info = `cal $month $year`;
>$fri = (split(' ', $info[4]))[5];
>
>print "third friday of $month/$year is the $fri\n";

There's always the Date::Manip module:

  #!/usr/local/bin/perl -w
  
  use Date::Manip; 
  
  $date = UnixDate(ParseDate("3rd Friday of November"), "%m/%d/%y");
  
  print "$date\n";
  
Result:

  11/17/00

Here's another example:


  #!/usr/local/bin/perl -w

  use Date::Manip;

  $date = UnixDate(ParseDate("Last Friday of December"), "%m/%d/%y");

  print "$date\n";

Result:

  12/29/00

-- 
Clay Irving <clay@panix.com>
Working in the theater has a lot in common with unemployment. 
- Arthur Gingold 


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

Date: Sun, 05 Nov 2000 18:56:46 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: OT: Yes there _are_ stupid questions.  Anyone collect them?
Message-Id: <m3snp6p7rw.fsf@solo.david-steuber.com>

"Alan J. Flavell" <flavell@mail.cern.ch> writes:

' well...
' 
' > and kill its computer somehow.
' 
' This _is_ OT, but don't even suggest that, even in desperation.

Yes, I won't mention that again.  Such a mechanism would open you up
to all sorts of DOS attacks anyway.  Not to mention the excessive CPU
usage just to deal with mail.

There are plenty of filters about for MTAs anyway that allow you to
send back a 550 and close the connection.  Checking that the
connecting host has an IP that is an MX record is one.  Using ORBS to
deny connections from open relays is another (although I don't really
like that one too much).

Just to be clear, I'm not advocating actually launching such an
attack.  It was just a wishful thought, not intended to be carried
out.  My ISP would most certainly boot me out if I did such a thing.

-- 
David Steuber | Perl apprentice.  The axe did not stop the
NRA Member    | mops and buckets from flooding my home.
ICQ# 91465842
***         http://www.david-steuber.com/          ***


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

Date: Sun, 05 Nov 2000 21:43:14 GMT
From: spcman@my-deja.com
Subject: Passing hash to perl module
Message-Id: <8u4k9h$s2g$1@nnrp1.deja.com>

Hi im having a problem with no immediate fix.
Ive learned the basics of perl from my experience
with other programming languages, lots of source
code examples, and a few faqs.  I am not an
expert.  Anyhow heres my problem.

I have a script test.cgi and a (perl module?)
template.pm

I want to transfer a hash from my test.cgi to a
subroutine in my template.pm

How to I send the hash to template.pm and how do
i receive the hash in template.pm

Heres my current code in test.cgi...

$RunTemplate = New template;
$RunTemplate -> SetVariables(%MyHash);
$RunTemplate -> ProcessTemplate($Location);


heres my code in template.pm

sub SetVariables {
  my %hash = @_;
}


I know its not right but assuming i want to pass
a hash to the subroutine SetVariables in the
Template.pm perl module... can someone please
write me some code.  Thanks - Al


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 5 Nov 2000 16:44:15 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Passing hash to perl module
Message-Id: <slrn90bl5f.csi.tadmc@magna.metronet.com>

On Sun, 05 Nov 2000 21:43:14 GMT, spcman@my-deja.com <spcman@my-deja.com> wrote:

>Hi im having a problem with no immediate fix.


Oh it has an immediate fix.


>Ive learned the basics of perl from my experience
>with other programming languages, lots of source
>code examples, and a few faqs.  


I do not see the #1, first, best, most authoritative Perl
resource listed there, namely Perl's std docs.

   perldoc perlsub

describes how to pass arguments and return values from subroutines.

Which part are you unclear on?


>How to I send the hash to template.pm and how do
          ^^^^^^^^^^^^^

"send the hash" in programmer talk is "pass the hash as an argument".


>i receive the hash in template.pm
>
>Heres my current code in test.cgi...
>
>$RunTemplate -> SetVariables(%MyHash);


That _is_ how you pass the hash as an argument!


>heres my code in template.pm
>
>sub SetVariables {
>  my %hash = @_;
>}


That _is_ how you "receive the hash".


>I know its not right 


What is not right about it?


>but assuming i want to pass
>a hash to the subroutine SetVariables in the
>Template.pm perl module... can someone please
>write me some code.  Thanks - Al


Why? You already have code that passes a hash arg.

What problem, exactly, is it that you are having?


If your hashes are "big" you might want to pass a reference
to a hash instead. To learn about references type:

   perldoc perlreftut
   perldoc perlref


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sun, 05 Nov 2000 17:20:23 GMT
From: "David Sisk" <davesisk@ipass.net>
Subject: Performance/scaleablility question:  Perl/CGI vs. Java Servlets?
Message-Id: <rFgN5.20266$%j.6381401@typhoon.southeast.rr.com>

This is not meant to start a flaming session.  I simply don't know the
answer and wish to ask!

I'm a Perl newbie, and I'm prototyping a CGI app in Perl.  From everything
I've read, Perl performs almost as well as C for lots of things (and I'm
assuming that this applies to CGI apps as well as non-CGI Perl programs).
I've learned enough to know that if the CGI script is hosted on Apache with
the mod_perl extension installed, then performance under heavy use (lots of
concurrent users) should be pretty good.

A friend keeps telling me that I should be creating this as Java Servlets
instead of Perl because Java will scale much better for a large number of
concurrent users.  I've had a Java class, but I wouldn't know where to start
writing this app in Java.  So, I plan to continue writing it in Perl at the
moment.  My thought is that Perl has proven itself for server-side Internet
apps (among many other things), and I'm not convinced that Java has.  Plus
if the popularity of the app really takes off, then I should have a revenue
stream available to get help converting it to Java if necessary.  Finally, I
think it will be much easier to find a hosting provider to run this app
under Perl as compared to Java.

Since Perl and Java both "manage memory" for you, is there any objective
data about which one does it more efficiently for large numbers of
concurrent users in this particular context?

So, has anyone had experience with both of these technologies and been able
to compare them from a performance and scaleability perspective?  I'm
looking for some objective answers, or some links with objective results to
help answer this question for me...

Best regards,
Dave





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

Date: 5 Nov 2000 22:00:40 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Perl syntax and beyond (was: Re: Perl style and module searches)
Message-Id: <slrn90bm48.f32.abigail@tsathoggua.rlyeh.net>

On Sat, 04 Nov 2000 11:22:21 GMT, Gwyn Judd (tjla@guvfybir.qlaqaf.bet) wrote in comp.lang.perl.misc <URL: news:<slrn907sba.h71.tjla@thislove.dyndns.org>>:
++ I was shocked! How could James Taylor <james@NOSPAM.demon.co.uk>
++ say such a terrible thing:
++ >> it is simpler for everyone to use. Having a linked list type is useful
++ >> when you are wanting to add or delete items in the middle of an array.
++ >
++ >So in what way does splice() on an array (of scalars or references to
++ >more complex objects) not perform the function you want?
++ 
++ Well addition or deletion in a linked list is O(1) whereas splice is
++ O(n). So if you are going through the list one by one and adding or
++ deleting items one by one then it will be quicker to do so using a
++ linked list rather than an array.


Deleting from a linked list is O(n) unless you happen to have a
pointer to the to be deleted element.

If you are going through the list one by one, adding or deleting them,
that can be done for arrays in O (n) *total* time as well: just built
a new one. This is how map() and grep() work.

There are cases where linked lists are faster than arrays. But more
often in C than in Perl. 



Abigail


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

Date: Sun, 05 Nov 2000 22:26:17 +0100
From: Jan <krupa@mel222.sggw.waw.pl>
Subject: script: many very similar letters (emails) to many  different recipients
Message-Id: <3A05D078.9DC69473@mel222.sggw.waw.pl>

I need to send automatically many (say 50) very similar
(but a little bit different) letters (emails) to many
different recipients.
E.g.:
 Slightly different subjects
Subj: Payment for ...(different months for different people)

Sir X... and here different names for different letter

Now some sentences (the same for different letters).
We expect that you'll pay Y... $ (possibly different
amounts for different letters). And so on...

It is enough to have two (2) different files e.g.:
one: file1 with email addresses,
second: file2 with entries for subjects and the main text?

Should I use  perl (under (preferably) Linux or Win95/NT) for such job?
Maybe awk is also good or better?
Does anybody know some published, free script (ftp or http address)
for such job?

Do you have some suggestion?


Jan



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

Date: Sun, 05 Nov 2000 19:21:32 GMT
From: birgitt@my-deja.com
Subject: Translating Perl to English
Message-Id: <8u4bvm$ltr$1@nnrp1.deja.com>

 I read the article in tpj's fall 2000 issue by Omri Schwartz
about his perl program translating ANSI C code to descriptive
English sentences.

I wonder if a similar perl program could be written to translate
Perl code into descriptive English.

--
birgitt


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sat, 4 Nov 2000 16:10:25 +0300
From: "Ildar Gabdullin" <ildar@mera.ru>
Subject: Using file with procedures
Message-Id: <8u3m8b$21vs$1@news.kis.ru>

Hello, all.

I have perl script with lot of procedures.
How I can use these procedures in other perl script without converting
1st script to module and using use <module_name> in second script ?
Converting  to module is not appropriate, because I want to determine
disposition of file with procedures at runtime.

Any help very appreciated.

Ildar.





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

Date: Sun, 05 Nov 2000 20:52:38 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: What i'm i doing wrong help!!
Message-Id: <m38zqyp2ei.fsf@solo.david-steuber.com>

"mark" <markscott@barclays.net> writes:

' <!#exec cgi="/cgi-bin/ip.pl">
' 
' My ISP says "Yes, we support SSI, but not executable SSI scripts."
' They support Perl
' What can be the problem?

It could be that you are trying to use an executable SSI script, if I
understand the SSI line above correctly.

-- 
David Steuber | Perl apprentice.  The axe did not stop the
NRA Member    | mops and buckets from flooding my home.
ICQ# 91465842
***         http://www.david-steuber.com/          ***


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

Date: Sun, 5 Nov 2000 10:23:20 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Why would subs not get the right args?
Message-Id: <slrn90aur8.bv1.tadmc@magna.metronet.com>

On Sun, 5 Nov 2000 06:40:41 -0800, Bill Moseley <usenet@hank.org> wrote:

>I guess why my ($foo) = @_ makes me squirm is exactly what started this 
>thread:  my ($foo) = @_ seems to get translated into my $foo = @_ 
>sometimes for new programmers.  


I see that as a Good Thing.

Context is central to "getting it" with regards to Perl.

Being forced to figure out list vs. scalar context early-on
will avoid lots of wasted time on future confusions.



Similarly, it is a Good Thing when a toddler first falls down.
They are forced to develop a "throw out my arms to break the fall"
response. A "net gain" that will serve them far into the future.

:-)




P.S. As a charter member of the Perl Spartacist Party I would be
     remiss not to also include:

        "What doesn't kill a newbie makes her stronger"

     :-)

-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sun, 05 Nov 2000 17:53:24 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Why would subs not get the right args?
Message-Id: <x7lmuygvai.fsf@home.sysarch.com>

>>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:

  BL> I don't. I use it. It makes converting code when you need one more
  BL> parameter for your sub, very easy.

  BL> 	my($ckmon, $opt) = @_;

and also for slurping in the rest of @_ into an array or hash:

	my( $class, %args ) = @_ ;

sometimes i combine use shift to change @_ for a later call:

	my $arg1 = shift ;

	foo( @_ ) ;

i rarely use $_[0] except for some speed cases.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Sun, 05 Nov 2000 11:53:50 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Why would subs not get the right args?
Message-Id: <3A05BACE.6B121362@vpservices.com>

Bill Moseley wrote:
> 
> On Sat, 04 Nov 2000 17:22:35 -0800 Jeff Zucker (jeff@vpservices.com)
> remarked...
> > >     my $ckmon = @_;
> > > this prints '1', when it should print 'jan'.  What the heck is going on?
> >
> > Nope, it should print '1'.  The symbol @_ is a list of items passed into
> > the sub.  The scalar value $ckmon is therefore equal to the length of
> > that list, i.e. 1.  If you want $ckmon to contain 'jan' you need to do
> > one of these:
> >
> >    my $ckmon = shift;
> >    my $ckmon = $_[0];
> >    my($ckmon)= @_;
> 
> I know TMTOWTDI, but that last one always makes me squirm a bit when I
> see it.  But that's just me.  And I saw it quite a few times today.
> When I see it in scripts I tend to deduct points.

Well, frankly I only use the last form myself when there are multiple
parameters being passed, or when I think I might change my mind and
switch between single and multiple parameters.  I included it in this
list mostly for completeness and to point out to the OP that there is a
fundamental (and easy to miss if you aren't watching) difference between
that and the same thing without the parens.

-- 
Jeff


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

Date: Sun, 05 Nov 2000 22:05:13 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Why would subs not get the right args?
Message-Id: <slrn90bmcr.l2.mgjv@verbruggen.comdyn.com.au>

On Sun, 5 Nov 2000 10:23:20 -0500,
	Tad McClellan <tadmc@metronet.com> wrote:
> On Sun, 5 Nov 2000 06:40:41 -0800, Bill Moseley <usenet@hank.org> wrote:
> 
> >I guess why my ($foo) = @_ makes me squirm is exactly what started this 
> >thread:  my ($foo) = @_ seems to get translated into my $foo = @_ 
> >sometimes for new programmers.  
> 
> 
> I see that as a Good Thing.
> 
> Context is central to "getting it" with regards to Perl.

Indeed. Understanding context in Perl is as important as understanding
pointers in C. You can get by, for while, without a good
understangding, and just follow recipes, but there comes a time that
you need to know how it works. The whole idea of scalar vs list
context (and boolean and void contexts), lists vs arrays, comma
operators, propagation of context over certain operators, and all that
jazz, is indeed central.

This is one of the things where the Camel actually is more useful than
the documentation. it contains some good conceptual explanations of
these things. If only that stuff had been around 10 years ago :)

>         "What doesn't kill a newbie makes her stronger"

Very good, although I still dislike the term newbie :)

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | That's funny, that plane's dustin'
Commercial Dynamics Pty. Ltd.   | crops where there ain't no crops.
NSW, Australia                  | 


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

Date: Mon, 6 Nov 2000 09:27:30 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: Zone to host data
Message-Id: <8u4g1s$l7c$1@hermes.nz.eds.com>


Chris Fedde <cfedde@fedde.littleton.co.us> wrote in message
news:DcIM5.164$Bf7.171120128@news.frii.net...
> In article <8ttc0h$1fp$1@hermes.nz.eds.com>,
> Peter Sundstrom <peter.sundstrom@eds.com> wrote:
> >I'm looking to convert zone data to host data, eg:
> >
> >foo1.foo.com    IN A    192.1.1.1
> >foo2.foo.com    IN A    192.1.1.2
> >bar.foo.com      IN CNAME foo1.foo.com
> >
> >would become
> >
> >192.1.1.1    foo1.foo.com  bar.foo.com
> >192.1.1.2    foo2.foo.com
> >
> >I'm unsure which way to approach this.  I need to keep the data in the
same
> >order, so I was thinking of using the Tie::IxHash module and then use
> >hostname as the key.  Does this seem like a sensible approach?
> >
>
> Sounds like a workable approach.  Think about how to deal with hosts that
> have multiple IP addresses.  Think about "round tripping" the data.  Can
> you get back the same (or equivalent) zone file?  What happens to MX
records
> for example. Is that important?

Thanks Chris.

In my instance, I only need to worry about going one way, ie: zone -> host.
I only need to worry about A and CNAME records.




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

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 V9 Issue 4816
**************************************


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