[31158] in Perl-Users-Digest
Perl-Users Digest, Issue: 2403 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 8 21:09:45 2009
Date: Fri, 8 May 2009 18:09:12 -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 Fri, 8 May 2009 Volume: 11 Number: 2403
Today's topics:
"print $variable" gives me REF(0x8fdc2d4) instead of HA <scottalorda@libello.com>
Re: "print $variable" gives me REF(0x8fdc2d4) instead o <smallpond@juno.com>
Re: Console output on Win32? <ben@morrow.me.uk>
Re: how to attach a running process to perl debugger <tadmc@seesig.invalid>
Re: IO::Socket::INET on OSX or TCP stack problem <stuart@otenet.gr>
Re: IO::Socket::INET on OSX or TCP stack problem <uri@stemsystems.com>
Re: opening a client application from a server? <cartercc@gmail.com>
Re: opening a client application from a server? <yankeeinexile@gmail.com>
Re: opening a client application from a server? <veatchla@yahoo.com>
Re: opening a client application from a server? <hjp-usenet2@hjp.at>
Re: opening a client application from a server? <jurgenex@hotmail.com>
Re: pod2ipf in Perl 5.10? <pauldespam@despamsmedley.id.au>
Proposal: Image::EXIF::DateTime::Parser <marcin@owsiany.pl>
To count # characters in a line and make the line short clearguy02@yahoo.com
Re: To count # characters in a line and make the line s <jurgenex@hotmail.com>
Re: transliteration of unicode to phonetic ASCII++? <nospam-abuse@ilyaz.org>
Re: writing get_script() <cwilbur@chromatico.net>
Re: writing get_script() <jurgenex@hotmail.com>
Re: writing get_script() <frank@example.invalid>
Re: writing get_script() <frank@example.invalid>
Re: writing get_script() <frank@example.invalid>
Re: writing get_script() <uri@stemsystems.com>
Re: writing get_script() <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 8 May 2009 05:31:28 -0700 (PDT)
From: =?ISO-8859-1?Q?S=E9bastien_Cottalorda?= <scottalorda@libello.com>
Subject: "print $variable" gives me REF(0x8fdc2d4) instead of HASH(0x....)
Message-Id: <6d602c63-49e2-423d-a88f-70cd16fb5015@l28g2000vba.googlegroups.com>
Hi all,
I'm trying to add Hash::Flatten functionality to the IPC::Shareable
module.
In IPC::Shareable, I've that function:
sub _freeze {
my $s = shift;
my $water = shift;
...
my $ice = freeze $water;
...
$s->shmwrite($ice);
}
I'm trying to add Hash::Flatten like this:
sub _freeze {
my $s = shift;
my $water = shift;
...
$water = flatten($water, { HashDelimiter => '->', ArrayDelimiter
=> '=>', });
my $ice = freeze $water;
...
$s->shmwrite($ice);
}
unfortunately, sometimes, i obtains:
"Not a SCALAR reference at /home/workspace/panneau/modules/IPC/
Shareable.pm line 717."
and the module crashes.
When I print $water just before flatten(...), I get REF(0x8fdc2d4)
instead of HASH(0x...)
With the Data::Dumper module, I obtains:
$water = \{
'key' => 'value',
'another_key => {
'key1' => 'value1',
....
},
}
How can I transform $water from REF(0x....) to HASH(0x....)
Thanks in advance for any kind of help.
Sebastien
------------------------------
Date: Fri, 8 May 2009 08:07:01 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: "print $variable" gives me REF(0x8fdc2d4) instead of HASH(0x....)
Message-Id: <4c015e45-e29d-408a-b19d-c02898adfcf2@e23g2000vbe.googlegroups.com>
On May 8, 8:31=A0am, S=E9bastien Cottalorda <scottalo...@libello.com>
wrote:
> Hi all,
>
> I'm trying to add Hash::Flatten functionality to the IPC::Shareable
> module.
>
> In IPC::Shareable, I've that function:
> sub _freeze {
> =A0 =A0 my $s =A0=3D shift;
> =A0 =A0 my $water =3D shift;
> ...
> =A0 =A0 my $ice =3D freeze $water;
> ...
> =A0 =A0 $s->shmwrite($ice);
>
> }
>
> I'm trying to add Hash::Flatten like this:
> sub _freeze {
> =A0 =A0 my $s =A0=3D shift;
> =A0 =A0 my $water =3D shift;
> ...
> =A0 =A0 $water =3D flatten($water, { HashDelimiter =3D> '->', ArrayDelimi=
ter
> =3D> '=3D>', });
> =A0 =A0 my $ice =3D freeze $water;
> ...
> =A0 =A0 $s->shmwrite($ice);
>
> }
>
> unfortunately, sometimes, i obtains:
> "Not a SCALAR reference at /home/workspace/panneau/modules/IPC/
> Shareable.pm line 717."
> and the module crashes.
> When I print $water just before flatten(...), I get REF(0x8fdc2d4)
> instead of HASH(0x...)
>
> With the Data::Dumper module, I obtains:
> $water =3D \{
> =A0 =A0 'key' =3D> 'value',
> =A0 =A0 'another_key =3D> {
> =A0 =A0 =A0 =A0 'key1' =3D> 'value1',
> =A0 =A0 =A0 =A0 ....
> =A0 =A0 },
>
> }
>
> How can I transform $water from REF(0x....) to HASH(0x....)
>
> Thanks in advance for any kind of help.
>
> Sebastien
Is the ref to a ref to a hash? ie. $water =3D \\%h?
$rapids =3D ref $water eq "REF" ? %$water : $water;
------------------------------
Date: Fri, 8 May 2009 23:18:45 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Console output on Win32?
Message-Id: <5nned6-i14.ln1@osiris.mauzo.dyndns.org>
Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> Is it possible to use `binmode($fh, SOMETHING)' in Win32 to get "the
> expected console-like behaviour" on the handle? Something other API?
>
> I mean something like what I find on:
> http://blogs.msdn.com/junfeng/archive/2004/02/25/79621.aspx
>
> (the semantic is to get full unicode text on the console, and text
> converted to the current codepage if the output is redirected to a
> pipe/file; cp65001 [=UTF-8] not excluded).
I don't think so. There doesn't appear to be any way to call
WriteConsoleW from perl without wrapping it yourself: AFAICT,
Win32::Console only allows you to call WriteConsoleA, which won't do
what you want.
The pipe/file part is obviously easy: just use Win32::Console::OutputCP
to get the encoding and binmode($fh, ":encoding(cp$CP)") to encode the
data.
If you were interested in doing so, writing a :win32console or
:via(Win32::Console) PerlIO layer wouldn't be hard. You would need some
XS to call the W versions of the console functions, of course.
Ben
------------------------------
Date: Fri, 8 May 2009 05:48:25 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: how to attach a running process to perl debugger
Message-Id: <slrnh083fp.2es.tadmc@tadmc30.sbcglobal.net>
sunil <sunil.vvn@gmail.com> wrote:
[ snip duplicated article ]
Please do not multipost.
http://oakroadsystems.com/genl/unice.htm#xpost
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sat, 9 May 2009 00:05:54 +0300
From: Stuart Gall <stuart@otenet.gr>
Subject: Re: IO::Socket::INET on OSX or TCP stack problem
Message-Id: <gu26qu$e47$1@mouse.otenet.gr>
On 2009-05-07 23:03:16 +0300, derykus@gmail.com said:
> On May 7, 12:26 pm, Stuart Gall <stu...@otenet.gr> wrote:
>> Hello,
>> I have written a script using IO::Socket::INET to read and write data to
>> modbus devices. Using blocking IO ->read and ->write.
>> This is running on OSX V 10.4.11
>> I have the latest IO::Socket Library from CPAN.
>> ....
>
> No ideas about the problem but I'd recommend showing
> some of your code. Seeing actual code often jogs
> memories in ways other problem descriptions can't.
> What options did you pass to the IO::Socket::INET constructor,
> Reuseaddr, Timeout, Blocking, etc.?
Good point, my code is so basic that I am convinced there must be a
generic problem on OSX. I just cant believe no one else has come across
it. :-(
I tried Reuseaddr which did not make any diferance, I am only openeing
one socket per destination anyways.
I open the sockets with
sub OpenSocket() {
#Get Socket address for IP or open a new socket
my ($IP,$PORT,$S,$R,$I,@R);
$IP=shift;
$PORT=502;
if(!$SOCKETS{$IP}) {
$S = new IO::Socket::INET (PeerAddr => $IP,
PeerPort => $PORT,
Proto => "tcp",
Timeout =>10,
Type => SOCK_STREAM) or return(undef);
$SOCKETS{$IP}=$S;
$SELECT->add($SOCKETS{$IP});
$SOCKETS{$IP}->sockopt(TCP_NODELAY,1);
};
return ($SOCKETS{$IP});
};
This is then called from for example
sub Read_10_Integer($$) {
my (@R, $IP, $ADD, $PORT,$COMMAND, $q, $socket, $len, @Reply);
$IP = shift;
$ADD = shift;
$PORT=502;
$ADD--;
$COMMAND =
"\x00\x00\x00\x00\x00\x06\x01\x03".chr(int($ADD/256)).chr($ADD %
256)."\x00\x0A";
unless($socket= OpenSocket($IP)) {
print "Can't connect ($IP) : $@ [$!]\n";
return undef;
};
print $socket $COMMAND;
$socket->read($r,6); #5th byte is the length byte *****
This is one place that it hangs with repeated retries on the tcpdump
@R=split(//,$r);
return undef if(ord($R[0])!=0 or ord($R[1])!=0);
$len=ord($R[5]);
$socket->read($r,$len);
@R=split(//,$r);
Exception(ord($R[2])) if(ord($R[1]) > 0x80);
@Reply=();
for($q=0;$q<10;$q++) {
$Reply[$q]=ord($R[$q*2+3])*256+ord($R[$q*2+4]);
};
return @Reply;
};
------------------------------
Date: Fri, 08 May 2009 18:18:45 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: IO::Socket::INET on OSX or TCP stack problem
Message-Id: <87iqkb5jcq.fsf@quad.sysarch.com>
>>>>> "SG" == Stuart Gall <stuart@otenet.gr> writes:
SG> Good point, my code is so basic that I am convinced there must be a
SG> generic problem on OSX. I just cant believe no one else has come
SG> across it. :-(
your code could still use major improvements.
SG> I open the sockets with
SG> sub OpenSocket() {
SG> #Get Socket address for IP or open a new socket
SG> my ($IP,$PORT,$S,$R,$I,@R);
SG> $IP=shift;
my( $ip ) = @_ ;
SG> $PORT=502;
my $port = 502 ;
use lower case names for lexical vars. upper case is for constants (yes,
the port is a constant but still i like lower as do most perl coders)
SG> if(!$SOCKETS{$IP}) {
unless( $sockets{$ip} ) {
where is %sockets declared? it should be passed in via a hash ref
instead of being a global
SG> $S = new IO::Socket::INET (PeerAddr => $IP,
SG> PeerPort => $PORT,
SG> Proto => "tcp",
SG> Timeout =>10,
SG> Type => SOCK_STREAM) or return(undef);
my $sock = IO::Socket::INET->new( "$ip:$port" ) ;
there, isn't that much simpler? basic tcp socket connections can pass a
single host:port string. the type, proto are defaulted
correctly. timeout is fine with its default.
$sock or return ;
no need to return undef. plain return does that when called in scalar
context.
SG> $SOCKETS{$IP}=$S;
SG> $SELECT->add($SOCKETS{$IP});
what's with all the shouting? perl style is lower case
SG> $SOCKETS{$IP}->sockopt(TCP_NODELAY,1);
here is the big question. why do you do that? it is not needed except in
very special cases and your code is not one of them. it may even be the
cause of the socket dropouts.
SG> };
SG> return ($SOCKETS{$IP});
why do you return the socket from the global hash? you have it in $S (or
in my version $sock).
SG> };
SG> This is then called from for example
SG> sub Read_10_Integer($$) {
SG> my (@R, $IP, $ADD, $PORT,$COMMAND, $q, $socket, $len, @Reply);
don't declare vars before you need them. you can my each of these in the
assignments below
SG> $IP = shift;
SG> $ADD = shift;
my( $ip, $add ) = @_ ;
shifting @_ for args is poor style. it is useful in some cases but
assiging @_ to a list of my vars is standard perl style.
SG> $PORT=502;
why is this set again? if it is really a constant, move it outside the
subs or pass it in as an arg.
SG> $ADD--;
what is $ADD? use a better name for it.
SG> $COMMAND =
SG> "\x00\x00\x00\x00\x00\x06\x01\x03".chr(int($ADD/256)).chr($ADD %
SG> 256)."\x00\x0A";
SG> unless($socket= OpenSocket($IP)) {
since this is a boolean test, have OpenSocket just return 1 on success,
not the socket itself.
SG> print "Can't connect ($IP) : $@ [$!]\n";
SG> return undef;
SG> };
SG> print $socket $COMMAND;
$socket->print( $COMMAND ) ;
SG> $socket->read($r,6); #5th byte is the length byte
$socket->sysread(my $read_buf, 6);
use sysread on sockets. unless you are doing blocking line by line
protos, you shouldn't use stdio or perlio for sockets.
SG> This is one place that it hangs with repeated retries on the tcpdump
SG> @R=split(//,$r);
my @read_bytes = split(//,$r);
SG> return undef if(ord($R[0])!=0 or ord($R[1])!=0);
SG> $len=ord($R[5]);
SG> $socket->read($r,$len);
maybe the retries are caused by the NO_DELAY thing. it moves data out in
smaller packets and those are getting lost often. remove that unhelpful
option and see what happens.
SG> @R=split(//,$r);
SG> Exception(ord($R[2])) if(ord($R[1]) > 0x80);
SG> @Reply=();
my @reply ;
SG> for($q=0;$q<10;$q++) {
SG> $Reply[$q]=ord($R[$q*2+3])*256+ord($R[$q*2+4]);
SG> };
i am sure that can be done more cleanly but i can't fathom it right now.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Fri, 8 May 2009 05:27:26 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: opening a client application from a server?
Message-Id: <49a39eda-1999-405b-b596-24c86d74f897@b1g2000vbc.googlegroups.com>
PROBLEM SOLVED! :-)
What a dunce am I! All I had to do was link to the directory rather
than the document. Not only will this enable the end user to open the
document in the native application on the client machine, but it also
has the very beneficial side effect of avoiding the creation of links
to all the documents. This works in IE, FF, Opera, and Safari.
As soon as I got to work this morning, I realized that I was following
my client's instructions too literally. The fix took literally about
six seconds, and my client was very happy.
Apologies to those who were misled by my confusion.
As an end note, I'm happy with the way OOXML has worked out. I can now
create Word documents, and presumably Excel workbooks and PowerPoint
presentations, by writing XML files. I view this as a great leap
forward, and report that Perl is just as capable now of creating
Office documents as it is ordinary text files, and thus lives up to
its name as a practical extraction and reporting language.
Thanks to everyone who responded, and again, please accept my apology
for my initial confusion.
CC.
On May 7, 3:41=A0pm, ccc31807 <carte...@gmail.com> wrote:
> This relates to the post I made last week about working with
> WordProcessingML. That part turned out to be easy -- as easy as
> writing a CGI script and dynamically updating the HTML from a
> database. WordProcessingML is no different from XHTML and does pretty
> good at creating Word documents.
>
> Here's the question: The client has a requirement that the users
> create a Word document on a web enabled app and open it in the client
> browser. I can create the word document and open it on the server
> (using this command -- exec("c:/Program Files/Microsoft Office/
> OFFICE12/winword.exe", "c:/TEST1.DOC")) but I can't get Word to open
> the file on the client. I can write the .doc file to a directory and
> give the client to the directory over the internet, but that doesn't
> meet the requirement.
>
> I've tried creating =A0hyperlink like <a href=3D"test.doc">Here is your
> Word document</a> but that doesn't work either.
>
> I'm about to tell my client that I can't meet this requirement ...
> I've been trying since Monday and have about given up. Any ideas?
>
> Thanks, CC.
------------------------------
Date: Fri, 08 May 2009 09:59:14 -0500
From: Lawrence Statton <yankeeinexile@gmail.com>
Subject: Re: opening a client application from a server?
Message-Id: <m163gbiqt9.fsf@mac.gateway.2wire.net>
ccc31807 <cartercc@gmail.com> writes:
> Besides, I don't understand why a Content-Type is necessary.
>
Content-Type is how the user agent SHOULD map "content" to
"application suitable for consuming this content"
The browser MAY attempt to infer content-type from the URI if the
content-type header is missing. Very Old versions of IE had a nasty bug
where they would ignore the content-type header under some conditions,
and ONLY infer the type based on the URI.
Your HTTP server may add a "suitable" content-type header based on the
URI if you do not send one explicitly when generating your response.
--L
------------------------------
Date: Fri, 08 May 2009 10:42:07 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: opening a client application from a server?
Message-Id: <YtWdnfHAQqhNz5nXnZ2dnUVZ_oudnZ2d@supernews.com>
Jürgen Exner wrote:
> l v <veatchla@yahoo.com> wrote:
>> If you are dynamically creating the document, you don't need to write it
>> to the file system and generate a link in a web page for the user to
>> click on. You can simply send the document directly to the client
>> browser *if* you send the proper html content type.
>
> Thank you, I think you very nicely explained the basic assumption
> everyone was making.
> One minor point: it would be a content type in the HTTP header and just
> to make absolutely sure: it would not be set to "HTML".
>
> jue
Good point on the s/html/http/ catch. I blame the allergy meds I'm on. :)
--
Len
------------------------------
Date: Fri, 8 May 2009 18:31:06 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: opening a client application from a server?
Message-Id: <slrnh08nib.jjh.hjp-usenet2@hrunkner.hjp.at>
On 2009-05-08 01:16, ccc31807 <cartercc@gmail.com> wrote:
> On May 7, 8:46 pm, Jürgen Exner <jurge...@hotmail.com> wrote:
>> No, it's not an Apache problem, either. It's an HTTP problem.
I think it is an Apache problem, but we don't have enough information to
be sure.
> This is what I can't understand. I import a big glob of data from a
> database into my script, generate many csv files, or txt files, or pdf
> files, or xml file, etc., and generate links. The browsers, IE but FF
> as well will happily open a csv file in Excel (assuming that the
> client is a Windows machine with Office installed), open a pdf file in
> Acrobat, open a txt file in the browser window, and so on.
This is because the server (Apache in your case) is configured to send
the correct content-type for these file types *and* because the browser
is configured to invoke the appropriate application for each of these
content-types. You may not personally have configured the server or the
browser, but if you look at their configuration you will see it.
> I ASSUMED(!) that a doc file would work the same way, that is, open
> natively in Word on a machine running Office. It doesn't, and I don't
> know enough to understand why it doesn't.
There are two possibilities:
* The server is not configured to recognize MS-Word files and send an
appropriate content-type (e.g., application/msword).
* The browser is not configured to invoke MS-Word for documents of type
application/msword.
I think it probably is the former: Apache uses the extension to
determine the file type (because that's a lot faster than actually
looking into the file) and .doc has been historically used for many
different file formats, so that it's probably too dangerous to assume
that any file ending with ".doc" is a Word document.
But that's easy to check: Just retrieve the file with wget, and it will
tell you the content-type. If it's Apache, fix the Apache config. If
it's the browser, fix the browser config.
>> Has nothing to do with Windows but everything with how HTTP works.
>> So, what Content-Type did you try?
>
> I didn't. When I produce csv, pdf, etc., I don't specify any Content-
> Type.
Oh, yes, you do. You create files with a specific extension (e.g.,
".pdf") and you (or whoever configured the server) set up a config file
which maps the extension ".pdf" to the content-type "application/pdf".
> I just create the files and they open the way they should. XML
> is very picky, and Word demands a PERFECT(!) XML file to open,
> otherwise it throws an error, and I suspect that an attempt to
> incorporate a Content-Type element in the XML would create a problem.
The content type doesn't belong into the XML file. It needs to be sent
in the HTTP header.
> Besides, I don't understand why a Content-Type is necessary.
A content type is always necessary. It is a mandatory part of the HTTP
protocol. You were just lucky that Apache was already set up in a way
to choose the correct content type for the files you generated.
hp
------------------------------
Date: Fri, 08 May 2009 09:47:27 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: opening a client application from a server?
Message-Id: <eao805967se2v5soc7996bseh2uq1ddd9n@4ax.com>
"Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>On 2009-05-08 01:16, ccc31807 <cartercc@gmail.com> wrote:
>> On May 7, 8:46 pm, Jürgen Exner <jurge...@hotmail.com> wrote:
>>> No, it's not an Apache problem, either. It's an HTTP problem.
>
>I think it is an Apache problem, but we don't have enough information to
>be sure.
Yes, it was either or. Either Apache wasn't configured to create the
correct content type in the HTTP header or the OP didn't set the correct
content in the HTTP header.
As we established in a different branch of this thread everyone assumed
the later because he was talking about CGI while the OP was actually
talking about the former.
jue
------------------------------
Date: 08 May 2009 23:46:26 GMT
From: "Paul Smedley" <pauldespam@despamsmedley.id.au>
Subject: Re: pod2ipf in Perl 5.10?
Message-Id: <POn1Xm9ddZOp-pn2-WwJdWghQ771q@smedley.info>
Hi Andy,
On Thu, 7 May 2009 19:08:00 UTC, "Andy"
<nospam-abwillis1-nopspam@nospam-gmail.com> wrote:
> On Wed, 29 Apr 2009 09:55:19 UTC, "Paul Smedley"
> <pauldespam@despamsmedley.id.au> wrote:
>
> > Hi Shmuel,
> >
> > On Tue, 28 Apr 2009 12:52:26 UTC, Shmuel (Seymour J.) Metz
> > <spamtrap@library.lspace.org.invalid> wrote:
> >
> > > In <POn1Xm9ddZOp-pn2-HGd75dgbvE56@smedley.info>, on 04/26/2009
> > > at 10:07 PM, "Paul Smedley" <pauldespam@despamsmedley.id.au> said:
> > >
> > > >I don't see a 5.10.1
> > >
> > > Perl 5.10.1 is a projected bug-fix release that is expected imminently. I
> > > don't know whether you normally do builds for such.
> > Yeah I probably will - I do for things like mysql, apache2, etc
> >
> >
> > > >I don't plan on installing any external packages
> > >
> > > But is something documented in perlos2 really an external package for an
> > > OS/2 release? Do you plan on creating an INF the next time around?
> > I've never even looked at perlos2 - and have no idea how to create an
> > INF... so I guess that's a know unless someone wants to help create
> > it.
> >
> > I'd like to work out why my perl builds can't be used to build mozilla
> > - just need to find a few more extra hours in the week - getting
> > harder and harder the way my day job is going right now....
> >
> Works fine here for building Mozilla. I am using the wpi that was
> released (don't recall by whome) but had to update the
> klibcpathrewriters as it set /perl and it needed to set /perl5.
Interesting - I'll have to look at my install then :)
--
Cheers,
Paul.
------------------------------
Date: Fri, 8 May 2009 12:06:13 -0700 (PDT)
From: Marcin Owsiany <marcin@owsiany.pl>
Subject: Proposal: Image::EXIF::DateTime::Parser
Message-Id: <c7812d91-8a01-4845-a4ec-126746bd1235@v4g2000vba.googlegroups.com>
[cc: modules@cpan.org, sergey - author of Image::EXIF]
As a part of a program I'm writing I made a module that might be
useful to
other people. Below is an excerpt from its README and POD.
Please send me your comments and suggestions before I upload it to
CPAN.
README:
| Image::EXIF::DateTime::Parser
| =============================
|
| Purpose
| -------
|
| This module provides a parser for "DateTime" strings as defined in
| Exchangeable image file format for digital still cameras:
| Exif Version 2.2
| Section 4.6.4 "TIFF Revision 6.0 Attribute information"
| Subsection D. "Other Tags", DateTime
|
| Apart from parsing the strings that conform to the specification,
this
| module tries to decipher some non-compliant strings which certain
| implementations produce. Examples of supported deviations can be
| found in the unit tests for this module.
| [...]
POD:
| NAME
| Image::EXIF::DateTime::Parser - parser for EXIF date/time
strings
|
| SYNOPSIS
| use Image::EXIF::DateTime::Parser;
|
| my $parser = Image::EXIF::DateTime::Parser->new;
| printf "%d\n", $p->parse("2009:05:05 09:17:37");
|
| produces "1241540257", if you are in America/Los_Angeles
timezone.
|
| DESCRIPTION
| While parsing standards-compliant EXIF Date/Time string is
easy, allow$B!>(B
| ing for the various ways different non-standards-compliant
implementa$B!>(B
| tions mangle these strings is neither easy nor pleasant. This
module
| encapsulates this complexity for you. It provides a parser
which takes
| an EXIF Date/Time string and returns time in "calendar time"
format,
| aka. time_t.
|
| EXPORTS
|
| Nothing.
|
| METHODS
|
|
| $p = Image::EXIF::DateTime::Parser->new
| Returns a new parser object.
|
| Introduced in version 1.1.
|
| $time_t = $p->parse( $B!G(B2009:05:05 09:17:37$B!G(B )
| Takes a single argument: an EXIF Date/Time string, and
returns a
| time_t value by interpreting the string as local time.
|
| Returns undef when the string represents an unknown date/
time
| (zeros or blanks).
|
| Throws an exception if the string is not parseable.
|
| Introduced in version 1.1.
regards,
Marcin
PS: Apologies if google groups mangles the message.
------------------------------
Date: Fri, 8 May 2009 16:21:07 -0700 (PDT)
From: clearguy02@yahoo.com
Subject: To count # characters in a line and make the line shorter
Message-Id: <66e6a6ae-3c69-404b-9aad-71755e89be77@c18g2000prh.googlegroups.com>
Hi experts,
In my script, I need to check if a total number of characters in a
line is more than 10 or not and it it is >10, I should the cut the
original line to only 10 characters.
Example:
=============
$orig_line = "Perl is a good language";
$total_char = length ($orig_line)";
$second_line;
if ($total_char > 10)
{
print "The original's size is $total_char, but it should be
$second_line";
}
One way I can think is to get the difference between the $total_char
and the limit value (10) and after the finding the difference number,
I can truncate those many characters from the original line and store
that modified line in $second_line variable.
Does some one suggest me a shorter way of doing it?
Thanks,
J
------------------------------
Date: Fri, 08 May 2009 17:10:41 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: To count # characters in a line and make the line shorter
Message-Id: <5ci905hs13i4thp8bkovj0ao9a34dcbgmb@4ax.com>
clearguy02@yahoo.com wrote:
>In my script, I need to check if a total number of characters in a
>line is more than 10 or not and it it is >10, I should the cut the
>original line to only 10 characters.
>
>Example:
>=============
You are missing
use strict; use warnings;
>$orig_line = "Perl is a good language";
[complicated, non-compilable code snipped]
This does smell like homework, but I'm bored today:
use warnings;
use strict;
my $orig_line = "Perl is a good language";
if (length $orig_line > 10){
print ('The original\'s size is ',
length $orig_line ,
' total_char, but it should be ',
substr($orig_line, 0, 10)
)
}
jue
------------------------------
Date: Fri, 08 May 2009 17:03:20 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: transliteration of unicode to phonetic ASCII++?
Message-Id: <slrnh08peo.6o3.nospam-abuse@chorin.math.berkeley.edu>
In the first message of this thread
>>>> I'd like to translate some cyrillic file names into file names, that are
>>>> ASCII only.
Let me summarize what I learned from this thread:
a) http://userguide.icu-project.org/transforms/general
is very educational on what kind of intelligent questions and
answers one could encounter in this topic. (This is slightly
offset by the terms `slash' and `backslash' being used
interchangingly - in a document on character semantic!)
b) http://search.cpan.org/~sburke/Text-Unidecode-0.04/lib/Text/Unidecode.pm
documentation (and organization - tables are broken into small
chunks) is very impressive. The date looks a little bit
suspicious - but it MAY be that there is nothing to fix!
c) http://search.cpan.org/~wollmers/Text-Undiacritic-0.02
(probably) uses Unicode data tables. (Probably) does not break
the tables into small chunks, so loading may be slow and take
quite a lot of resources. (But I did not look deep; it might be
that it uses Unicode tables at build time only to generate its
own "small tables".)
Myself, I would very much prefer the flexibility of "a" combined with
the simplicity of "b". If I would try to code something like this, I
would special-case some small "hot" subset (like IBM's UGL, or M$'s
WGL), and would
A) machine-translate to this hot subset;
B) allow human-generated web of possible "equivalences" and
"simplifications" inside the hot subset...
Thanks to everybody,
Ilya
------------------------------
Date: Fri, 08 May 2009 10:56:37 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: writing get_script()
Message-Id: <8663gbiqxm.fsf@mithril.chromatico.net>
>>>>> "cc" == ccc31807 <cartercc@gmail.com> writes:
cc> On May 7, 5:17 pm, Charlton Wilbur <cwil...@chromatico.net> wrote:
>> Because of requirement 3, I'd probably do the whole thing in
>> C. The pain of the parsing is likely to be considerably less
>> than the pain of integrating C and Perl.
cc> We don't know what will happen to the data.
The OP has informed us that it's going to be processed by C code, so we
do, in fact, know what will happen to the data.
cc> Maybe the OP would be better off using Perl for the entire app
cc> rather than integrating C and Perl.
Maybe he would; but that's a separate question.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Fri, 08 May 2009 08:48:05 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: writing get_script()
Message-Id: <1uk8059slakhk4obuvr851titbqcvku8st@4ax.com>
Charlton Wilbur <cwilbur@chromatico.net> wrote:
>>>>>> "cc" == ccc31807 <cartercc@gmail.com> writes:
> cc> We don't know what will happen to the data.
>
>The OP has informed us that it's going to be processed by C code, so we
>do, in fact, know what will happen to the data.
And even more: "[...]and then use C to
insert the data into a binary tree."
> cc> Maybe the OP would be better off using Perl for the entire app
> cc> rather than integrating C and Perl.
>
>Maybe he would; but that's a separate question.
True. However there is no reason why not to build a binary tree in Perl.
jue
------------------------------
Date: Fri, 8 May 2009 16:03:54 -0700
From: Franken Sense <frank@example.invalid>
Subject: Re: writing get_script()
Message-Id: <16fd0fseqdd46.18gn65ijp75yb.dlg@40tude.net>
In Dread Ink, the Grave Hand of Jürgen Exner Did Inscribe:
> Charlton Wilbur <cwilbur@chromatico.net> wrote:
>>>>>>> "cc" == ccc31807 <cartercc@gmail.com> writes:
>> cc> We don't know what will happen to the data.
>>
>>The OP has informed us that it's going to be processed by C code, so we
>>do, in fact, know what will happen to the data.
>
> And even more: "[...]and then use C to
> insert the data into a binary tree."
The task is motivated by §11-12 in _C Unleashed_, wherein Heathfield uses a
binary tree to remove duplicate lines in a text. That turns out to be
pretty straightforwardto implement, and I was able to do that following the
development in K&R § 6 and the solns in the clc wiki.
>
>> cc> Maybe the OP would be better off using Perl for the entire app
>> cc> rather than integrating C and Perl.
>>
>>Maybe he would; but that's a separate question.
>
> True. However there is no reason why not to build a binary tree in Perl.
>
> jue
Is there a module for it?
--
Frank
No Child Left Behind is the most ironically named act, piece of legislation
since the 1942 Japanese Family Leave Act.
~~ Al Franken, in response to the 2004 SOTU address
------------------------------
Date: Fri, 8 May 2009 16:23:37 -0700
From: Franken Sense <frank@example.invalid>
Subject: Re: writing get_script()
Message-Id: <xeblcmfvi0jr.1o3ucnqb70n0g$.dlg@40tude.net>
In Dread Ink, the Grave Hand of Jürgen Exner Did Inscribe:
> Franken Sense <frank@example.invalid> wrote:
>>2) Remove the newline when not at the end of a verse.
>
> May I suggest a different structure for your data?
> Change the input_record_separator $/ into two consecutive newlines. Then
> the whole verse will be read as a single unit, allowing you to
> a) extract the numbers without worrying about if you are looking at a
> first line or follow-up line within the same verse
> b) blindly remove all newlines from within the verse and add whatever
> number you like at its end
$/ The input record separator, newline by default. This influences
Perl's idea of what a "line" is. Works like awk's RS variable,
including treating empty lines as a terminator if set to the
null string. (An empty line cannot contain any spaces or tabs.)
You may set it to a multi-character string to match a
multi-character terminator, or to "undef" to read through the
end of file. Setting it to "\n\n" means something slightly
different than setting to "", if the file contains consecutive
empty lines. Setting to "" will treat two or more consecutive
empty lines as a single empty line. Setting to "\n\n" will
blindly assume that the next input character belongs to the
next
paragraph, even if it's a newline. (Mnemonic: / delimits line
boundaries when quoting poetry.)
local $/; # enable "slurp" mode
local $_ = <FH>; # whole file now here
s/\n[ \t]+/ /g;
Remember: the value of $/ is a string, not a regex. awk has to
be better for something. :-)
Setting $/ to a reference to an integer, scalar containing an
integer, or scalar that's convertible to an integer will
attempt
to read records instead of lines, with the maximum record size
being the referenced integer. So this:
local $/ = \32768; # or \"32768", or \$var_containing_32768
open my $fh, $myfile or die $!;
local $_ = <$fh>;
will read a record of no more than 32768 bytes from FILE. If
you're not reading from a record-oriented file (or your OS
doesn't have record-oriented files), then you'll likely get a
full chunk of data with every read. If a record is larger than
the record size you've set, you'll get the record back in
pieces.
On VMS, record reads are done with the equivalent of "sysread",
so it's best not to mix record and non-record reads on the same
file. (This is unlikely to be a problem, because any file you'd
want to read in record mode is probably unusable in line mode.)
Non-VMS systems do normal I/O, so it's safe to mix record and
non-record reads of a file.
See also "Newlines" in perlport. Also see $..
This seems to be exactly what I need.
> Why? You can build binary trees in Perl, no problem.
>
> jue
I'd like to give it a try.
--
Frank
Drug war, well, as Rush Limbaugh said, anyone who uses drugs illegally
should be prosecuted and put away. I don't agree with him; I think they
should be treated, but that's what Rush believes and so, you know, we're
praying for Rush because he's in recovery and you take responsibilities for
your actions so I'm sure any day now Rush will demand to be put away for
the maximum sentence and ask for the most dangerous prison and we'll be
praying for maybe an African American cellmate who saw the Donovan McNabb
comments on ESPN. So we're prayin'.
~~ Al Franken, Book TV, on Rush Limbaugh's illegal drug arrest and racist
remarks
------------------------------
Date: Fri, 8 May 2009 16:27:51 -0700
From: Franken Sense <frank@example.invalid>
Subject: Re: writing get_script()
Message-Id: <zz2ewd4y8jhq.e8odpwvmo0dw$.dlg@40tude.net>
In Dread Ink, the Grave Hand of Ben Morrow Did Inscribe:
>> How do I make a single input record to be what lies between the ##:###:###
>> ?
>
> $/ = "";
Thanks, Ben, so far so good:
use strict;
use warnings;
# open input file
my $filename = 'text43.txt';
open(my $fh, '<', $filename) or
die "cannot open $filename for reading: $!";
# open output file
my $filename2 = 'outfile10.txt';
open(my $gh, '>', $filename2) or
die "cannot open $filename2 for writing: $!";
# process all lines in input file
$/ = "";
while( my $line = <$fh> ) {
chomp($line);
my @s = split /\s+/, $line;
# modify fields
$s[1] =~ s/1/9/;
$s[9] =~ s/m/xxx/;
# print modified fields
for my $i (0..$#s) {
print "s[$i] = $s[$i]\n";
}
# write modified fields to output file
my $outline = join(' ', @s);
print $gh "$outline\n";
}
# close input and output files
close($gh) or die("Error closing $filename2: $!");
close($fh) or die("Error closing $filename: $!");
__END__
# perl m2.pl
abridged output:
s[0] = 44:028:022
s[1] = But
s[2] = we
s[3] = desire
s[4] = to
s[5] = hear
s[6] = of
s[7] = thee
s[8] = what
s[9] = thou
s[10] = thinkest:
s[11] = for
s[12] = as
s[13] = concerning
s[14] = this
s[15] = sect,
s[16] = we
s[17] = know
s[18] = that
s[19] = every
s[20] = where
s[21] = it
s[22] = is
s[23] = spoken
s[24] = against.
s[0] = 44:028:023
s[1] = And
s[2] = when
s[3] = they
s[4] = had
s[5] = appointed
s[6] = him
s[7] = a
s[8] = day,
s[9] = there
s[10] = came
s[11] = many
s[12] = to
s[13] = him
s[14] = into
s[15] = his
s[16] = lodging;
s[17] = to
s[18] = whom
s[19] = he
s[20] = expounded
s[21] = and
s[22] = testified
s[23] = the
s[24] = kingdom
s[25] = of
s[26] = God,
s[27] = persuading
s[28] = them
s[29] = concerning
s[30] = Jesus,
s[31] = both
s[32] = out
s[33] = of
s[34] = the
s[35] = law
s[36] = of
s[37] = Moses,
s[38] = and
s[39] = out
s[40] = of
s[41] = the
s[42] = prophets,
s[43] = from
s[44] = morning
s[45] = till
s[46] = evening.
C:\MinGW\source>
question: Can you tell me exactly why this
$/ = "";
gets rid of the newlines and s[0] is the chapter and verse?
--
Frank
I do personal attacks only on people who specialize in personal attacks..
~~ Al Franken, Playboy interview
------------------------------
Date: Fri, 08 May 2009 19:06:51 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: writing get_script()
Message-Id: <87r5yz42k4.fsf@quad.sysarch.com>
>>>>> "FS" == Franken Sense <frank@example.invalid> writes:
FS> In Dread Ink, the Grave Hand of Ben Morrow Did Inscribe:
>>> How do I make a single input record to be what lies between the ##:###:###
>>> ?
>>
>> $/ = "";
FS> Thanks, Ben, so far so good:
FS> use strict;
FS> use warnings;
FS> # process all lines in input file
FS> $/ = "";
FS> while( my $line = <$fh> ) {
FS> chomp($line);
chomp removes what is in $/ and you set it to '' (paragraph mode) so it
becomes a no-op here.
FS> my @s = split /\s+/, $line;
don't use single letter variable names. choosing good names are very
important for maintainable code. even in throwaway scripts like this
FS> # modify fields
FS> $s[1] =~ s/1/9/;
FS> $s[9] =~ s/m/xxx/;
FS> # print modified fields
FS> for my $i (0..$#s) {
why loop over the indices when you only print each element?
FS> print "s[$i] = $s[$i]\n";
print "s[$i] = $_\n" for @s ;
FS> # write modified fields to output file
FS> my $outline = join(' ', @s);
FS> print $gh "$outline\n";
arrays interpolated into strings are separated by space. so you can do
this:
print $gh "$s\n";
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Fri, 08 May 2009 16:19:58 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: writing get_script()
Message-Id: <l1f905parbb729jj029ea7r14g31jaiv6a@4ax.com>
Franken Sense <frank@example.invalid> wrote:
>In Dread Ink, the Grave Hand of Jürgen Exner Did Inscribe:
>> And even more: "[...]and then use C to
>> insert the data into a binary tree."
>
>The task is motivated by §11-12 in _C Unleashed_, wherein Heathfield uses a
>binary tree to remove duplicate lines in a text.
Oh, well, aehmmmm, unless you want to do that as a learning excercise
there is a _MUCH_ better method in Perl, see 'perldoc -q duplicate':
"How can I remove duplicate elements from a list or array?"
in particular the very last sentence.
>That turns out to be
>pretty straightforwardto implement, and I was able to do that following the
>development in K&R § 6 and the solns in the clc wiki.
In Perl you just put each line into a hash (as keys) and the semantics
of a hash will automatically eliminate all duplicates.
>> True. However there is no reason why not to build a binary tree in Perl.
>
>Is there a module for it?
A quick search for 'Binary Tree" on CPAN returns several hundred
results, the very first on being "Tree::Binary" with many more
interesting modules on the same and the next page.
jue
------------------------------
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 2403
***************************************