[30385] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1628 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 10 11:09:51 2008

Date: Tue, 10 Jun 2008 08:09:15 -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, 10 Jun 2008     Volume: 11 Number: 1628

Today's topics:
    Re: discover invisible characters <bugbear@trim_papermule.co.uk_trim>
    Re: discover invisible characters <ela@yantai.org>
    Re: Moving from delimited to XML <ben@morrow.me.uk>
        output of a command in an variable <natxete@asenjo.nl.invalid>
    Re: output of a command in an variable <jacobcdf@yahoo.com>
    Re: output of a command in an variable <tadmc@seesig.invalid>
        Question on learning Perl <cdalten@gmail.com>
    Re: Question on learning Perl <willem@stack.nl>
    Re: Question on learning Perl <devnull4711@web.de>
    Re: Question on learning Perl (Randal L. Schwartz)
    Re: Question on learning Perl <cwilbur@chromatico.net>
    Re: Question on learning Perl <RedGrittyBrick@SpamWeary.foo>
    Re: Question on learning Perl <1usa@llenroc.ude.invalid>
    Re: Question on learning Perl <cartercc@gmail.com>
        Time and again <markdibley@gmail.com>
    Re: Time and again <jacobcdf@yahoo.com>
    Re: Time and again <jacobcdf@yahoo.com>
    Re: Time and again <jurgenex@hotmail.com>
    Re: Time and again <bugbear@trim_papermule.co.uk_trim>
    Re: Time and again <markdibley@gmail.com>
    Re: Time and again <markdibley@gmail.com>
    Re: Time and again <RedGrittyBrick@SpamWeary.foo>
    Re: Tk with Thread <zentara@highstream.net>
    Re: Tk with Thread <zentara@highstream.net>
    Re: Tk with Thread <ben@morrow.me.uk>
    Re: Trying to catch invalid emails <szrRE@szromanMO.comVE>
    Re: Trying to catch invalid emails <danrumney@warpmail.net>
        Using IPC::Open2 on Windows for mission critical app <jacobcdf@yahoo.com>
    Re: Using IPC::Open2 on Windows for mission critical ap <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 10 Jun 2008 10:29:42 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: discover invisible characters
Message-Id: <SvSdnc9sVZ4b1NPVnZ2dnUVZ8vmdnZ2d@posted.plusnet>

Ela wrote:
> I've tried to identify the invisible characters leading to unsuccessful 
> pattern matching. However the screen prints out nothing special like this:
> 
> ORF: AAAAMT0002
> pattern COG3i start: AAAAMT0002
> 
> What should I do to find out the problem? Thanks a lot.

feed you output to something like a hexdump, or cat -ev

There are no invisible characers in a hexdump...

   BugBear


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

Date: Tue, 10 Jun 2008 21:41:30 -0700
From: "Ela" <ela@yantai.org>
Subject: Re: discover invisible characters
Message-Id: <g2m0a0$hb6$2@ijustice.itsc.cuhk.edu.hk>


"Ben Bullock" <benkasminbullock@gmail.com> wrote in message
news:g2l7qq$hbm$1@ml.accsnet.ne.jp...
> Ela <ela@yantai.org> wrote:
>> I've tried to identify the invisible characters leading to unsuccessful
>> pattern matching. However the screen prints out nothing special like
>> this:
>>
>> ORF: AAAAMT0002
>> pattern COG3i start: AAAAMT0002
>>
>> What should I do to find out the problem? Thanks a lot.
>
> The problem is probably a space character at the end of the string. If
> you change the print statement you might see it.
>
>>                $pattern2 = $aref2->[$cog3i];
>>                $pattern2 =~ s/[\t\n^M]//g;
>
> $pattern2 =~ s/\s+//g;
>
>>                $pattern1 = $aref1->[$orfi];
>>                $pattern1 =~ s/[\t\n^M]//g;
>
> $pattern1 =~ s/\s+//g;
>

It's really weird.... I used vim to replace and it reported that replacement
did succeed...
Anyway, thanks a lot!!! It's most frustrated when you cannot see any
characters but the pattern matching keeps failing. Any editor works better
than vim in this case?







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

Date: Tue, 10 Jun 2008 04:49:02 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Moving from delimited to XML
Message-Id: <e6a1i5-b9e.ln1@osiris.mauzo.dyndns.org>


Quoth Bill H <bill@ts1000.us>:
> 
> Recently I have started using XML in other areas and realize that this
> format would be more easily maintained then the text files. So the
> question of the day, can someone point me to some simple XML
> implementation in perl that wont take days to learn and includes some
> commentary on how it works that is geared more to the layman?

While XML is a decent format for many things, particularly because it is
so widely supported, for storing Perlish data structures in a text file
YAML may be a better fit. In particular YAML::Tiny makes a good
serialization format.

Ben

-- 
The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching.
       Assyrian stone tablet, c.2800 BC                        ben@morrow.me.uk


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

Date: 10 Jun 2008 10:07:53 GMT
From: Natxo Asenjo <natxete@asenjo.nl.invalid>
Subject: output of a command in an variable
Message-Id: <484e5279$0$14361$e4fe514c@news.xs4all.nl>

hi,

This should be easy but I do not seem to get right. I want to monitor
the health of a raid controller with nagios. No plugin for it, so I'm
writing my own.

The tool is arcconf.exe and I this is what i have so far (it works, but
the output is not nice enough):

==========begin snippet============================
#!/usr/bin/perl

use warnings;
use strict;

=pod
this script executes "c:\program files\adaptec\adaptec storage
manager\arcconf.exe" 
=cut

# here is the program
my $adaptec_installdir = "c:/program files/adaptec/adaptec storage
manager";

# we go to this dir
chdir $adaptec_installdir or die "$!\n" ;

# we execute the program, output is kept in variable $arcconf
my $arcconf = `arcconf\.exe getconfig 1 ad`;


open(OUTPUT, $arcconf) or die "Can't run $arcconf: $!\n" ;
while (<OUTPUT>) {
    print $_ ."\n" ;
}

====================end snippet===========================

and this is the output:

Unsuccessful open on filename containing newline at D:\Program
Files\NSClient++-
Win32-0.3.1\scripts\check_adaptec_raid.pl line 28.
Can't run Controllers found: 1

----------------------------------------------------------------------
Controller information
----------------------------------------------------------------------
   Controller Status                   : OK
   Channel description                 : SCSI
   Controller Model                    : 2120S
   Controller Serial Number            : c65a68
   BIOS Version                        : 4.2-0 (8208)
   Firmware Version                    : 4.2-0 (8208)
   Driver Version                      : 4.2-1 (7372)
   Physical Slot                       : 4
   Copyback enabled                    : No
   Background consistency check enabled: No
   Defunct disk drive count            : 0
   Logical devices/Failed/Degraded     : 1/0/0


Command completed successfully.
: No such file or directory

if I run the command on cmd.exe this is the output:

C:\Program Files\Adaptec\Adaptec Storage Manager>arcconf.exe getconfig 1
ad
Controllers found: 1

----------------------------------------------------------------------
Controller information
----------------------------------------------------------------------
   Controller Status                   : OK
   Channel description                 : SCSI
   Controller Model                    : 2120S
   Controller Serial Number            : c65a68
   BIOS Version                        : 4.2-0 (8208)
   Firmware Version                    : 4.2-0 (8208)
   Driver Version                      : 4.2-1 (7372)
   Physical Slot                       : 4
   Copyback enabled                    : No
   Background consistency check enabled: No
   Defunct disk drive count            : 0
   Logical devices/Failed/Degraded     : 1/0/0


Command completed successfully.

Why am I getting the 'Unsuccessful ..." warnings? How can I get rid of
them?

-- 
Groeten,
J.I.Asenjo


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

Date: Tue, 10 Jun 2008 03:53:24 -0700 (PDT)
From: Jacob JKW <jacobcdf@yahoo.com>
Subject: Re: output of a command in an variable
Message-Id: <af857075-d2a4-4e88-ae0e-9694f7f14d81@34g2000hsh.googlegroups.com>

On Jun 10, 6:07 am, Natxo Asenjo <natx...@asenjo.nl.invalid> wrote:
> ==========begin snippet============================
> # we execute the program, output is kept in variable $arcconf
> my $arcconf = `arcconf\.exe getconfig 1 ad`;
>
> open(OUTPUT, $arcconf) or die "Can't run $arcconf: $!\n" ;
> while (<OUTPUT>) {
>     print $_ ."\n" ;
>
> }
> ==========end snippet============================
> Why am I getting the 'Unsuccessful ..." warnings? How can I get rid of
> them?

Replace the open() command and while loop with:

    print $arcconf;

Or alternatively, replace the backticks in the declaration of the
$arcconf variable with double quotes (or with single quotes after
removing the backslash):

    my $arcconf = 'arcconf.exe getconfig 1 ad';



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

Date: Tue, 10 Jun 2008 06:56:38 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: output of a command in an variable
Message-Id: <slrng4sqvm.sua.tadmc@tadmc30.sbcglobal.net>

Natxo Asenjo <natxete@asenjo.nl.invalid> wrote:


> my $arcconf = `arcconf\.exe getconfig 1 ad`;


At this point you have the output from the command stored in $arcconf.

(the backslash is not needed there...)


> open(OUTPUT, $arcconf) or die "Can't run $arcconf: $!\n" ;
> while (<OUTPUT>) {
>     print $_ ."\n" ;
> }


If you want to print the output of the command, then

   print $arcconf;


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Tue, 10 Jun 2008 05:45:09 -0700 (PDT)
From: grocery_stocker <cdalten@gmail.com>
Subject: Question on learning Perl
Message-Id: <9caecf98-85bf-477c-966e-b9f883313dcb@e39g2000hsf.googlegroups.com>

I asked this in another forum and never got a response. Maybe the
question was worded poorly.

Anyhow, when you learned Perl, did you memorize most of the functions?
Ie memorize what they do and the arguments that they take? Or did you
just memorize the ones that you felt were relevant to you job? Is
there some kind of trick to memorizing the functions?


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

Date: Tue, 10 Jun 2008 12:56:09 +0000 (UTC)
From: Willem <willem@stack.nl>
Subject: Re: Question on learning Perl
Message-Id: <slrng4suf9.98a.willem@snail.stack.nl>

grocery_stocker wrote:
) Anyhow, when you learned Perl, did you memorize most of the functions?

No.

) Ie memorize what they do and the arguments that they take?

No.

) Or did you just memorize the ones that you felt were relevant to you job?

No.

) Is there some kind of trick to memorizing the functions?

Yes.  Don't do it.  It's a waste of time.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


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

Date: Tue, 10 Jun 2008 15:02:03 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: Question on learning Perl
Message-Id: <6b7cbgF3af9ulU2@mid.individual.net>

grocery_stocker wrote:
> I asked this in another forum and never got a response. Maybe the
> question was worded poorly.
> 
> Anyhow, when you learned Perl, did you memorize most of the functions?
> Ie memorize what they do and the arguments that they take? Or did you
> just memorize the ones that you felt were relevant to you job? Is
> there some kind of trick to memorizing the functions?

I use the following litte book which I always have on my desktop:

"Perl Pocket Reference", O'Reilly, Johan Vromans, $9.95

Frank
-- 
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


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

Date: Tue, 10 Jun 2008 06:18:48 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: grocery_stocker <cdalten@gmail.com>
Subject: Re: Question on learning Perl
Message-Id: <86k5gx1l8n.fsf@blue.stonehenge.com>

>>>>> "grocery" == grocery stocker <cdalten@gmail.com> writes:

grocery> Anyhow, when you learned Perl, did you memorize most of the functions?

Larry Wall has admitted that from time to time, he still looks at the manpage.
Why should you try to have a bigger brain than Larry? :)

print "Just another Perl hacker,"; # the original

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


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

Date: Tue, 10 Jun 2008 09:38:49 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Question on learning Perl
Message-Id: <86skvlcsuu.fsf@mithril.chromatico.net>

>>>>> "gs" == grocery stocker <cdalten@gmail.com> writes:

    gs> Anyhow, when you learned Perl, did you memorize most of the
    gs> functions?  Ie memorize what they do and the arguments that they
    gs> take? Or did you just memorize the ones that you felt were
    gs> relevant to you job? Is there some kind of trick to memorizing
    gs> the functions?

I didn't set out to memorize anything.  When I needed to do something, I
looked through the FAQ and perldoc perlfunc to see what might help me do
it.  After a couple months, I stopped needing to look things up very
often; I still look through perldoc perlfunc from time to time, and I
read the FAQs as they're posted here.

Charlton


-- 
Charlton Wilbur
cwilbur@chromatico.net


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

Date: Tue, 10 Jun 2008 15:05:29 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Question on learning Perl
Message-Id: <484e8a2b$0$2494$da0feed9@news.zen.co.uk>

grocery_stocker wrote:
> I asked this in another forum and never got a response. Maybe the
> question was worded poorly.
> 
> Anyhow, when you learned Perl, did you memorize most of the functions?
> Ie memorize what they do and the arguments that they take? Or did you
> just memorize the ones that you felt were relevant to you job? Is
> there some kind of trick to memorizing the functions?


When I was initially learning Perl, I didn't consciously try to memorize 
functions. To the extent that occurred, it was merely an unavoidable 
side-effect of writing programs.

perldoc -q and -f are your friend (tm).

What I do nowadays is add any discovered unobvious gems to a text file. 
The act of writing a note helps me to memorize things. After much time 
has passed you can delete from the file any notes that now seem obvious. 
I use Grutatxt to make HTML pages out of such notes.

-- 
RGB

"Never memorize what you can look up in books."
  - Albert Einstein.


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

Date: Tue, 10 Jun 2008 14:12:25 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Question on learning Perl
Message-Id: <Xns9AB967D3CC3F4asu1cornelledu@127.0.0.1>

grocery_stocker <cdalten@gmail.com> wrote in news:9caecf98-85bf-477c-
966e-b9f883313dcb@e39g2000hsf.googlegroups.com:

> Anyhow, when you learned Perl, did you memorize most of the functions?

No.

I used perldoc perlfunc to get a list of functions by category. Then 
looked up the ones that seemed relevant.

Of course, before doing that, I had first read the full FAQ list (even 
though I did not know any Perl at the time).

> Ie memorize what they do and the arguments that they take?

Never. I still look up

perldoc -f function

* a lot *.

> Or did you just memorize the ones that you felt were 
> relevant to you job?

You mean, like, using flash cards or something. Nope. Never. I have 
never memorized anything consciously in my life. Some things just become 
part of your the current working set in your brain without having to 
exert any other effort than using them.

Then they get moved to long term storage (for example, my Danish 
vocabulary has shrunk a lot over the last decade).

> Is there some kind of trick to memorizing the functions?

Using them???

Sinan



-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: Tue, 10 Jun 2008 07:20:20 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: Question on learning Perl
Message-Id: <a0473e73-9b55-449a-adbb-595be89bf120@x41g2000hsb.googlegroups.com>

On Jun 10, 8:45 am, grocery_stocker <cdal...@gmail.com>
> Anyhow, when you learned Perl, did you memorize most of the functions?

Using a language is a technical skill, and the only way to learn it is
to use it. You can't learn to cook by reading a cookbook, by watching
someone cook, by listening to people talk about cooking, or by eating
the results of the cooking. You only learn to cook by actually
cooking, although everything else helps.

Likewise, you can't learn to program by reading a book, by listening
to people talk about it, or by watching people do it. The only way to
learn how to program is by doing it.

Example: I had a period of time where I had write a series of scripts
which required conversiion of a date from '06/09/08' to '09-JUN-2008'.
Doing this required using several functions, including split, joint,
sprintf, array splicing, and hash slicing. The first time, it took a
couple of hours to do. After several months, writing perhaps two dozen
scripts for this, I could do it in my sleep.

One other comment: Cut and paste is the enemy of learning. The saving
of time by cutting and pasting is illusory. Yes, you save some time
doing it, but the only thing you learn is how to cut and paste. A ball
player or a musician spends hours in a batting cage or in the practice
studio, hitting pitches or playing scales. Okay, it's tedious and
boring, but there is no other way. You can't do it once -- you have to
do it over and over until you learn it. Instead of cutting and pasting
code, write it from scratch each time. (I'm not talking about
modularization, but about learning how to program. If you have a lot
of common code, put it in a module and call it from there. But even
then, writing and using modules takes the same kind of practice. You
can't read about writing a module and expect to be an instant expert.)

CC


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

Date: Tue, 10 Jun 2008 04:02:45 -0700 (PDT)
From: markdibley <markdibley@gmail.com>
Subject: Time and again
Message-Id: <b7e750c0-2572-4128-8f5d-3697012ca4e4@d1g2000hsg.googlegroups.com>

Hello

I keep searching and searching and can never find the function I am
looking for.

print scalar localtime();
gives
Tue Jun 10 11:28:55 2008

I write that to a file and later I read it in and want to convert it
into a timestamp that I can sort on.

Is there anything I can use that does the following

print xxxxx("Tue Jun 10 11:28:55 2008");
gives
1213094829

timelocal doesn't work because I have the scalar of localtime, not the
array.

If localtime always outputs the same format then surely there must be
something that reads it in and converts it back.

I CAN do this manually - I just want to know if there is something
official.

Thanks for any advice.

Mark


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

Date: Tue, 10 Jun 2008 04:09:06 -0700 (PDT)
From: Jacob JKW <jacobcdf@yahoo.com>
Subject: Re: Time and again
Message-Id: <7c3953c0-5499-44ca-b651-f93f1cd1a3da@m73g2000hsh.googlegroups.com>

On Jun 10, 7:02 am, markdibley <markdib...@gmail.com> wrote:
> print scalar localtime();
> gives
> Tue Jun 10 11:28:55 2008
>
> I write that to a file and later I read it in and want to convert it
> into a timestamp that I can sort on.
>
> Is there anything I can use that does the following
>
> print xxxxx("Tue Jun 10 11:28:55 2008");
> gives
> 1213094829
Check out http://search.cpan.org/~drolsky/DateTime-Format-HTTP/


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

Date: Tue, 10 Jun 2008 04:15:30 -0700 (PDT)
From: Jacob JKW <jacobcdf@yahoo.com>
Subject: Re: Time and again
Message-Id: <2f392c61-bde1-46c2-a6b6-7e49997ffddc@27g2000hsf.googlegroups.com>

On Jun 10, 7:09 am, Jacob JKW <jacob...@yahoo.com> wrote:
> On Jun 10, 7:02 am, markdibley <markdib...@gmail.com> wrote:> print scalar localtime();
> > gives
> > Tue Jun 10 11:28:55 2008
>
> > I write that to a file and later I read it in and want to convert it
> > into a timestamp that I can sort on.
>
> > Is there anything I can use that does the following
>
> > print xxxxx("Tue Jun 10 11:28:55 2008");
> > gives
> > 1213094829
>
> Check outhttp://search.cpan.org/~drolsky/DateTime-Format-HTTP/

Sorry make that http://search.cpan.org/~gaas/libwww-perl-5.812/lib/HTTP/Date.pm:

use HTTP::Date;
print str2time('Tue Jun 10 11:28:55 2008');


yields 1213111735



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

Date: Tue, 10 Jun 2008 11:30:52 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Time and again
Message-Id: <1uos4495gt10qpds6tle2vtalkv827tba1@4ax.com>

markdibley <markdibley@gmail.com> wrote:
>print scalar localtime();
>gives
>Tue Jun 10 11:28:55 2008
>
>I write that to a file and later I read it in 

Why are you dumping the data into a file and then reading it back in?
That seems to be a very roundabout way of doing things.

>and want to convert it
>into a timestamp that I can sort on.

You could print the list value of localtime(), after selecting the
proper subset of values [0-2, 4, 5] and reverse()ing their sequence.

>Is there anything I can use that does the following
>
>print xxxxx("Tue Jun 10 11:28:55 2008");
>gives
>1213094829

What is the relation between the date in the string and that number?

jue


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

Date: Tue, 10 Jun 2008 12:52:39 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Time and again
Message-Id: <j4idnf-tG-Wa9tPVnZ2dnUVZ8vWdnZ2d@posted.plusnet>

Jürgen Exner wrote:
> markdibley <markdibley@gmail.com> wrote:
>> print scalar localtime();
>> gives
>> Tue Jun 10 11:28:55 2008
>>
>> I write that to a file and later I read it in 
> 
> Why are you dumping the data into a file and then reading it back in?
> That seems to be a very roundabout way of doing things.

I'm guessing the output is primarily a human readable
log file of some kind, but that the OP also
wishes to post process the log file.

   BugBear (who's done just that)


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

Date: Tue, 10 Jun 2008 04:59:57 -0700 (PDT)
From: markdibley <markdibley@gmail.com>
Subject: Re: Time and again
Message-Id: <e5cc652c-7426-4381-9cbe-040d10632278@m36g2000hse.googlegroups.com>

Dear Jue

Thanks for your help. Just to reply to some of your questions.....

> Why are you dumping the data into a file and then reading it back in?
> That seems to be a very roundabout way of doing things.

Because that is the nature of log files - they need to be both human
and machine readable (well they don't but that is what people ask
for :-)

> >and want to convert it
> >into a timestamp that I can sort on.
>
> You could print the list value of localtime(), after selecting the
> proper subset of values [0-2, 4, 5] and reverse()ing their sequence.

That sounds like a lot of work for something that should be simple.

> >print xxxxx("Tue Jun 10 11:28:55 2008");
> >gives
> >1213094829
>
> What is the relation between the date in the string and that number?

It is the time() - i.e. the answer i was looking for.

Thanks again for your help.

Mark


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

Date: Tue, 10 Jun 2008 05:10:49 -0700 (PDT)
From: markdibley <markdibley@gmail.com>
Subject: Re: Time and again
Message-Id: <751ab83c-7a27-4f52-8320-456ec73bf724@w7g2000hsa.googlegroups.com>

On Jun 10, 12:15=A0pm, Jacob JKW <jacob...@yahoo.com> wrote:
> On Jun 10, 7:09 am, Jacob JKW <jacob...@yahoo.com> wrote:
> > Check outhttp://search.cpan.org/~drolsky/DateTime-Format-HTTP/
>
> Sorry make thathttp://search.cpan.org/~gaas/libwww-perl-5.812/lib/HTTP/Dat=
e.pm:
>
> use HTTP::Date;
> print str2time('Tue Jun 10 11:28:55 2008');
>
> yields 1213111735

Thank you sooooo much. That is exactly what I was looking for.

Below is an outline of all the outputs I have tried

#!/usr/bin/perl -w

use strict;
use Time::Local ;
use HTTP::Date;

print localtime();print "\n";
print localtime(),"\n";
print scalar localtime();print "\n";
print localtime()."\n";
print localtime(time)."\n";
print time()."\n";
print timelocal(localtime())."\n";
#print timelocal(scalar localtime())."\n";    doesn't work
print str2time(scalar localtime())."\n";
print str2time('Tue Jun 10 11:28:55 2008')."\n";
exit;

gives

28141310510821611
28141310510821611
Tue Jun 10 13:14:28 2008
Tue Jun 10 13:14:28 2008
Tue Jun 10 13:14:28 2008
1213100068
1213100068
1213100068
1213093735

where the last number is different because it is from an earlier time
string.

Now, when I forget and I search for "convert localtime string into
timestamp" I will hopefully find this. Google is my notebook ;-)

Thanks again

Mark



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

Date: Tue, 10 Jun 2008 14:39:38 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Time and again
Message-Id: <484e841d$0$2494$da0feed9@news.zen.co.uk>

markdibley wrote:
> 
> I write that to a file and later I read it in and want to convert it
> into a timestamp that I can sort on.
> 
> Is there anything I can use that does the following
> 
> print xxxxx("Tue Jun 10 11:28:55 2008");
> gives
> 1213094829
> 

I usually log timestamps in the form yyyy-mm-dd hh:mm:ss.ttt in order to 
produce something that is both sortable and human-readable.

Prevention is better than cure :-)

-- 
RGB


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

Date: Tue, 10 Jun 2008 09:20:09 -0400
From: zentara <zentara@highstream.net>
Subject: Re: Tk with Thread
Message-Id: <f8vs44l1lapprbk2kn03e5i6dspsbje46m@4ax.com>

On Mon, 9 Jun 2008 08:22:12 -0700 (PDT), Slickuser
<slick.users@gmail.com> wrote:

>When I move the use OLE to where I want to use it. Here's the error I
>get.
>
>Free to wrong pool 2db6e00 not 222dc8 during global destruction.

That is definitely an error caused by threads getting confused.
Try putting your 
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';

in the new_thread sub.  The other subs are part of the main code.

Also, try to make new_thread self-contained, don't use a separate
&test. Additionally, you are trying to access the Tk widget from thread
code in &test..... this cannot be done.

You cannot try to access Tk widgets in main from the thread, use a timer
and shared variables instead.



>use strict;
>use warnings;
>use Tk;
>use threads;
>use threads::shared;
>
>my $run:shared = 0;
>my $exit:shared = 0;
>my $count:shared = 0;
>
>
> my $thr = threads->new(\&new_thread);
>
>my $mainWindow = MainWindow->new;
>my $textBox = $mainWindow->Scrolled("Text", -width=>80, -height=>7,
>      -scrollbars=>"ose", -wrap=>"word")->pack();
>
>$mainWindow->Button(-foreground=>"blue", -text=>"Click",
>                   -command=>\&excecute)->pack();
>
>my $stopBut = $mainWindow->Button(-foreground=>"red", -text=>"Stop",
>                   -command=>sub{ $run=0; })->pack();
>
>
>
>
>$mainWindow->Button(-foreground=>"black", -text=>"exit",
>                   -command=>sub{ $exit=1;
>                                  $thr->join;
>                                  exit;
>                                   })->pack();
>
>my $repeater = $mainWindow->repeat(1000,sub{
>            if($run){
>              $textBox->insert('end', "$count\n");
>              $textBox->see('end');
>              $textBox->update;
>			  #$stopBut->configure(-state=> "disabled");
>             }
>            });
>
>
>
>
>MainLoop;
>
>sub new_thread{
>
>    while(1)
>	{
>       if($exit){ return; }    #thread can only be joined after it
>returns
>       if($run)
>	   {
>           if($exit){return;}
>          &test;
>
>       }
>	   else
>	   {
>		## Sleep for 1 miliseconds
>		select(undef,undef,undef,.1);
>	   }
>    }
>
>}
>sub test{
> $count++;
>#$::stopBut->configure(-state=> "disabled");
>}
>
>
>sub excecute {
>
>$run = 1 ;
>
>use Win32::OLE;
>use Win32::OLE::Const 'Microsoft Excel';
>
>
>}

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/CandyGram_for_Mongo.html 


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

Date: Tue, 10 Jun 2008 09:20:09 -0400
From: zentara <zentara@highstream.net>
Subject: Re: Tk with Thread
Message-Id: <qivs44debhljiuth03emdkg0t3d6j86t2l@4ax.com>

On Mon, 9 Jun 2008 16:18:07 -0700 (PDT), Slickuser
<slick.users@gmail.com> wrote:

>Here is what I want to achieve:
>Have the GUI up, use thread to process the data (read from file) and
>Excel OLE to output the data.
>I don't want my GUI to freeze up when it's running.
>I got the script going but I got couple of errors below.
>
>Any help would be great. Thanks a lot.

Go back and read the advice from previous threads. You must create
any thread before any Tk is called. You are trying to launch a thread
from a Tk button callback...... it won't work.

If you insist on using these types of designs, you will need to switch
to Perl/Gtk2, which allows some of these things, with certain
precautions.

Search groups.google.com for many examples of "Perl Tk thread" and
"perl Gtk2 thread". 

>
>Attempt to free non-existent shared string '_TK_RESULT_', Perl
>interpreter: 0x2e
>e14dc at C:\Documents and Settings\slickuser\Desktop\thread3.pl line
>22.
>Tk::Error: Can't call method "Call" on an undefined value at C:/Perl/
>site/lib/Tk
>/After.pm line 89.
> [once,[{},after#7,idle,once,[ConfigChanged,{},{}]]]
> ("after" script)
>Tk::Error: Can't call method "Call" on an undefined value at C:/Perl/
>site/lib/Tk
>/After.pm line 89.
> [once,[{},after#8,idle,once,[ConfigChanged,{},{}]]]
> ("after" script)
>Attempt to free non-existent shared string 'Value', Perl interpreter:
>0x22485c a
>t (eval 9) line 1.
>Free to wrong pool 222da8 not 2ed3ec8 at (eval 9) line 1.
>
>
>Here is my code:
>
>use strict;
>use warnings;
>use Tk;
>use threads;
>my $thr;
>
>my $mainWindow = MainWindow->new;
>my $textBox = $mainWindow->Scrolled("Text", -width=>80, -height=>7,
>      -scrollbars=>"ose", -wrap=>"word")->pack();
>
>my $goBut = $mainWindow->Button(-foreground=>"blue", -text=>"Click",
>                   -command=>sub { $thr = threads->new(\&excecute) } )-
>>pack();
>
>my $stopBut = $mainWindow->Button(-foreground=>"red", -text=>"Exit",
>                   -command=>sub{ if(defined($thr)){ $thr->detach; }
>exit; })->pack();
>
>MainLoop;
>
>
>sub excecute
>{
>	$goBut->configure(-state=>"disabled");
>	$textBox->configure(-state=>"normal");
>	open(FILE,"C:/file.txt") or die "Can't open file.\n";
>	while(<FILE>)
>	{
>		my $message = $_;
>		$textBox->insert('end', $message);
>	}
>	close(FILE);
>
>	$textBox->configure(-state=>"disabled");
>	$textBox->see('end');
>
>	use Win32::OLE;
>	use Win32::OLE::Const 'Microsoft Excel';
>
>	my ($Excel,$Workbook,$fileOutput,$CurrentSheet,$Range);
>	$fileOutput = "C:/test.xls";
>
>	$Excel = Win32::OLE->new('Excel.Application', 'Quit') || die "Can't
>create Excel object. \n";
>	$Excel->{'Visible'} 			= 1;	#0 is hidden, 1 is visible
>	$Excel->{DisplayAlerts} 		= 0;	#0 is hide alerts
>	$Excel->{SheetsInNewWorkbook} 	= 1;
>	$Workbook = $Excel->Workbooks->Add();
>
>	$Workbook->SaveAs($fileOutput) or die "Can't save Excel.\n";
>	$CurrentSheet = $Workbook->Worksheets(1);
>	$CurrentSheet->Select;
>
>	for (my $i=1; $i<=65356; $i++)
>	{
>		$Range = $CurrentSheet->Range("A$i");
>		$Range->{Value} = $i;
>		sleep(0.01);
>	}
>
>	$Workbook->Save();
>	$Workbook->Close();
>	$Excel->Quit();
>	Win32::OLE->FreeUnusedLibraries();
>	$goBut->configure(-state=>"normal");
>
>	return;
>}

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/CandyGram_for_Mongo.html 


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

Date: Tue, 10 Jun 2008 15:55:26 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Tk with Thread
Message-Id: <u7h2i5-k12.ln1@osiris.mauzo.dyndns.org>


Quoth zentara <zentara@highstream.net>:
> On Mon, 9 Jun 2008 08:22:12 -0700 (PDT), Slickuser
> <slick.users@gmail.com> wrote:
> 
> >When I move the use OLE to where I want to use it. Here's the error I
> >get.
> >
> >Free to wrong pool 2db6e00 not 222dc8 during global destruction.
> 
> That is definitely an error caused by threads getting confused.
> Try putting your 
> use Win32::OLE;
> use Win32::OLE::Const 'Microsoft Excel';
> 
> in the new_thread sub.  The other subs are part of the main code.

This won't change anything. Use statements are executed at compile-time,
before any threads have been created.

If you *really* need to use a module in a particular thread, you need to
'require' it and call ->import manually. This is almost certainly not
necessary in this case, though.

> Also, try to make new_thread self-contained, don't use a separate
> &test. Additionally, you are trying to access the Tk widget from thread
> code in &test..... this cannot be done.

This is much more likely to be the problem.

Ben

-- 
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~                   Jorge Luis Borges, 'The Babylon Lottery'


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

Date: Tue, 10 Jun 2008 01:18:53 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: Trying to catch invalid emails
Message-Id: <g2ldde01t0o@news4.newsguy.com>

Ben Bullock wrote:
> Samik R. <samik@frkkshkll.org> wrote:
>
>> This expression does not catch the above 3 emails in the array (the
>> program says that they are valid emails).
>>
>> Can someone help me to discard these three?
>
> You asked the same question on May 7th 2008, and got a lot of replies:
>
> http://groups.google.co.jp/group/comp.lang.perl.misc/browse_frm/thread/a807e473d83be073/d0e7a31a55bedb02?hl=en#d0e7a31a55bedb02

(Sorry for nitpicking, but just for the sake of correctness, as all as 
curiousness; did you get May 7th from a time zone localization or was 
there another reason?)

Actually it was posted on May 6th, 2008:

   From: "Samik R." <samik@frKKshKll.org>
   Newsgroups: comp.lang.perl.misc
   Subject: Trying to catch invalid emails
   Date: Tue, 06 May 2008 20:58:25 -0600
   Message-ID: <fvr60f$pqd$1@aioe.org>


-- 
szr 




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

Date: Tue, 10 Jun 2008 09:21:37 -0400
From: Dan Rumney <danrumney@warpmail.net>
Subject: Re: Trying to catch invalid emails
Message-Id: <484e7fe1$0$20175$4c368faf@roadrunner.com>

> ------------
> my @Email=("sam._\@abc.org", "sam_.\@abc.org", "sam_.\@abc.org");
> foreach (@Email)
> {
> 
> if(/^[A-z0-9]+([_\.][A-z0-9\-]+)*[@][A-z0-9_\-]+([.][A-z0-9_\-]+)?\.[A-z]{2,3}$/) 
> 
>  {    print "$_ is a valid email id\n";    }
>  else
>  {    print "$_ is an invalid email id\n"; }
> }
> -------------

No it doesn't

I just ran that script and it calls the first email address valid and 
the other 2 invalid.

Since the second 2 email addresses are identical, it's not surprising 
that they are assessed with the same validity.


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

Date: Tue, 10 Jun 2008 03:28:03 -0700 (PDT)
From: Jacob JKW <jacobcdf@yahoo.com>
Subject: Using IPC::Open2 on Windows for mission critical app
Message-Id: <4e2835b4-577a-4dfe-94db-a664e28b2493@z66g2000hsc.googlegroups.com>

I'd like to start using IPC::Open2 on Windows Vista for a mission
critical application, but I'm a little cautious based on some postings
I've read. So far I've gotten it working without a hitch and have been
unable to manufacture any errors.

The way I have it working is by opening a single external process for
read/write access local to a class that handles all interaction with
this process. If all goes well, my application during its entire
lifespan will only have one instance of this external process running.

A class method writes to the process when necessary and another method
reads from it when necessary.

The read method uses a while() loop on the read file handle and then
uses "last" to exit the loop when a specific line of text is read. I
find this a little disconcerting as if anything goes wrong with the
process the while loop will just hang indefinitely, effectively
slaughtering my application.

As a failsafe, I've tried using $SIG{ALRM} to no avail, as the alarm()
doesn't appear useful when reading from the file handle.

	local $SIG{ALRM} = sub { die "Alarm went off!\n"; };
	while(<$readFH>) {
		last if m/^END$/;
		# do stuff
	}

Does anyone have any ideas on a better failsafe? Of perhaps on a way
to get SIG ALRM working in the manner I've outlined? Or perhaps
someone could offer reassurances that the problems with IPC::Open2 on
Windows that I've hear about (which I'll reiterate that I've yet to
actually encounter) have been cleared up with new releases.

I'm currently using ActiveState binary build 820.


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

Date: Tue, 10 Jun 2008 15:50:49 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Using IPC::Open2 on Windows for mission critical app
Message-Id: <9vg2i5-k12.ln1@osiris.mauzo.dyndns.org>


Quoth Jacob JKW <jacobcdf@yahoo.com>:
> 
> As a failsafe, I've tried using $SIG{ALRM} to no avail, as the alarm()
> doesn't appear useful when reading from the file handle.
> 
> 	local $SIG{ALRM} = sub { die "Alarm went off!\n"; };
> 	while(<$readFH>) {
> 		last if m/^END$/;
> 		# do stuff
> 	}

AFAIK alarm doesn't work on Win32. Probably the simplest alternative is
to create a second thread which waits for the timeout and then kills the
first thread: you will need to test to make sure that a thread waiting
for IO can be killed.

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 'Alcestis')        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

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 V11 Issue 1628
***************************************


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