[19585] in Perl-Users-Digest
Perl-Users Digest, Issue: 1780 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 20 09:10:23 2001
Date: Thu, 20 Sep 2001 06:10:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1000991409-v10-i1780@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 20 Sep 2001 Volume: 10 Number: 1780
Today's topics:
run another script from this one (without qx{}) (Rory)
Re: run another script from this one (without qx{}) news@roaima.demon.co.uk
Re: run another script from this one (without qx{}) <tinamue@zedat.fu-berlin.de>
Re: Schwartzian Transform problem <bart.lateur@skynet.be>
Re: select() timeout problem <philippe.perrin@sxb.bsf.alcatel.fr>
Re: select() timeout problem <philippe.perrin@sxb.bsf.alcatel.fr>
setting up time value and converting it to epoch second <shanali@singapura.singnet.com.sg>
Re: setting up time value and converting it to epoch se <Thomas@Baetzler.de>
Re: setting up time value and converting it to epoch se news@roaima.demon.co.uk
Re: setting up time value and converting it to epoch se <shanali@singapura.singnet.com.sg>
Re: split SuchKindOfWord into individual words (Anno Siegel)
Win32::ODBC (James Vaughan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Sep 2001 03:19:58 -0700
From: rory@campbell-lange.net (Rory)
Subject: run another script from this one (without qx{})
Message-Id: <ba9de059.0109200219.4ea41ec6@posting.google.com>
Hi
I have a script which does a whole lot of stuff, and then calls a
mailing script with the names of some attachments that need to be
gzipped/tarred, attached and sent.
This works:
qx{./mail.pl $dir};
but doesn't seem very perlish. Apart from making mail.pl into a
module, what is the approved way of making it callable or part of my
main script?
Thanks for any help.
Rory
------------------------------
Date: 20 Sep 2001 12:21:11 GMT
From: news@roaima.demon.co.uk
Subject: Re: run another script from this one (without qx{})
Message-Id: <3ba9d126@news.netserv.net>
Rory <rory@campbell-lange.net> wrote:
> This works:
> qx{./mail.pl $dir};
> but doesn't seem very perlish. Apart from making mail.pl into a
> module, what is the approved way of making it callable or part of my
> main script?
Not necessarily approved, but you could open it, slurp it, and then eval
the result. Probably not significantly faster or more efficient, either.
As an alternative, have you considered Mail::Mailer?
Chris
------------------------------
Date: 20 Sep 2001 11:35:01 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: run another script from this one (without qx{})
Message-Id: <9ock95$c2qum$1@fu-berlin.de>
news@roaima.demon.co.uk wrote:
> Rory <rory@campbell-lange.net> wrote:
>> This works:
>> qx{./mail.pl $dir};
>> but doesn't seem very perlish. Apart from making mail.pl into a
>> module, what is the approved way of making it callable or part of my
>> main script?
> Not necessarily approved, but you could open it, slurp it, and then eval
> the result.
hm, isn't that kind of what do() is supposed to do?
regards, tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Thu, 20 Sep 2001 09:40:53 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Schwartzian Transform problem
Message-Id: <uaejqtkpj4vn6faenbgia23hjf6if5926g@4ax.com>
Leo Hemmings wrote:
>@secs = map { $_->[0] }
> sort {
> $a->[0] <=> $b->[0] ||
> $a->[2] <=> $b->[2]
> }
> map { [ $_, (split /\t/) ] } @secs;
>
>This code will sort the array by the first field ( in this case [0] (or
>actually @secs[x][0]) ) but it will not sort the second field [2].
No, the first field is $a->[1]. You're sorting on the entire string
(which is in array item 0) first -- treated as a number.
--
Bart.
------------------------------
Date: Thu, 20 Sep 2001 09:14:44 +0200
From: Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr>
Subject: Re: select() timeout problem
Message-Id: <3BA99764.8F52D58@sxb.bsf.alcatel.fr>
Philippe PERRIN wrote:
>
> Michel Dalle wrote:
> > FIFO files are weird things - you need to have them open both for reading
> > *and* writing before you can do any input or output from either side (at
> > least according to the glibc docs).
> >
> > When I tried it out on my system, the script 'hung' on the open() until
> > some other process opened the FIFO for writing, and *then* it timed out
> > after the select() - if the other process still hadn't printed anything to the
> > FIFO after 5 seconds...
>
> I'll try with opening for writing, then.
OK, here is what I did :
1) I added an opening line at the beginig of my script :
open(W, "> myFifo") || die("too bad...\n");
in the hope of making it work as you said. it didn't work AND no other
process could use the fifo to write in it.
2) so I removed my open() line (back to the original script), and tried
again but in opening the fifo for writing first (other process : "cat >
myFifo") and THEN all worked fine : my script behaved normally, with
timeout.
This solution didn't please me, so I found another one, thanks to your
remark on the hanging of the open() call. I don't use select any more,
just alarm(). See the solution below.
Thanks for your help. The script works exactly the way I want (no need
to open the FIFO for writing first).
--
PhP
-----= SCRIPT =-----
use strict;
my $timeout = 5;
alarm($timeout);
$SIG{ALRM} = \&alarme;
while(1) {
open(FIFO, "essai") || die("fail : open()\n");
print "OPENING\n";
while(<FIFO>) {
chomp;
print "I read [$_]\n";
exit if $_ eq 'exit';
}
close(FIFO);
print "CLOSING\n";
}
sub alarme
{
print "alarme()\n";
alarm($timeout);
}
------------------------------
Date: Thu, 20 Sep 2001 09:41:02 +0200
From: Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr>
Subject: Re: select() timeout problem
Message-Id: <3BA99D8E.B8CA8E9@sxb.bsf.alcatel.fr>
Martien Verbruggen wrote:
> As Michel Dalle has already explained, you need to open FIFOs for both
> read and write, and you have to use the sysopen and sysread functions
> to deal with them. This is not a Perl specific thing, but it's the
> same for C.
Martien,
thanks for your advice.
since then, I found another solution (see previous post) without using
select(). the "problem" with your solution (which works fine) is that
the fifo needs to be opened for writing before I open it, and that
doesnt match my needs. What I need is to be able to read input from the
fifo, coming from "asynchronous" processes : they shouldn't need to open
the fifo for writing in first.
My other solution (on previous post) uses an open() blocking call woth
an alarm() call. It works fine.
Thanks again for your explanations, I think I now understand how fifos
work :-)
--
PhP
($r1,$r2,$r3,$r4)=("19|20","0|1","28|29","5|24");($r5,$r6)=("9|10|15|16|$r1|$r2","9|10|$r3");%h=("1|",$r6,"1=","[1-5]|2[0-4]","1/","0|19","1\\","6|25","2|","0|6|19|25|$r6","2/","1|20","2\\",$r4,"3|","$r2|6|$r1|25|$r6","3/",$r4,"4|","$r2|$r1|$r6","4=","2|3|4|11|12|13|14|21|22|23","4/",$r4,"4\\",15,"5|","$r2|9|15|$r1|20|$r3","5/",10,"6|",$r5,"7|",$r5,"7/",$r3);for($l=1;$l<8;$l++){b:for($i=0;$i<30;$i++){c:foreach(keys
%h){next c if(!(/^$l(.*)$/));$a=$1;if($i=~/^($h{$_})$/){print $a;next
b;}}print " ";}print "\n";}
------------------------------
Date: 20 Sep 2001 10:05:19 GMT
From: Shan Ali Khan <shanali@singapura.singnet.com.sg>
Subject: setting up time value and converting it to epoch seconds
Message-Id: <9ocf0v$kgr$1@coco.singnet.com.sg>
Hi,
I am trying to setup time value based on day of my choice but month
and year from localtime() and then to convert this value to epoch
second. Apparently in doing so lost my way :) will appreciate your
help. Thanks
--
Shan
------------------------------
Date: Thu, 20 Sep 2001 12:22:17 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: setting up time value and converting it to epoch seconds
Message-Id: <hogjqtgjkjncpe4fad1sfs9huidq3mflg9@4ax.com>
On 20 Sep 2001, Shan Ali Khan <shanali@singapura.singnet.com.sg>
wrote:
>I am trying to setup time value based on day of my choice but month
>and year from localtime() and then to convert this value to epoch
>second. Apparently in doing so lost my way :) will appreciate your
>help. Thanks
How about some code that illustrates your problem?
Have you looked at Time::Local?
curious,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: 20 Sep 2001 12:17:48 GMT
From: news@roaima.demon.co.uk
Subject: Re: setting up time value and converting it to epoch seconds
Message-Id: <3ba9d05c@news.netserv.net>
Shan Ali Khan <shanali@singapura.singnet.com.sg> wrote:
> I am trying to setup time value based on day of my choice but month
> and year from localtime() and then to convert this value to epoch
> second. Apparently in doing so lost my way :) will appreciate your
> help. Thanks
Post a small snippet of code showing what you've tried, and why you
think it doesn't work
Chris
------------------------------
Date: 20 Sep 2001 11:49:01 GMT
From: Shan Ali Khan <shanali@singapura.singnet.com.sg>
Subject: Re: setting up time value and converting it to epoch seconds
Message-Id: <9ocl3d$mfm$1@coco.singnet.com.sg>
news@roaima.demon.co.uk wrote:
> Shan Ali Khan <shanali@singapura.singnet.com.sg> wrote:
>> I am trying to setup time value based on day of my choice but month
>> and year from localtime() and then to convert this value to epoch
>> second. Apparently in doing so lost my way :) will appreciate your
>> help. Thanks
> Post a small snippet of code showing what you've tried, and why you
> think it doesn't work
> Chris
well..
# -*- mode: Perl -*-
# SessionTimeout
#
use Time::Local;
sub
{
my $p = ${$_[0]}; # request packet
my $rp = ${$_[1]}; # reply packet to NAS
my $result = ${$_[2]}; # handled flag
my $endofmonth; # time at around midnight of the last day of the month
my $current = time; # localtime since 1st Jan, 1970
($sec, $min, $hour, $mday, $mon, $year) = (localtime)[0,1,2,3,4,5]; # calculation of localtime
$endofmonth = timegm(0, 50, 23, 30, $month, $year); # calculation of time till end of month
if ($mday = '30' && ($endofmonth - $current) <= '86400') {
$sessiontimeout = $endofmonth - $current;
$rp->delete_attr('Session-Timeout');
$rp->add_attr('Session-Timeout', $sessiontimeout);
&main::log($main::LOG_INFO, "Session-Timeout = $sessiontimeout replied in Radius Packet");
}
return;
}
I hope it will make some sort of sense. I am not good at perl at all.
--
Shan
------------------------------
Date: 20 Sep 2001 09:49:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: split SuchKindOfWord into individual words
Message-Id: <9oce3r$9ng$1@mamenchi.zrz.TU-Berlin.DE>
According to Joe Schaefer <joe+usenet@sunstarsys.com>:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>
> > According to Michael Budash <mbudash@sonic.net>:
> > >
> > > based strictly on your example, here's one way:
> > >
> > > push @words, $1 while /([A-Z][^A-Z]+)/g;
> > ^ ^ ^
> > Besides the obvious typo,
>
> Typo? What's wrong with using [^A-Z] instead of [a-z] ?
Nothing, after re-reading the original post and realizing it doesn't
specify lower case letters. I don't have to point out the difference...
> > you may want "*" instead of "+" (ACatAndADog). Shorter and perhaps
> > faster:
> >
> > @words = /([A-Z][a-z]*)/g;
> ^ ^
>
> Useless use of parens ... :)
Technically true. However, when collecting matches in list context
like above I'd recommend to always use capturing parentheses to mark
the parts that are going to be collected.
Anno
------------------------------
Date: 20 Sep 2001 04:34:33 -0700
From: jvaughan@qinetiq.com (James Vaughan)
Subject: Win32::ODBC
Message-Id: <9d271e8e.0109200334.741cc6df@posting.google.com>
I'm coding a script to connect to multiple Microsoft SQL 7 servers and
run some simple SQL queries. My question being a newcomer to
Win32::ODBC is how do I specify the server I want to connect to?
I assume that where I'm setting the $dsn variable I need to add
another section which relates to the server I am connecting to. I've
been through the Win32::ODBC documentation that ships with ActiveState
Perl but can't seem to find any reference to setting the server IP
address, or other DSN attributes.
any help/references/faq's/links gratefully recieved
kind regards
James Vaughan
~~~~~~~~~~~~~~~~~~~~~~
My code is as follows:
#Load modules
use Win32::ODBC;
#Set variables
$dsn = "DSN=testdsn;UID=sa;PWD=;";
if (!($data_connection = new Win32::ODBC($dsn)))
{
print "Error connecting to $DSN\n";
print "Error: " . Win32::ODBC::Error() . "\n";
exit;
}
$data_connection->Close();
------------------------------
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:
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.
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 1780
***************************************