[31375] in Perl-Users-Digest
Perl-Users Digest, Issue: 2627 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 8 21:09:38 2009
Date: Thu, 8 Oct 2009 18:09:19 -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, 8 Oct 2009 Volume: 11 Number: 2627
Today's topics:
Re: [regexp] Changing lines NOT containing a pattern <azeroiu@poupidoup.com>
Re: [regexp] Changing lines NOT containing a pattern <azeroiu@poupidoup.com>
Re: [regexp] Changing lines NOT containing a pattern <tadmc@seesig.invalid>
Binary size differences between 5.8 and 5.10 <abc@def.com>
Re: Binary size differences between 5.8 and 5.10 <jurgenex@hotmail.com>
Re: Binary size differences between 5.8 and 5.10 <ben@morrow.me.uk>
Re: Binary size differences between 5.8 and 5.10 <abc@def.com>
Re: Binary size differences between 5.8 and 5.10 <abc@def.com>
Re: Binary size differences between 5.8 and 5.10 <ben@morrow.me.uk>
Re: FAQ 5.19 How can I reliably rename a file? <brian.d.foy@gmail.com>
FAQ 5.41 How do I delete a directory tree? <brian@theperlreview.com>
FAQ 8.29 Why can't my script read from STDIN after I ga <brian@theperlreview.com>
grepping thru hashref <user@example.net>
Re: grepping thru hashref <thepoet_nospam@arcor.de>
Re: grepping thru hashref <ben@morrow.me.uk>
Re: Perl and packge <bart.lateur@pandora.be>
Perl Tk Grid <f1crazed@gmail.com>
Re: Perlpod, pod2man: get ascii grave accent in ROFF \( <waterlan@xs4all.nl>
Re: sorting broken string <user@example.net>
time format +1 hour <slick.users@gmail.com>
Re: time format +1 hour <jurgenex@hotmail.com>
Re: time format +1 hour <jimsgibson@gmail.com>
Re: time format +1 hour <someone@example.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 08 Oct 2009 20:12:04 GMT
From: azrazer <azeroiu@poupidoup.com>
Subject: Re: [regexp] Changing lines NOT containing a pattern
Message-Id: <4ace4794$0$411$426a34cc@news.free.fr>
On Wed, 07 Oct 2009 15:39:45 -0700, sln wrote:
> On 06 Oct 2009 21:51:57 GMT, azrazer <azeroiu@poupidoup.com> wrote:
[...]
>
> Its moderately dificult, depending on what the overal conditions are.
> Simple lookahead is all this needs. And there are many ways to do this
> without extended regx's.
>
> -sln
> -------------------------
>
> use strict;
> use warnings;
>
> my $string = "
> 1 this WORD here; this is ok
> 2 word2 is not here; delete comment
> 3 word3 is not here either; should not see this WORD, ; delete comment
> ";
>
> #$string =~ s/^ ( (?:(?! WORD ).)* ;) .* $ /$1/xmg;
>
> $string =~
> s/
> ^ # start of new line and substitution part
>
> ( # Capture group 1
> (?: # group
> (?! WORD ) # lookahead, not 'WORD' ? Continue else Fail line
> . # capture this character
> ) * # end group, do this zero or more times ;
> # capture ';'
> ) # end Capture group 1
>
> .* # get all from ';' to the end of line
>
> $ # end of new line, substitute with $1
>
> /$1/xmg;
>
> print $string,"\n";
>
> __END__
Ha ! great, that was what i was struggling with ... look-aheads.
I actually forgot to group my pattern like this (?:(?!word).)* and did (?!
word).* which did not work...
Thanks a lot for this answer, i guess i learned a lot today :)
Best,
azra.
------------------------------
Date: 08 Oct 2009 20:19:13 GMT
From: azrazer <azeroiu@poupidoup.com>
Subject: Re: [regexp] Changing lines NOT containing a pattern
Message-Id: <4ace4941$0$29441$426a74cc@news.free.fr>
On Tue, 06 Oct 2009 19:44:20 -0500, Tad J McClellan wrote:
> azrazer <azeroiu@poupidoup.com> wrote:
>> On Tue, 06 Oct 2009 17:09:50 -0500, Tad J McClellan wrote:
>>
>> [snip]
>>>> The question is : Using a regexp (with mg flags)
>>> Errrr, there is no need for the m//m flag, since there are no ^ or $
>>> anchors in the pattern...
>> Well, since the file is slurped, m flag might help finding line
>> boundaries, isn't it ... ?
>
>
> No.
>
> m//m ONLY affects the meaning of the ^ and $ anchors.
>
> It is useless and does nothing when those anchors are not used.
Arh, sorry i think i still don't get it...
m//m affects the meanings of ^ and $ ... and allows it to be matched for
every line in the scalar variable, isn't it ?
I mean, this way, it is possible to find treat every single line present
within this variable using patterns like m/^...$/mg, then applying
changes to every line if the regexp is correctly built.
Am I wrong somewhere or did you say this for that your great pattern
works without m flag ? :)
Thanks again for the explanations,
azra
------------------------------
Date: Thu, 08 Oct 2009 16:28:02 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: [regexp] Changing lines NOT containing a pattern
Message-Id: <slrnhcslfe.tld.tadmc@tadmc30.sbcglobal.net>
azrazer <azeroiu@poupidoup.com> wrote:
> On Tue, 06 Oct 2009 19:44:20 -0500, Tad J McClellan wrote:
>
>> azrazer <azeroiu@poupidoup.com> wrote:
>>> On Tue, 06 Oct 2009 17:09:50 -0500, Tad J McClellan wrote:
>>>
>>> [snip]
>>>>> The question is : Using a regexp (with mg flags)
>>>> Errrr, there is no need for the m//m flag, since there are no ^ or $
>>>> anchors in the pattern...
>>> Well, since the file is slurped, m flag might help finding line
>>> boundaries, isn't it ... ?
>>
>>
>> No.
>>
>> m//m ONLY affects the meaning of the ^ and $ anchors.
>>
>> It is useless and does nothing when those anchors are not used.
>
> Arh, sorry i think i still don't get it...
> m//m affects the meanings of ^ and $ ... and allows it to be matched for
> every line in the scalar variable, isn't it ?
Exactly so.
> I mean, this way, it is possible to find treat every single line present
> within this variable using patterns like m/^...$/mg, then applying
> changes to every line if the regexp is correctly built.
Yes, but neither ^ nor $ is required.
Just .* without the m//s modifier is all that is needed.
> Am I wrong somewhere or did you say this for that your great pattern
> works without m flag ? :)
Exactly so once again.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Fri, 09 Oct 2009 00:16:04 +0100
From: zaphod <abc@def.com>
Subject: Binary size differences between 5.8 and 5.10
Message-Id: <UvKdnWtwFKop71PXnZ2dnUVZ8m-dnZ2d@brightview.co.uk>
I've just installed Perl 5.10.1 on OS X Leopard after backing up the original system binary. When I looked at 3 different Perl binaries I was puzzled by the huge differences in size:
- OS X 10.5 system Perl 5.8.8 = 48K
- New Perl 5.10.1 = 2628K
- MacPorts Perl 5.8.9 = 1192K
What accounts for the differences?
zaphod
------------------------------
Date: Thu, 08 Oct 2009 16:19:57 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Binary size differences between 5.8 and 5.10
Message-Id: <irssc5pomoqj3cms7hnprgpqags73ngt22@4ax.com>
zaphod <abc@def.com> wrote:
>I've just installed Perl 5.10.1 on OS X Leopard after backing up the original system binary. When I looked at 3 different Perl binaries I was puzzled by the huge differences in size:
>
>- OS X 10.5 system Perl 5.8.8 = 48K
>- New Perl 5.10.1 = 2628K
>- MacPorts Perl 5.8.9 = 1192K
>
>What accounts for the differences?
Wild guess: staticly versus dynamically linked libraries
jue
------------------------------
Date: Fri, 9 Oct 2009 00:56:12 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Binary size differences between 5.8 and 5.10
Message-Id: <spa2q6-vq82.ln1@osiris.mauzo.dyndns.org>
Quoth zaphod <abc@def.com>:
> I've just installed Perl 5.10.1 on OS X Leopard after backing up the
> original system binary.
*DON'T* do that. It is a *very* bad idea to replace the system perl on a
system like OS X or Solaris that uses perl as part of the system tools.
Install your copy somewhere else, like /usr/local or /opt/perl.
> When I looked at 3 different Perl binaries I was
> puzzled by the huge differences in size:
>
> - OS X 10.5 system Perl 5.8.8 = 48K
> - New Perl 5.10.1 = 2628K
> - MacPorts Perl 5.8.9 = 1192K
>
> What accounts for the differences?
How can we possibly tell, from here? WHat does file(1) tell you about
the binaries? What configure options did you use, and what did Apple use
(you can find out with perl -V:config_args)? Did you use a different
compiler (AFAIK gcc is the only compiler on OS X, but Apple have their
own version).
My first guess would be that Apple's perl was built with -Duseshrplib
and your perls weren't. If that's the case then you really ought to be
looking at the corresponding libperl.so, since the binary is just a
minimal loader for the library.
Ben
------------------------------
Date: Fri, 09 Oct 2009 01:05:36 +0100
From: zaphod <abc@def.com>
Subject: Re: Binary size differences between 5.8 and 5.10
Message-Id: <RoWdnW9bjovN41PXnZ2dnUVZ8q9i4p2d@brightview.co.uk>
Jürgen Exner wrote:
> zaphod <abc@def.com> wrote:
>> I've just installed Perl 5.10.1 on OS X Leopard after backing up the original system binary. When I looked at 3 different Perl binaries I was puzzled by the huge differences in size:
>>
>> - OS X 10.5 system Perl 5.8.8 = 48K
>> - New Perl 5.10.1 = 2628K
>> - MacPorts Perl 5.8.9 = 1192K
>>
>> What accounts for the differences?
>
> Wild guess: staticly versus dynamically linked libraries
>
> jue
The README.macosx suggests you're right. Any advantages in either of these options? I'm also recompiling without -arch i686 as this is a PPC Mac G5.
zaphod
------------------------------
Date: Fri, 09 Oct 2009 01:16:25 +0100
From: zaphod <abc@def.com>
Subject: Re: Binary size differences between 5.8 and 5.10
Message-Id: <IuSdnVQXxs5EHVPXnZ2dnUVZ8iFi4p2d@brightview.co.uk>
Ben Morrow wrote:
> *DON'T* do that. It is a *very* bad idea to replace the system perl on a
> system like OS X or Solaris that uses perl as part of the system tools.
> Install your copy somewhere else, like /usr/local or /opt/perl.
> My first guess would be that Apple's perl was built with -Duseshrplib
> and your perls weren't. If that's the case then you really ought to be
> looking at the corresponding libperl.so, since the binary is just a
> minimal loader for the library.
>
> Ben
>
My config args for Leopard's system Perl are:
config_args='-ds -e -Dprefix=/usr -Dccflags=-g -pipe -Dldflags= -Dman3ext=3pm -Duseithreads -Duseshrplib'
There's also:
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=define use64bitall=define uselongdouble=undef
usemymalloc=n, bincompat5005=undef
... so do I need to define these manually as well?
zaphod
------------------------------
Date: Fri, 9 Oct 2009 01:48:30 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Binary size differences between 5.8 and 5.10
Message-Id: <urd2q6-t892.ln1@osiris.mauzo.dyndns.org>
Quoth zaphod <abc@def.com>:
> Ben Morrow wrote:
> > *DON'T* do that. It is a *very* bad idea to replace the system perl on a
> > system like OS X or Solaris that uses perl as part of the system tools.
> > Install your copy somewhere else, like /usr/local or /opt/perl.
>
> > My first guess would be that Apple's perl was built with -Duseshrplib
> > and your perls weren't. If that's the case then you really ought to be
> > looking at the corresponding libperl.so, since the binary is just a
> > minimal loader for the library.
>
> My config args for Leopard's system Perl are:
> config_args='-ds -e -Dprefix=/usr -Dccflags=-g -pipe -Dldflags=
> -Dman3ext=3pm -Duseithreads -Duseshrplib'
>
> There's also:
>
> hint=recommended, useposix=true, d_sigaction=define
> usethreads=define use5005threads=undef useithreads=define
> usemultiplicity=define
> useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
> use64bitint=define use64bitall=define uselongdouble=undef
> usemymalloc=n, bincompat5005=undef
>
> ... so do I need to define these manually as well?
Well... what are you trying to achieve? If you are trying to compile a
perl suitable for use as your system perl, I would suggest you put the
proper binary back where you found it :). You should probably restore
the whole of /usr from backup, in fact, since the reinstall will have
overwritted a whole lot of other important stuff.
Otherwise: what will you be using this perl for? -Duseshrplib is usefil
if you will have several binaries linking the same libperl.so, so if you
are going to be building e.g. Vim or mod_perl against this perl, you
want it. If you aren't, it will make perl a little larger and a little
slower for no benefit. I would recommend against -Duseithreads on a Unix
system unless you know you need it, as it just makes perl slower and
there is rarely any point using Perl threads on a system with a real
fork(2). If you are building mod_perl and you omit ithreads you will
need to add -Dusemultiplicity.
The other significant options (use64bit{int,all}, usemymalloc=n) are
presumably the defaults on your system, since Apple didn't specify them.
Ben
------------------------------
Date: Thu, 08 Oct 2009 19:44:28 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 5.19 How can I reliably rename a file?
Message-Id: <081020091944289055%brian.d.foy@gmail.com>
In article <747tp6-7cq1.ln1@osiris.mauzo.dyndns.org>, Ben Morrow
<ben@morrow.me.uk> wrote:
> Quoth Keith Thompson <kst-u@mib.org>:
> >
> > How hold is File::Copy::move()? Is the "Newer versions" qualifier
> > still necessary?
>
> A little digging in http://perl5.git.perl.org/ says it was added in
> 1996. So, no.
I'll fix that up.
By the way, the perlfaq is now in Github, so anyone who wants to help
can fork and send pull requests. :)
------------------------------
Date: Thu, 08 Oct 2009 22:00:04 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 5.41 How do I delete a directory tree?
Message-Id: <Ehtzm.238547$cf6.193398@newsfe16.iad>
This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
5.41: How do I delete a directory tree?
(contributed by brian d foy)
If you have an empty directory, you can use Perl's built-in "rmdir". If
the directory is not empty (so, no files or subdirectories), you either
have to empty it yourself (a lot of work) or use a module to help you.
The "File::Path" module, which comes with Perl, has a "rmtree" which can
take care of all of the hard work for you:
use File::Path qw(rmtree);
rmtree( \@directories, 0, 0 );
The first argument to "rmtree" is either a string representing a
directory path or an array reference. The second argument controls
progress messages, and the third argument controls the handling of files
you don't have permissions to delete. See the "File::Path" module for
the details.
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Thu, 08 Oct 2009 16:00:03 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 8.29 Why can't my script read from STDIN after I gave it EOF (^D on Unix, ^Z on MS-DOS)?
Message-Id: <70ozm.78101$4t6.25352@newsfe06.iad>
This is an excerpt from the latest version perlfaq8.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
8.29: Why can't my script read from STDIN after I gave it EOF (^D on Unix, ^Z on MS-DOS)?
Some stdio's set error and eof flags that need clearing. The POSIX
module defines clearerr() that you can use. That is the technically
correct way to do it. Here are some less reliable workarounds:
1 Try keeping around the seekpointer and go there, like this:
$where = tell(LOG);
seek(LOG, $where, 0);
2 If that doesn't work, try seeking to a different part of the file
and then back.
3 If that doesn't work, try seeking to a different part of the file,
reading something, and then seeking back.
4 If that doesn't work, give up on your stdio package and use sysread.
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Thu, 08 Oct 2009 18:12:18 -0400
From: monkeys paw <user@example.net>
Subject: grepping thru hashref
Message-Id: <P_udnTVaD-Ar_lPXnZ2dnUVZ_tednZ2d@insightbb.com>
In the following code i want to grep for a number ($num) held in
%toplist_hash.
If a match is found the program should which key in %toplist_hash
contains the number. The question really boils down to how to use
grep to access an element of an array ref inside a hash
my %toplist_hash = (
'LTest' => [
'140105',
'140113',
'141007',
'20408',
'140408',
'110304',
'110609',
'160609'
],
'Friday' => [
'60403',
'140422',
'110626',
'180104',
'220202',
'90507'
],
);
$num = '60403';
for (keys %toplist_name) {
if (grep(/^$num$/, @{$toplist_hash{$_}})) {
print $_;
}
}
------------------------------
Date: Fri, 09 Oct 2009 00:21:51 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: grepping thru hashref
Message-Id: <4ace65f9$0$6557$9b4e6d93@newsspool4.arcor-online.net>
monkeys paw schrieb:
> In the following code i want to grep for a number ($num) held in
> %toplist_hash.
> If a match is found the program should which key in %toplist_hash
> contains the number. The question really boils down to how to use
> grep to access an element of an array ref inside a hash
>
> my %toplist_hash = (
> 'LTest' => [
> '140105',
> '140113',
> '141007',
> '20408',
> '140408',
> '110304',
> '110609',
> '160609'
> ],
> 'Friday' => [
> '60403',
> '140422',
> '110626',
> '180104',
> '220202',
> '90507'
> ],
> );
>
> $num = '60403';
> for (keys %toplist_name) {
> if (grep(/^$num$/, @{$toplist_hash{$_}})) {
> print $_;
> }
> }
The algorithm is quite OK, you just need to make sure that you
don't change variable names halfway down.
"toplist_hash" ne "toplist_name"
but a simple "use warnings;" would have explained the problem
to you.
_Always_ test your code with 'use strict;' and 'use warnings;'.
-Chris
------------------------------
Date: Thu, 8 Oct 2009 23:39:58 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: grepping thru hashref
Message-Id: <ua62q6-vc82.ln1@osiris.mauzo.dyndns.org>
Quoth monkeys paw <user@example.net>:
> In the following code i want to grep for a number ($num) held in
> %toplist_hash.
> If a match is found the program should which key in %toplist_hash
> contains the number. The question really boils down to how to use
> grep to access an element of an array ref inside a hash
>
> my %toplist_hash = (
> 'LTest' => [
> '140105',
<snip>
> ],
> );
>
> $num = '60403';
> for (keys %toplist_name) {
> if (grep(/^$num$/, @{$toplist_hash{$_}})) {
> print $_;
> }
> }
You have both for and grep setting $_. Since grep can't be changed, you
need to tell for to use a different variable. Also, if these are numbers
you should probably be using numeric equality (and not quoting them).
for my $k (keys %toplist_hash) {
if (grep $num == $_, @{$toplist_hash{$k}}) {
print $k;
}
}
If you know there's only one matching key, add a 'last' after the
'print' so you don't search the rest of the keys. If you are going to be
doing this at all often, build a reversed hash like
my %toplist_num;
for my $k (keys %toplist_hash) {
for my $n (@{$toplist_hash{$k}}) {
$toplist_num{$n} = $k;
}
}
so you can perform the lookup directly.
Ben
------------------------------
Date: Thu, 08 Oct 2009 19:43:44 +0200
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Perl and packge
Message-Id: <577sc5t80fg08vj8am6as7pi5juk2vcsqp@4ax.com>
cvrèak wrote:
>Can somebody explain me when use *.pm files and when uses *.pl?
Will this do?
http://perldoc.perl.org/perlmod.html
In short: there are two ways to specify files to load (require): the
special package syntax (Foo::Bar), and the plain (Unix) file path
format: "Foo/Bar.pm". The former is a special syntax that is recognized
as syntactic sugar for the latter, but only in source code. If you
specify the file as a string, or in a (scalar) variable, you *must* use
the file path format.
That's one way in which ".pm" special as a file extension. The second is
that with "use", Perl will treat Foo::Bar both as a file name (after
conversion), and as a package/class name, for which it will try to do a
"import" class method call. That's the main reason for which module
names and package names are commonly the same.
>must be classes in *.pm files?
No.
Classes are defined as packages, and package declarations can be in any
type of source files. See above as to why package and file name are
usually the same. But it's not uncommon to have extra (utility) packages
in the same source file.
--
Bart.
------------------------------
Date: Thu, 8 Oct 2009 13:54:57 -0700 (PDT)
From: f1crazed <f1crazed@gmail.com>
Subject: Perl Tk Grid
Message-Id: <8a5c2291-8a4d-46cb-af79-0ee7f7492e21@2g2000prl.googlegroups.com>
Hello,
I am new to using tk and perl. What I am trying to do below is just
get the label and text boxes to line up on the left side and top of
the mainwindow. It seems that there is some kind of padding on the
left side and top of the window that won't allow me to put widgets all
the way on the left and top of the window.
Here is the code:
#!/usr/bin/perl -w
use Tk;
use strict;
my $mw = new MainWindow(); # Main Window
$mw->geometry("400x200+500+400");
$mw->title("Learning Grid");
$mw -> Label(-text=> "hello") -> grid(-row=>0, -column=>0, -sticky =>
'w', );
my $txt = $mw-> Text(-width=>20, -height=>1)-> grid(-row=>2, -
column=>0, -sticky => 'w') ;
my $txt2 = $mw-> Text(-width=>20, -height=>1)-> grid(-row=>3, -
column=>0, -sticky => 'w');
MainLoop;
Thanks for any help!
-JD
------------------------------
Date: Thu, 08 Oct 2009 18:32:55 +0200
From: Erwin Waterlander <waterlan@xs4all.nl>
Subject: Re: Perlpod, pod2man: get ascii grave accent in ROFF \(ga.
Message-Id: <4ace1437$0$83247$e4fe514c@news.xs4all.nl>
Op 10/08/2009 04:50 PM, Erwin Waterlander schreef:
> Op 10/08/2009 03:00 PM, Ben Morrow schreef:
>> Quoth Erwin Waterlander <waterlan@xs4all.nl>:
>>> Op 10/07/2009 10:32 PM, Ben Morrow schreef:
>>>> 'Wrong' according to whom? Pod is not supposed to be a highly-specific
>>>> document creation system, it is supposed to be a quick and easy way of
>>>> documenting Perl with lots of DWIM in the formatters.
>>>>
>>>> I know you said 'don't ask', but I have to ask why you think you need
>>>> this. It sounds like you may be better served by some other markup
>>>> language.
>>> It is not indented for normal text but for unix shell script
>>> examples. There a backqoute replaced by a qoute results in a wrong
>>> script.
>>
>> Have you indented your examples, to make them into a 'verbatim
>> paragraph'? If you have, the pod formatters should be leaving backquote
>> alone (after all, it's just as special a character in Perl as in shell).
>> If they are not, you have a buggy version of whatever pod tool you are
>> using; upgrade to the latest version, and report a bug if it's still
>> there.
>>
>> Ben
>>
>
> This is the solution (also thanks to Jari Aalto):
>
> POD:
> code=`cmd` # example
>
> pod2man produces this ROFF:
> \& code=\`cmd\` # example
>
>
> An escaped backquote in ROFF, has the same output as \(ga.
>
> man 7 groff:
> \` The grave accent `; same as \(ga. Unescaped: left quote,
> backquote (ASCII 0x60).
>
>
> So now everybody who uses the man page will see an ASCII backquote.
>
> regards,
>
> Erwin
Actually the problem was that I used a too old version of pod2man. The
version shipped with RHEL4 is 1.10 (2002/07/16). This version produces
un-escaped backquotes in ROFF. A more recent version (1.16 2006)
produces correct ROFF.
Erwin
------------------------------
Date: Thu, 08 Oct 2009 17:26:10 -0400
From: monkeys paw <user@example.net>
Subject: Re: sorting broken string
Message-Id: <LI-dnXOGQc56xVPXnZ2dnUVZ_tSdnZ2d@insightbb.com>
Thanks all, the improper RE will ruin a sort, thats for sure. It was too
late to be writing code i suppose ...
> On Thu, 08 Oct 2009 01:16:19 -0400, monkeys paw <user@example.net> wrote:
>
>> If a string is broken into pieces and sorted, with four components after
>> the string break, how would it be done.
>>
>> Example:
>>
>> @list = qw(CA2009000H1 AK2009000H2 FL2009000H1 FL2009000H13 FL2009000H111);
>>
>> I would like the string to be broken like so:
>>
>> $a =~ /^(\w{2})(\d+)([A-Za-z]+)(\d+)$/;
>>
>> So we get CA, 2009000, H, 1 etc.
>>
>> The final sort should look like:
>>
>> AK2009000H2
>> CA2009000H1
>> FL2009000H1
>> FL2009000H13
>> FL2009000H111
>>
>> I was trying this for a sort block:
>> my @list = qw(AK2009000H2 CA2009000H1 FL2009000H1 FL2009000H13
>> FL2009000H111);
>>
>> @list = sort state_billnum @list;
>>
>>
>> sub state_billnum {
>> $a =~ /^(\w{2})(\d+)([A-Za-z]+)(\d+)$/;
>> my ($astt, $asession, $atype, $anum) = ($1, $2, $3, $4);
>> $b =~ /^(\w{2})(\d+)(\w+)(\d+)$/;
>> my ($bstt, $bsession, $btype, $bnum) = ($1, $2, $3, $4);
>> return
>> $astt cmp $bstt ||
>> $asession <=> $bsession ||
>> $atype cmp $btype ||
>> $anum <=> $bnum;
>> }
>>
>> But this sorts as:
>>
>> 'AK2009000H2',
>> 'CA2009000H1',
>> 'FL2009000H1',
>> 'FL2009000H111',
>> 'FL2009000H13'
>
> Ben Bullock solved it. But the explanation is..
>
> \w includes numeric. Btype was grabbing all but
> the last digit when $b is parsed (assuming just alpha
> is needed).
> Likewise, if you expect the state abbrv to
> be all alpha, it should change as well.
> Something like this.
>
> my ($astt, $asession, $atype, $anum) =
> $a =~ /^([a-z]{2})(\d+)([a-z]+)(\d+)$/i;
>
> my ($bstt, $bsession, $btype, $bnum) =
> $b =~ /^([a-z]{2})(\d+)([a-z]+)(\d+)$/i;
>
> -sln
------------------------------
Date: Thu, 8 Oct 2009 15:56:51 -0700 (PDT)
From: Slickuser <slick.users@gmail.com>
Subject: time format +1 hour
Message-Id: <896889cd-90e1-4602-9775-fc465f7bf1fa@z3g2000prd.googlegroups.com>
I have this value:
20091008155222
YYYY_MM_DD_HH_MM_SS
Is there any module out there if I add 1 hour to my current timestamp,
it will also roll over to DD, MM, and year if possible.
This might happen at 23 hours (0-23), 0-6 days, 0-12 months..
I can put a lot of "if" statement but have to do all possible case.
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime(time);
$mon += 1;
$year += 1900;
## add on a 0 if less than 10
if ($mon < 10) {
$mon = "0" . $mon;
}
if ($mday < 10) {
$mday = "0" . $mday;
}
if ($hour < 10) {
$hour = "0" . $hour;
}
if ($min < 10) {
$min = "0" . $min;
}
my $timenow = "$year$mon$mday$hour$min$sec\n";
print $timenow;
------------------------------
Date: Thu, 08 Oct 2009 16:16:21 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: time format +1 hour
Message-Id: <gjssc5l1aqret9tciq1m8us5vadqq93k04@4ax.com>
Slickuser <slick.users@gmail.com> wrote:
>I have this value:
>20091008155222
>YYYY_MM_DD_HH_MM_SS
>
>Is there any module out there if I add 1 hour to my current timestamp,
>it will also roll over to DD, MM, and year if possible.
>This might happen at 23 hours (0-23), 0-6 days, 0-12 months..
>
> my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
>localtime(time);
What's wrong with a simple
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)
= localtime(time + 3600);
jue
------------------------------
Date: Thu, 08 Oct 2009 16:31:08 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: time format +1 hour
Message-Id: <081020091631086729%jimsgibson@gmail.com>
In article
<896889cd-90e1-4602-9775-fc465f7bf1fa@z3g2000prd.googlegroups.com>,
Slickuser <slick.users@gmail.com> wrote:
> I have this value:
> 20091008155222
> YYYY_MM_DD_HH_MM_SS
>
> Is there any module out there if I add 1 hour to my current timestamp,
> it will also roll over to DD, MM, and year if possible.
> This might happen at 23 hours (0-23), 0-6 days, 0-12 months..
>
> I can put a lot of "if" statement but have to do all possible case.
>
>
> my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
> localtime(time);
> $mon += 1;
> $year += 1900;
>
> ## add on a 0 if less than 10
> if ($mon < 10) {
> $mon = "0" . $mon;
> }
> if ($mday < 10) {
> $mday = "0" . $mday;
> }
> if ($hour < 10) {
> $hour = "0" . $hour;
> }
> if ($min < 10) {
> $min = "0" . $min;
> }
> my $timenow = "$year$mon$mday$hour$min$sec\n";
> print $timenow;
If you are doing arithmetic on dates and times, it is best to use a
representation of a Date/Time that supports simple arithmetic. Once
such representation is "seconds-from-a-fixed-date-time", as returned by
the Perl built-in time() function. Now, your problem becomes converting
between the numeric representation and your YYYYMMDDHHMMSS format. See
the DateTime module on CPAN for some help on doing the conversions. The
module Date::Calc can also do arithmetic on dates.
--
Jim Gibson
------------------------------
Date: Thu, 08 Oct 2009 17:24:54 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: time format +1 hour
Message-Id: <rpvzm.12537$QG1.2600@newsfe23.iad>
Slickuser wrote:
> I have this value:
> 20091008155222
> YYYY_MM_DD_HH_MM_SS
>
> Is there any module out there if I add 1 hour to my current timestamp,
> it will also roll over to DD, MM, and year if possible.
> This might happen at 23 hours (0-23), 0-6 days, 0-12 months..
$ perl -le'
use POSIX qw/ mktime strftime /;
my $date = q/20091008155222/;
my ( $cent, $year, $mon, $day, $hour, $min, $sec ) = $date =~ /\d\d/g;
print strftime q/%Y%m%d%H%M%S/, localtime 3600 + mktime $sec, $min,
$hour, $day, $mon - 1, "$cent$year" - 1900;
'
20091008165222
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 2627
***************************************