[24830] in Perl-Users-Digest
Perl-Users Digest, Issue: 6981 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 9 14:06:20 2004
Date: Thu, 9 Sep 2004 11:05:06 -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 Thu, 9 Sep 2004 Volume: 10 Number: 6981
Today's topics:
another try (Darius)
Date format in perl (MES)
Re: Date format in perl <mark.clements@kcl.ac.uk>
Re: Date format in perl <nobull@mail.com>
Re: Object Oriented Perl : Query (Peter J. Acklam)
Re: Object Oriented Perl : Query (Randal L. Schwartz)
Re: Object Oriented Perl : Query (Peter J. Acklam)
Re: parsing XML using a regular expression <njc@wolfgang.uucp>
Re: Perl inconsistency <ppagee@yahoo.com>
Re: perl open function for size bigger than 2 Gig <nobull@mail.com>
Re: perl open function for size bigger than 2 Gig <gifford@umich.edu>
Re: Plotting into XML pages <nobull@mail.com>
Question <lwang@cae.wisc.edu>
Re: Question <nobull@mail.com>
Re: Shared memory for data structures <mark.clements@kcl.ac.uk>
strange output of pack in perl 5.8.0 <dotREMOVEan.halevTHISi@intANDTHISel.com>
Re: strange output of pack in perl 5.8.0 <nobull@mail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 9 Sep 2004 10:35:46 -0700
From: dmedhora@yahoo.com (Darius)
Subject: another try
Message-Id: <26a5971.0409090935.4022f9ef@posting.google.com>
Hi,
Here goes again. Please excuse the repeat question. But then, I got no
response that could be 'matched' as appropriate :)
I have many lines in a bad xml file that are like the long one below:
<word_word1 string="start" date="2004-09-02 07:33:22" id="2033878"
word_id="2000589" get_id="8647" ><word name="MOVIE"><film
title="S"things Gotta Give" the_number="531780"
/></word></word_word1><film title="S'"e Gotta Give"
the_number="531780" />
I don't want to try XML::parser yet, so, not caring about whether this
is an xml file or not, there are 2 occurences of "Gotta" in this
string and these 2
occurences need to be pre-fixed by "Somethings" between the first "=\"
just
before the "Gotta", and, the "Gotta"
So: ="S'"e Gotta Give" should become ="Somethings Gotta Give"
and ="S"things Gotta Give" should become ------ditto-----
etc.
e.g ="Something's Gotta Give" should become ="Somethings Gotta Give"
The characters before the Gotta and first =\" just before it, are not
static
so I can't use lookbehinds :( or can I?
I tried this so far:
while( $line=~/(.*)(=\")(.*?)(Gotta)/g ){
print "\n$2$3$4\n";
}
which gave me:
="S'"e Gotta
But I could't get the Gotta previous to this in the string :( and so I
am not able to repeat the while loop successfully.
Can anyone help me with this ? Thx
D
------------------------------
Date: 9 Sep 2004 09:02:41 -0700
From: mesemailoffers@verizon.net (MES)
Subject: Date format in perl
Message-Id: <332aa15a.0409090802.156681a7@posting.google.com>
I want a quick way to convert a unix date to a date in the following format:
YYYY_MM_DD_HH_MM_SS:
I currently have $date = time
Is there an easy way to convert time to the above format?
Thanks!
------------------------------
Date: Thu, 09 Sep 2004 18:58:08 +0200
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: Date format in perl
Message-Id: <41408ba1@news.kcl.ac.uk>
MES wrote:
> I want a quick way to convert a unix date to a date in the following format:
>
> YYYY_MM_DD_HH_MM_SS:
>
> I currently have $date = time
>
> Is there an easy way to convert time to the above format?
check out Date::Format, but next time you may want to check out
http://search.cpan.org before posting.
Mark
------------------------------
Date: Thu, 09 Sep 2004 18:25:56 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Date format in perl
Message-Id: <chq3n3$dan$1@slavica.ukpost.com>
MES wrote:
> I want a quick way to convert a unix date
What do you mean by a Unix date? I shall assume you mean Unix epoch
seconds.
> to a date in the following format:
> YYYY_MM_DD_HH_MM_SS:
perldoc -f localtime
------------------------------
Date: 09 Sep 2004 18:47:27 +0200
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Object Oriented Perl : Query
Message-Id: <7jr38k4g.fsf@online.no>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> Peter J. Acklam <pjacklam@online.no> wrote:
>
> > The "$class = ref($obj) || $obj;" construction is used many
> > places in the Perl docs and the Perl standard modules, so
>
> Yes. Much to the regret of some of us. It's a pretty idiom,
> and it has been propagated by well-renowned people. (I'm
> tempted to say, people who should know better :)
Personally, I have let "$obj->new" be exactly the same as
"ref($obj)->new" which wasn't even mentioned on Randal's page.
> > Anyway, if it's use is disallowed an appropriate error message
> > should be given. Maybe something like this:
> >
> > sub new {
> > my $class = shift;
> > croak "new(): not an instance method" if ref $class;
> > ...
> > }
>
> Perhaps, but only because users may have come to expect it to be
> callable that way. Basically, ->new is a class method and the
> user has no business calling it through an object. If they do,
> they may as well deal with the consequences.
Users all to often do things they have no business of doing. :-)
I think that *all* inappropriate or incorrect usage should display
a descriptive error message.
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: 09 Sep 2004 10:30:05 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Object Oriented Perl : Query
Message-Id: <86d60vpcyq.fsf@blue.stonehenge.com>
*** post for FREE via your newsreader at post.newsfeed.com ***
>>>>> "Peter" == Peter J Acklam <pjacklam@online.no> writes:
Peter> Personally, I have let "$obj->new" be exactly the same as
Peter> "ref($obj)->new" which wasn't even mentioned on Randal's page.
Uh, wrong. Read closer. Especially that nearly last paragraph
from <http://www.stonehenge.com/merlyn/UnixReview/col52.html>:
The purpose of these few lines of extra code is to permit:
my $other = $dog->new;
to act like
my $other = (ref $dog)->new;
But here's the problem. When I survey experienced object-oriented
programmers, and ask them what they expect new means when called on an
instance (without looking at the implementation), the result usually
divides rather equally into three camps: those that go ``huh, why
would you do that'' and think it should throw an error, those that say
that it would clone the object, and those that say it would copy the
object's class but not the contents.
And yes, "perltoot" has been updated in the upcoming 5.8.5 Perl, so
the lines have been approporiately "deblessed", in part due to my
ranting about it.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
-----= Posted via Newsfeed.Com, Uncensored Usenet News =-----
http://www.newsfeed.com - The #1 Newsgroup Service in the World!
-----== 100,000 Groups! - 19 Servers! - Unlimited Download! =-----
------------------------------
Date: 09 Sep 2004 19:40:49 +0200
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Object Oriented Perl : Query
Message-Id: <llfj7332.fsf@online.no>
merlyn@stonehenge.com (Randal L. Schwartz) wrote:
> *** post for FREE via your newsreader at post.newsfeed.com ***
>
> >>>>> "Peter" == Peter J Acklam <pjacklam@online.no> writes:
>
> Peter> Personally, I have let "$obj->new" be exactly the same as
> Peter> "ref($obj)->new" which wasn't even mentioned on Randal's page.
>
> Uh, wrong. Read closer. Especially that nearly last paragraph
> from <http://www.stonehenge.com/merlyn/UnixReview/col52.html>:
> [...]
Sorry, you're absolutely right.
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: Thu, 09 Sep 2004 11:18:27 -0500
From: Neil Cherry <njc@wolfgang.uucp>
Subject: Re: parsing XML using a regular expression
Message-Id: <slrnck10ii.ubu.njc@wolfgang.uucp>
On Thu, 09 Sep 2004 11:13:39 GMT, Jürgen Exner wrote:
> Leif Wessman wrote:
>> I was trying to find a general solution to parsing both HTML and
>> xml-files.
>
> That general solution would be to use a proper parser.
>> And I didn't know that regular expressions was such a bad
>> idea when parsing XML. Now I know, and now I will build a solution
>> using regular expressions for HTML and an XML-parser for the
>> XML-files.
>
> Arrrrgggggg! Have you been reading _any_ previous postings or even the FAQ
> about parsing HTML?
> "Contrary to popular believe parsing HTML correctly is close to rocket
> science and while it might be theoretically possible to parse HTML using
> extended REs no sane person would ever attempt to do so."
> For further information please see the FAQ (perldoc -q "remove HTML") and
> the numerous postings about this topic on google.
I just went through this exercise for something simple. I wanted to
remove all the comments from a bunch of files with HTML. Here's what I
found:
$upd =~ s{ <! # comments begin with a `<!'
# followed by 0 or more comments;
(.*?) # this is actually to eat up comments in non
# random places
( # not suppose to have any white space here
# just a quick start;
-- # each comment starts with a `--'
.*? # and includes all text up to and including
-- # the *next* occurrence of `--'
\s* # and may have trailing while space
# (albeit not leading white space XXX)
)+ # repetire ad libitum XXX should be * not +
(.*?) # trailing non comment text
> # up to a `>'
}{
if ($1 || $3) { # this silliness for embedded comments in tags
"<!$1 $3>";
}
}gesx; # mutate into nada, nothing, and niente
Uhm, yeah! While I'm not an expert on regex I have real trouble
comprehending the above. Even with the comments I wouldn't be able to
reuse the code to remove something else. Here's one I used to just
grab the contents between 2 specific comments:
$upd_str ='<!-- update -->'; # delimiting string
@upd = (qx(cat $file) =~ m|$upd_str(.*)$upd_str|s); # match update
Note that <!--.*--> won't work properly to find all occurances of
comments (single line solo comment, single line comment with other
html, or multi-line comments)
For anything more complicated I'll need a proper parser. I read the
'don't do it' line and initially thought it can't be that bad. Nope
they were correct, it's that bad.
--
Linux Home Automation Neil Cherry ncherry@comcast.net
http://home.comcast.net/~ncherry/ (Text only)
http://hcs.sourceforge.net/ (HCS II)
http://linuxha.blogspot.com/ My HA Blog
------------------------------
Date: Thu, 09 Sep 2004 19:42:11 +0200
From: Mike Mimic <ppagee@yahoo.com>
Subject: Re: Perl inconsistency
Message-Id: <xD00d.2538$F6.560430@news.siol.net>
Hi!
Michele Dondi wrote:
> BTW: this is one of the reasons why Perl6 is being designed to be more
> consistent (and IMHO *slightly* less magic).
It is nice to know that. Then I am waiting with impatience for Perl 6,
because I like that things are consistent (so that there are no special
cases which are that way just because they are special). If things
are not consistent you have to remember all special cases and this is
like learning irregular verbs. :-)
But it is interesting that if you try this:
open(FILE, '<file.txt');
if ($_ = <FILE>) {
print "$_\n";
}
close(FILE);
Perl complains with:
Value of <HANDLE> construct can be "0"; test with defined()
And the same could be with while(<HANDLE>).
Mike
------------------------------
Date: Thu, 09 Sep 2004 18:30:33 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: perl open function for size bigger than 2 Gig
Message-Id: <chq3vo$db3$1@slavica.ukpost.com>
Peng Yue wrote:
> open(FILE, "| cat > bigfile") is not working for cat thing whatever
> perl pass is a filename.
Since it is clear that English is not your first language it is
even more important that you try to express yourself by giving minimal
but complete Perl scripts to illustrate your point.
>
> open(FILE," | echo >> bigfile");
> print FILE "HELLO";
> is also not working. It only append new line to bigfile. Can not
> figure out why echo doesn't work
To read a description of the Unix echo command
man echo
> or any other program to try.
Well you could use dd but there's not reason why cat shouldn't work.
------------------------------
Date: Thu, 09 Sep 2004 13:32:31 -0400
From: Scott W Gifford <gifford@umich.edu>
Subject: Re: perl open function for size bigger than 2 Gig
Message-Id: <qszacvzgxg0.fsf@asteroids.gpcc.itd.umich.edu>
peng.yue@gmail.com (Peng Yue) writes:
[...]
> Scott's solution sounds simple and good. I did succeed in opening
> big file:
>
> open(FILE, "cat bigfile | ");
>
> however, I still have trouble with writing a big file. Just following
> what Scott suggests, I try to use pipe to pass parameter to other
> programs.
>
> open(FILE, "| cat > bigfile") is not working for cat thing whatever
> perl pass is a filename.
I'm not sure I understand exactly what you're saying here, but you'll
want to check whether the open command succeeded, and also the close
command. Is it printing an error now, or just not working? If it's
not working, is the file not created at all, or is it empty, or what?
Does it work when you specify a filename that doesn't exist, but not
when you specify a filename that does exist? What are permissions on
the directory you're writing into, and what's the current directory
when the cat command is started? If you run cat by hand with the same
arguments and type a few lines, what happens?
> open(FILE," | echo >> bigfile");
> print FILE "HELLO";
> is also not working. It only append new line to bigfile. Can not
> figure out why echo doesn't work or any other program to try.
echo just prints its arguments, it doesn't take input from a pipe and
print it too, so this is just echo behaving like it's supposed to.
----ScottG.
------------------------------
Date: Thu, 09 Sep 2004 18:47:45 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Plotting into XML pages
Message-Id: <chq4vv$ddo$1@slavica.ukpost.com>
Stephen Jeffrey wrote:
> I have a CGI script that uses GnuPlot to
> dynamically graph data. It works when the
> page calling the CGI script is HTML, but
> not XML.
I do not think your problem has anything to do with Perl (or CGI). To
help partition your problem try putting a static image/png entity into
your XML.
------------------------------
Date: Thu, 9 Sep 2004 10:05:55 -0700
From: "Mike" <lwang@cae.wisc.edu>
Subject: Question
Message-Id: <chq2hj$hgi$1@news01.intel.com>
Hi,
I have a question about the function rand().
Let say we have a variable $a = int (rand(50)), is there a formula that can
predict how long this random function will hit all the values from 0 to 49?
(Assume srand is set to a fixed value)
thanks,
Mike
------------------------------
Date: Thu, 09 Sep 2004 18:21:25 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Question
Message-Id: <chq3ej$dad$1@slavica.ukpost.com>
Mike wrote:
> Subject: Question
>
> I have a question about the function rand().
Please put the subject of your post in the subject of your post.
> Let say we have a variable $a = int (rand(50)), is there a formula that can
> predict how long this random function will hit all the values from 0 to 49?
> (Assume srand is set to a fixed value)
Not if the random number generator is any good.
This, of course, has nothing to do with Perl.
------------------------------
Date: Thu, 09 Sep 2004 19:02:53 +0200
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: Shared memory for data structures
Message-Id: <41408cbd$1@news.kcl.ac.uk>
Gregory Toomey wrote:
>
> If you want shared data you can use System 5 shared memory, which is
> available on just about all unixes/linux. Not sure if there is a Perl
> module that supports it though.
Cache::SharedMemoryCache
Mark
------------------------------
Date: Thu, 9 Sep 2004 18:36:17 +0300
From: "Dotan Halevi" <dotREMOVEan.halevTHISi@intANDTHISel.com>
Subject: strange output of pack in perl 5.8.0
Message-Id: <chpt9l$epi$1@news01.intel.com>
Hi all.
I had tried these two one liners over several perl distributions (perl
version 5.6 and down, OS = Linux , Solaris, Windows) and got the same GOOD
results :
___________ test #1 ___________________
$ perl -e 'print(pack("v", 0x1234))'| hexdump
0000000 1234
0000002
________________ test #2 _______________
$ perl -e 'print(pack("v", 0xabcd))'| hexdump
0000000 abcd
0000002
_____________ end ______________________
but on RedHat Linux 9.0 , whence
$ rpm -q perl
perl-5.8.0-88
Test # 2 produces these strange results :
__________ test #2 over RedHat 9.0, perl 5.8.0-88 __________
$ perl -e 'print(pack("v", 0xabcd))'| hexdump
0000000 8dc3 abc2
0000004
___________ end ________________________
What is wrong here ???
Thanks, Dotan
------------------------------
Date: Thu, 09 Sep 2004 18:42:55 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: strange output of pack in perl 5.8.0
Message-Id: <chq4mu$dcr$1@slavica.ukpost.com>
Dotan Halevi wrote:
> __________ test #2 over RedHat 9.0, perl 5.8.0-88 __________
> $ perl -e 'print(pack("v", 0xabcd))'| hexdump
> 0000000 8dc3 abc2
> 0000004
> ___________ end ________________________
>
> What is wrong here ???
It would appear that somewhere between pack() and STDOUT it's getting
utf8 encoded.
I assue that the output of pack() is a byte string but when you pass it
to a utf8 encoded filehandle it interprets the bytes of the string as
Unicode code-points.
I think this has to do with some sort of locale setting since I don't
see in on my (non-Redhat) Linux box.
I'd guess it's fixable by explicitly saying binmode(STDOUT) but I can't
check since I can't reproduce the problem.
------------------------------
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 6981
***************************************