[25703] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7944 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 5 06:05:20 2005

Date: Tue, 5 Apr 2005 03:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 5 Apr 2005     Volume: 10 Number: 7944

Today's topics:
    Re: Help with a script.. <felix.geerinckx@gmail.com>
    Re: Help with a script.. <joe@inwap.com>
    Re: Help with a script.. <do-not-use@invalid.net>
    Re: how to get installed program path under Windows lik <joe@inwap.com>
    Re: LWP Doesn't Seem To Save Cookies: <joe@inwap.com>
    Re: perl update - what about the modules? <joe@inwap.com>
    Re: recursivity <joe@inwap.com>
    Re: Regular expression question. <noreply@gunnar.cc>
    Re: Regular expression question. axel@white-eagle.invalid.uk
    Re: Shell Commands (Getting PID and Timing Them) <hal@thresholddigital.com>
    Re: Shell Commands (Getting PID and Timing Them) <hal@thresholddigital.com>
    Re: Shell Commands (Getting PID and Timing Them) axel@white-eagle.invalid.uk
    Re: time zone offset calc with localtime and gmtime <joe@inwap.com>
    Re: time zone offset calc with localtime and gmtime <joe@inwap.com>
    Re: time zone offset calc with localtime and gmtime <leendert@wouter.unitedknowledge.net>
    Re: Using a for() statement to create a variable?? <joe@inwap.com>
    Re: Using a for() statement to create a variable?? <joe@inwap.com>
    Re: Why doesn't Perl have cp or mv? <joe@inwap.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 05 Apr 2005 07:36:58 GMT
From: "Felix Geerinckx" <felix.geerinckx@gmail.com>
Subject: Re: Help with a script..
Message-Id: <xn0e0mxv425phh000@news.easynews.com>

On 05/04/2005, Abigail wrote:

> Felix Geerinckx (felix.geerinckx@gmail.com) wrote on MMMMCCXXXIV
> September MCMXCIII in <url: news:xn0e0lj3e1r1u3000@news.easynews.com>:
> ~~      $shortyear = '04';
> ~~  
> ~~  could mean any of 
> ~~  
> ~~      $longyear = '1904'; 
> ~~      $longyear = '2004'; 
> ~~      $longyear = '2104';
> ~~  
> ~~  etc.
> 
> Not in this case. The OP defined '04' to be 2004. Given that it's a
> timestamp, 2104 isn't logical, as it's only 2005, and neither is 1904.
> There was a shortage of computers in 1904.

You are right, of course, but isn't it about making one's programs
future proof?

And speaking of dates, would you care to share why you stopped using
the standard calendar in Sept 1993?

-- 
felix


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

Date: Tue, 05 Apr 2005 01:29:56 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Help with a script..
Message-Id: <a6ydnQK7OcUb0c_fRVn-gA@comcast.com>

Gunnar Hjalmarsson wrote:
> When converting two-digit years to four-digit 
> ditto you *always* need to know in which century you are, don't you?

In one interpretation, you need to know the current century and
the other century that is within plus-or-minus 50 years from now.

   31-Dec-99 = 1999 for 1949 through 2048.
   31-Dec-99 = 2099 for 2049 through 2148.
    1-Jan-70 = 1970 for 1920 through 2019.
    1-Jan-70 = 2070 for 2020 through 2119.

Rules like the above are definitely application dependent.
	-Joe


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

Date: 05 Apr 2005 10:37:19 +0200
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Help with a script..
Message-Id: <yzdvf71pqkg.fsf@invalid.net>


"Felix Geerinckx" <felix.geerinckx@gmail.com> writes:
> On 05/04/2005, Abigail wrote:
> 
> > Felix Geerinckx (felix.geerinckx@gmail.com) wrote on MMMMCCXXXIV
> > September MCMXCIII in <url: news:xn0e0lj3e1r1u3000@news.easynews.com>:
> > ~~      $shortyear = '04';
> > ~~  
> > ~~  could mean any of 
> > ~~  
> > ~~      $longyear = '1904'; 
> > ~~      $longyear = '2004'; 
> > ~~      $longyear = '2104';
> > ~~  
> > ~~  etc.
> > 
> > Not in this case. The OP defined '04' to be 2004. Given that it's a
> > timestamp, 2104 isn't logical, as it's only 2005, and neither is 1904.
> > There was a shortage of computers in 1904.
> 
> You are right, of course, but isn't it about making one's programs
> future proof?
> 
> And speaking of dates, would you care to share why you stopped using
> the standard calendar in Sept 1993?

"The September that never ended." Look it up with Google.


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

Date: Tue, 05 Apr 2005 02:11:27 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: how to get installed program path under Windows like Win32 API?
Message-Id: <D_mdnaLTnd_cy8_fRVn-pA@comcast.com>

Lance wrote:
> The installed program I mean here is but other
> installed programs, such notepad.exe, msword.exe, photoshop.exe etc.

Programs that are started by clicking on an icon can be in any
directory.  Icons that are shortcuts often have the full path
of the application stored as a property.  To get that info,
you may have to track down and locate all possible icons and/or
parse the Registry.
	-Joe


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

Date: Tue, 05 Apr 2005 03:00:05 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: LWP Doesn't Seem To Save Cookies:
Message-Id: <hqudnbP36M80_M_fRVn-qA@comcast.com>

Hal Vaughan wrote:

> At this point, I think it's a bigger problem and I could use some
> clarification from anyone

Last time I had a problem like this, I told my browser to use an
http proxy, and had the proxy log what was actually being sent to
the server.  I used http://www.inwap.com/mybin/miscunix/?tcp-proxy
to do the logging when my proxy did not log everything I needed.
	-Joe

P.S. I noticed that cookies are mentioned in 
http://search.cpan.org/~petdance/WWW-Mechanize-1.12/lib/WWW/Mechanize.pm


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

Date: Tue, 05 Apr 2005 01:56:39 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: perl update - what about the modules?
Message-Id: <bd-dnSHEW5xUz8_fRVn-hw@comcast.com>

Ted Zlatanov wrote:

> The CPAN module can generate a snapshot bundle, which will make
> reinstalling everything from CPAN easier.  From "perldoc CPAN":

Yep, the last time I used this:

perl -MCPAN -e 'autobundle'
cd src/perl; ./configure && make && make test && make install; cd
perl -MCPAN -e 'install '`ls -t .cpan/Bundle/Snapshot* | sed -n '1 
s%.cpan/Bundle/%bundle::%p'`

(That last line resolves to 'install bundle::Snapshot_yyyy_mm_dd_00.pm')
	-Joe


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

Date: Tue, 05 Apr 2005 00:20:42 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: recursivity
Message-Id: <r_GdnaBfI6_Soc_fRVn-iw@comcast.com>

julia wrote:

>    opendir DIR, $dir || die "Couldnt open $dir - $!\n";
>    my @entries = readdir(DIR);
>    closedir (DIR);
> 
>     foreach my $file (@entries) {

   use File::Find;
   find(\&wanted,@ARGV);
   exit;

   sub wanted {
      print "Processing file '$_' in directory $File::Find::dir\n";
      # Use $_ or $File::Find::name when opening the input file.
   }

	-Joe


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

Date: Tue, 05 Apr 2005 09:43:21 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Regular expression question.
Message-Id: <3beu3mF6e4ig1U1@individual.net>

MENTAT wrote:
> I have a log file that looks something like this
> 
> 2005-03-29 17:17:11.293|DEBUG|Line 1|
> >>>>>>>
> Actual Log output line 1
> Actual Log output line 2
> Actual Log output line 3
> Actual Log output line ...
> <<<<<<<
> 2005-03-29 17:17:11.293|DEBUG|Line 9|
> >>>>>>>
> Actual Log output line 1
> Actual Log output line 2
> Actual Log output line 3
> Actual Log output line ...
> <<<<<<<
> 
> I am trying to write a regular expression that extracts all the log
> entries for a given value of "Line".

Set the input record separator:

     my $line = 4;
     local $/ = "<<<\n";
     /\|Line $line\|/ and print while <LOG>;

See "perldoc perlvar".

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Tue, 05 Apr 2005 03:00:03 -0500
From: axel@white-eagle.invalid.uk
Subject: Re: Regular expression question.
Message-Id: <44SdnTozqZge2M_fRVn-sw@adelphia.com>

MENTAT <chaitanyag@hotmail.com> wrote:
> I have a log file that looks something like this
> 
> 2005-03-29 17:17:11.293|DEBUG|Line 1|
>>>>>>>>
> Actual Log output line 1
> Actual Log output line 2
> Actual Log output line 3
> Actual Log output line ...
> <<<<<<<
> 2005-03-29 17:17:11.293|DEBUG|Line 9|

[...]

> So if I wanted to look at the entries for Line 4 I want the output to
> look something like
 
> 2005-03-29 17:17:11.309|INFO|Line 4|
>>>>>>>>
> Actual Log output line 1
> Actual Log output line 2
> Actual Log output line 3
> Actual Log output line ...
> <<<<<<<
 
> Note that I want everything in the line before the "Line 4" text as
> well, such as time.
 
> I tried using "<<<<<<<(.*?\|Line 4.*?)>>>>>>>(.*?)<<<<<<<" as the
> regular expression (with the ms global modifiers), but the problem is
> it matches everything from the beginning of the file (basically the
> first <<<<<<<) to the "Line 4". Making .* non-greedy doesn't help
> because after it finds the first <<<<<<< the non-greedy match goes all
> the way upto the first "Line 4".
 
> Replacing <<<<<<< with the beginning of line (^) doesn't make any
> difference either because after the start of the first line, the .*?
> still matches everything until "Line 4".

You could instead of using .*? specify exactly where a line end may
occur... along the lines of:

	'<<<<<<<\n([\w |.:-]*?\|Line 4.*?)>>>>>>>(.*?)<<<<<<<'

Although from the sample data that you have provided, this would not
work if the data sought is at the begining of the file. So perhaps:

	'^([\w |.:-]*?\|Line 1.*?)>>>>>>>(.*?)<<<<<<<'

would be better. Of course you would have to check that the [\w |.:-]
part covers exverything that will occur on that line and that there will
not be clashed with the 'Actual Log output' lines.

Axel



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

Date: Tue, 05 Apr 2005 03:14:02 -0400
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Re: Shell Commands (Getting PID and Timing Them)
Message-Id: <kvednerv_Mklp8_fRVn-2w@comcast.com>

Joe Smith wrote:

> Hal Vaughan wrote:
>> In Perl I know how to fork and get a PID, and I know how to use
>> `command` to get a commands output, but I can't find a way to run a
>> command from Perl and get the PID so I can kill it when I want.
> 
>    my $child_pid = fork();
>    die unless defined $child_pid;
>    if ($child_pid) {  # Parent
>       sleep $sleep_time;
>       kill 2,$child_pid;
>    } else {   # Child
>       exec "command </dev/null >/dev/null 2>&1";
>       die "Could not run 'command'";
>    }
> -Joe

Thanks, but that gives me the PID of the forked process.  I want to run a
BASH command from Perl, and get the PID of the BASH command.  The child_pid
is not the same as the bash command.

Hal


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

Date: Tue, 05 Apr 2005 03:17:13 -0400
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Re: Shell Commands (Getting PID and Timing Them)
Message-Id: <kvedneXv_Mnrps_fRVn-2w@comcast.com>

axel@white-eagle.invalid.uk wrote:

> Hal Vaughan <hal@thresholddigital.com> wrote:
>> I want to run a shell command to record sound, and kill it after x
>> seconds. If I were writing a Bash script, I'd run the command in the
>> background, get the PID, use a sleep statement, then kill the first
>> command after the sleep
>> statement.  In Perl I know how to fork and get a PID, and I know how to
>> use `command` to get a commands output, but I can't find a way to run a
>> command from Perl and get the PID so I can kill it when I want.
>  
>> Is there a way to get the PID?  (I'd rather not use a 2nd script in bash
>> to do it.)
> 
>> If there's another way to execute a shell command from Perl, then after x
>> seconds kill it, I'm open to it.
> 
> Something like...
> 
> my $pid = open (PIPE, "-|") || exec("/what/ever");
> 
> # Read from PIPE, have a cup of coffee, sleep
> 
> my $kesult = kill 9, $pid;
> 
> Axel

I could use a bit of help understanding this.  When the pipe is opened, and
with the "||", it will exec the program, but still continue with the rest
of the Perl program, with the pipe still open?  (I'm just trying to make
sure I see what's going on here.)

Hal


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

Date: Tue, 05 Apr 2005 04:12:13 -0500
From: axel@white-eagle.invalid.uk
Subject: Re: Shell Commands (Getting PID and Timing Them)
Message-Id: <npmdnRc0ut3wy8_fRVn-1w@adelphia.com>

Hal Vaughan <hal@thresholddigital.com> wrote:
> axel@white-eagle.invalid.uk wrote:
 
>>> Is there a way to get the PID?  (I'd rather not use a 2nd script in bash
>>> to do it.)

>>> If there's another way to execute a shell command from Perl, then after x
>>> seconds kill it, I'm open to it.

>> Something like...
>> 
>> my $pid = open (PIPE, "-|") || exec("/what/ever");
>> 
>> # Read from PIPE, have a cup of coffee, sleep
>> 
>> my $kesult = kill 9, $pid;

> I could use a bit of help understanding this.  When the pipe is opened, and
> with the "||", it will exec the program, but still continue with the rest
> of the Perl program, with the pipe still open?  (I'm just trying to make
> sure I see what's going on here.)
 
Yes. The pipe would be open for reading in this case. A simple
example...  assuming we have the shell script hello.sh:

    #!/bin/sh
    echo Hello from a shell script

and the Perl script:

    #!/usr/bin/perl

    use warnings;
    use strict;

    my $pid = open (PIPE, "-|") || exec("./hello.sh");
    while (<PIPE>) {
	print "Received: ", $_;
    }
    close (PIPE);
    __END__

The Perl script will fork a child which exec's hello.sh and then reads
the output from the childs which will be:

	Received: Hello from a shell script

and the closes the PIPE and kills the child (although the child should
be dead by this time). Of course you may well want to do checks on the
status returned by the close statement to see if there was an abnormal
termination.

Axel



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

Date: Tue, 05 Apr 2005 00:35:32 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: time zone offset calc with localtime and gmtime
Message-Id: <VJ6dnf4tWqlZos_fRVn-1Q@comcast.com>

Leendert Bottelberghs wrote:

> - I use this in a module that will be used in mod_perl. I want to keep the
> number of loaded modules as concise as possible, because of the server
> memory overhead; - I want to be able to distribute this module without
> people having to install other modules;

Well, is it safe to use the modules that come bundled with perl, so
you might as well use them.
	-Joe


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

Date: Tue, 05 Apr 2005 00:46:45 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: time zone offset calc with localtime and gmtime
Message-Id: <W6SdnSzrPPv638_fRVn-3A@comcast.com>

Leendert Bottelberghs wrote:

> I want to calculate the time zone offset (as an integer)

The international standard for time zone offset is a five-character
string.  A plus or minus sign, two digits for hours, two digits for
minutes.

                Date: Mon, 04 Apr 2005 17:07:04 +0200
   NNTP-Posting-Date: Mon,  4 Apr 2005 15:06:45 +0000 (UTC)
     US-Pacific-Date: Mon, 04 Apr 2005 08:06:45 -0800 (PDT)

The last two digits are not always "00".

grep ' [-+][0-9][0-9][1-9]' /usr/lib/perl5/site_perl/5.8.3/Date/Manip.pm
       #"nst   -0330 ".  # Newfoundland Standard  nst=North Sumatra +0630
       "nft    -0330 ".  # Newfoundland
       "ndt    -0230 ".  # Newfoundland Daylight
       "it     +0330 ".  # Iran
       "ist    +0530 ".  # Indian Standard
       "nst    +0630 ".  # North Sumatra       nst=Newfoundland Std -0330
       "acst   +0930 ".  # Australian Central Standard
       "cast   +0930 ".  # Central Australian Standard
       "acdt   +1030 ".  # Australian Central Daylight
       "cadt   +1030 ".  # Central Australian Daylight

	  -Joe


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

Date: Tue, 05 Apr 2005 11:31:53 +0200
From: "Leendert Bottelberghs" <leendert@wouter.unitedknowledge.net>
Subject: Re: time zone offset calc with localtime and gmtime
Message-Id: <pan.2005.04.05.09.31.52.966909@wouter.unitedknowledge.net>

On Tue, 05 Apr 2005 00:35:32 -0700, Joe Smith wrote:
> Leendert Bottelberghs wrote:
> 
>> - I use this in a module that will be used in mod_perl. I want to keep the
>> number of loaded modules as concise as possible, because of the server
>> memory overhead; - I want to be able to distribute this module without
>> people having to install other modules;
> 
> Well, is it safe to use the modules that come bundled with perl, so
> you might as well use them.

You're absolutely right. Which standard module would you recommend?

-leendert


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

Date: Tue, 05 Apr 2005 02:28:53 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Using a for() statement to create a variable??
Message-Id: <vpKdnezlLJjKx8_fRVn-hQ@comcast.com>

Brian McCauley wrote:
> 
> 
> A. Sinan Unur wrote:
> 
> [ of "robic0@yahoo.com" ]
> 
>> Your ignorance is amusing. 
> 
> 
> No, I think it has long ceased to be.  robic0 is now rapidly[1] 
> decomming the heir apparent to the thrown of she whose name we shall not 
> utter.
> 
> [1] Fredian slip - I initially typed "rabidly".

I like the other Freudian slip: 'thrown', as in "I have thrown up
into the throne" (a nickname for the large white porcelain seat).

	-Joe


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

Date: Tue, 05 Apr 2005 02:29:49 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Using a for() statement to create a variable??
Message-Id: <vpKdne_lLJgTx8_fRVn-hQ@comcast.com>

robic0@yahoo.com wrote:
>>Just FYI: UseNet is not America.
>>Sinan.
> 
> Al Gore -> *****U S A*****  --->>>>>  ArpaNnet --> UseNet --> <you,
> the foreigner who taketh away American jobs>

As an American, I find name-calling like that to be insulting.
	-Joe


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

Date: Tue, 05 Apr 2005 02:22:42 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Why doesn't Perl have cp or mv?
Message-Id: <hfqdncwXP9p0xc_fRVn-sg@comcast.com>

Bart Lateur wrote:

> On a similar note, I've always wondered  why Perl had no curdir, or cwd.

Because that is not a standard system-call or standard C library
function.  (Most unix-like systems only keep track of the current
directory's inode, not its name.  And the name may have changed
in the interim.)

> Cwd() exists to solve that problem, but the question still remains.

Have you seen how much code it takes for Cwd() to come up with
that answer?  It's not something you want to do everytime perl
starts up.
	-Joe


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 7944
***************************************


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