[22236] in Perl-Users-Digest
Perl-Users Digest, Issue: 4457 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 23 18:05:58 2003
Date: Thu, 23 Jan 2003 15:05:12 -0800 (PST)
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, 23 Jan 2003 Volume: 10 Number: 4457
Today's topics:
Re: A Good Perl Developing Enviroment <keith_awcock@blueyonder.co.uk>
Re: A Good Perl Developing Enviroment (Malcolm Dew-Jones)
Checking IP Ranges in one line <charlest@indysoft.com>
Re: Checking IP Ranges in one line (Tad McClellan)
Re: Checking IP Ranges in one line <bigj@kamelfreund.de>
commenting out code <mfield@ernie.botany.ubc.ca>
Re: commenting out code <shondell@cis.ohio-state.edu>
Re: commenting out code <fm_duendeBASURA@yahoo.com>
Re: commenting out code (Jay Tilton)
Re: Converting a string to a valid date.. <bongie@gmx.net>
Re: Converting a string to a valid date.. <no_spam@fromyou.thanks-anyways.com>
Re: Converting a string to a valid date.. (Damian James)
Re: Dynamically Declaring Variables (Tad McClellan)
Re: Dynamically Declaring Variables <uri@stemsystems.com>
Re: hash of arrays using variable array names <uri@stemsystems.com>
Re: Is there a better way to check to see if a date li <mothra@nowhereatall.com>
Is there a better way to format numbers to use commas? <dragnet@internalysis.com>
Re: Is there a better way to format numbers to use comm <bongie@gmx.net>
Re: Is there a better way to format numbers to use comm <dragnet@internalysis.com>
Re: Is there a better way to format numbers to use comm <mjcarman@mchsi.com>
Re: Is there a better way to format numbers to use comm <bongie@gmx.net>
Re: Is there a better way to format numbers to use comm <uri@stemsystems.com>
Need a Perl Programmer (Grayson Bathgate)
Re: Need a Perl Programmer (Tad McClellan)
Re: Need a Perl Programmer <uri@stemsystems.com>
Re: parse scalar into array (Jay Tilton)
Re: parse scalar into array <bigj@kamelfreund.de>
Perl Batch Job without DOS window popup (Dominik)
Perl Batch Job without start of a DOS box (Dominik)
Re: Perl Batch Job without start of a DOS box <charlest@indysoft.com>
Re: Problem printing January "The Perl Journal" (Justin Masters - remove at to reply)
Re: Regex: optional word boundary (Sara)
Re: Regex: optional word boundary (Tad McClellan)
Re: slow grep <mpapec@yahoo.com>
Re: slow grep <mpapec@yahoo.com>
Re: unlink() (Jay Tilton)
Re: unlink() (Jay Tilton)
video grab problem with Video::Capture::V4l <peterv@delete.catuity.com.au>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 23 Jan 2003 21:10:03 -0000
From: "Keith Awcock" <keith_awcock@blueyonder.co.uk>
Subject: Re: A Good Perl Developing Enviroment
Message-Id: <yRYX9.482$9V2.141@news-binary.blueyonder.co.uk>
>
>Fellow Perl Netters:
>
>I have a newbie question:
>
>What would be a good Perl Developing Enviroment for
>managing and developing Perl projects?
>
I use emacs, for two reasons
I use the same setup for windows and linux
it integrates the debugger in a way I like
Actually the primary reason is someone else recommended it to me, it works
so I use it and I don't have time/money to muck about. If you have some cash
that mozilla based ide from ActiveState is very nice is you are after an
ide.
------------------------------
Date: 23 Jan 2003 14:58:25 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: A Good Perl Developing Enviroment
Message-Id: <3e307391@news.victoria.tc.ca>
Tony L. Svanstrom (tony@svanstrom.com) wrote:
: A. Fuentes <alvarof2@hotmail.com> wrote:
: > Fellow Perl Netters:
: >
: > I have a newbie question:
: >
: > What would be a good Perl Developing Enviroment for
: > managing and developing Perl projects?
: My favorite is Pico. =)
pico, plus a few keyboard macros in a terminal emulator, makes a fine
editing system if all else fails.
Personally I open three windows. In one window I run my favourite editor,
or what ever is available, in another window I run commands such as a
compiler. Command line recall makes the reuse of commands very easy. The
third window is used for anything else so as not to mess up the
environment of the first two windows, and/or to view online documentation.
This system is available on virtually any system, linux console,
linux/unix via an emulator from another system, windows, x-windows, VMS
via various access methods, etc, including other peoples computers on
which you don't/can't install something else. It works with virtually
any type of project (perl, C, SQL, etc). (Solaris anyone? as long as you
have x-windows or access it via an emulator...)
Combine the above with a project specific readme file full of useful
commands and notes to yourself, and cvs or rcs (or even just a batch file
to make online backups) and you have a fine enough IDE for almost any
project.
------------------------------
Date: Thu, 23 Jan 2003 14:37:14 -0500
From: "Charles R. Thompson" <charlest@indysoft.com>
Subject: Checking IP Ranges in one line
Message-Id: <v30h3b9igr2g90@corp.supernews.com>
There is mention of this in various posts, and I even question it in a
recent post, but have broken it off here for clarity. Is it possible to
match a range of numbers located in a string with a one line regexp? Using
IPs as an example... keep in mind we aren't looking to see if this is a
valid IP, etc ad nauseum that's not what this thread should be about... How
might one go about checking a provided IP to see if set of numbers matches
a range?
example...
Given this regexp: ^64.(152|153|154|155|156|157|158|159).(.*?)$
-or-
if ($ipblock =~ /^64.(152|153|154|155|156|157|158|159).(.*?)$/) { # do
stuff }
easily matches
64.152.0.0 through 64.159.255.255
How can it be modified in the same one line regexp to do without the
excessive or'ing? Is this a job for backreferencing?
CT
------------------------------
Date: Thu, 23 Jan 2003 16:23:33 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Checking IP Ranges in one line
Message-Id: <slrnb30qr5.brq.tadmc@magna.augustmail.com>
Charles R. Thompson <charlest@indysoft.com> wrote:
> How
> might one go about checking a provided IP to see if set of numbers matches
> a range?
You wouldn't.
Regexs are for working on _strings_, you should use numeric
operators for working on numbers (though you may need a regex
to pluck out the numberish parts).
> is this a job for backreferencing?
No, it is a job for > and/or < :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 23 Jan 2003 22:34:12 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Checking IP Ranges in one line
Message-Id: <pan.2003.01.23.21.13.58.175342@kamelfreund.de>
On Thu, 23 Jan 2003 14:37:14 +0000, Charles R. Thompson wrote:
> Given this regexp: ^64.(152|153|154|155|156|157|158|159).(.*?)$
> -or-
> if ($ipblock =~ /^64.(152|153|154|155|156|157|158|159).(.*?)$/) { # do
> stuff }
>
> easily matches
> 64.152.0.0 through 64.159.255.255
>
> How can it be modified in the same one line regexp to do without the
> excessive or'ing? Is this a job for backreferencing?
What's about
/^64.(15[2-9]).(.*)/
Note, that I removed the ? and the $ at the end of the regexp. It doesn't
make sense to capture characters as less as possible if the matching has
to go to the end. And the $ is unnecessary as normal .* is greedy enough
to go to the end.
Greetings,
Janek
------------------------------
Date: Thu, 23 Jan 2003 14:18:05 -0800
From: mfield <mfield@ernie.botany.ubc.ca>
Subject: commenting out code
Message-Id: <3E306A1D.BB777F53@ernie.botany.ubc.ca>
I was wondering if there is an easy way to comment out large sections of
code in perl (using emacs) without commenting out the lines
individually. Thanks in advance
------------------------------
Date: 23 Jan 2003 17:25:14 -0500
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: commenting out code
Message-Id: <xcwwukvv705.fsf@psi.cis.ohio-state.edu>
mfield <mfield@ernie.botany.ubc.ca> writes:
> I was wondering if there is an easy way to comment out large sections of
> code in perl (using emacs) without commenting out the lines
> individually. Thanks in advance
Embedded POD.
perldoc -q "comment out"
--
Ryan Shondell <shondell@cis.ohio-state.edu>
------------------------------
Date: Thu, 23 Jan 2003 22:27:09 GMT
From: monkeys paw <fm_duendeBASURA@yahoo.com>
Subject: Re: commenting out code
Message-Id: <1%ZX9.10876$4y2.1198@sccrnsc04>
mfield wrote:
> I was wondering if there is an easy way to comment out large sections of
> code in perl (using emacs) without commenting out the lines
> individually. Thanks in advance
=comment
lotsa code...
=cut
------------------------------
Date: Thu, 23 Jan 2003 22:44:58 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: commenting out code
Message-Id: <3e30703e.60029751@news.erols.com>
mfield <mfield@ernie.botany.ubc.ca> wrote:
: I was wondering if there is an easy way to comment out large sections of
: code in perl (using emacs) without commenting out the lines
: individually.
You might find Acme::Comment interesting.
------------------------------
Date: Thu, 23 Jan 2003 20:19:08 +0100
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: Converting a string to a valid date..
Message-Id: <1213731.4IvXHQthlP@nyoga.dubu.de>
Bullet wrote:
> Does this example really mean that PERL really treats all arrays as
> hashes with numeric keys? Hmmm.. ?
No, not at all, as already pointed out by others.
And this big difference can give a good reason to use a hash, even if
you only need integer indices:
---------- snip ----------
#!/usr/bin/perl
# need an indexed structure with entries at 1, 10, and 100'000'000...
# using an array:
my @array;
$array[1] = 'foo'; # no problem here
$array[10] = 'bar'; # neither here
$array[100_000_000] = 'baz'; # WARNING! See perl eat your memory
# like popcorn!
# using a hash:
my %hash;
$hash{1} = 'foo';
$hash{10} = 'bar';
$hash{100_000_000} = 'baz'; # no problem here - phew!
---------- snap ----------
Anyone else wanting sparse arrays? ;-)
Ciao,
Harald
--
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
"We must be the change we wish to see"
-- Mahatma Gandhi
------------------------------
Date: Thu, 23 Jan 2003 19:41:41 GMT
From: "Bullet" <no_spam@fromyou.thanks-anyways.com>
Subject: Re: Converting a string to a valid date..
Message-Id: <VzXX9.11783$aO2.3108202539@newssvr10.news.prodigy.com>
Thanks for the clear explanations guys.. that explains a lot..
I guess its not too surprising I didnt know what they were since my Perl
book doesnt discuss them at all..
I guess that means its finally time for a new PERL book .. but I should have
known that already
considering mine talks about how you should really upgrade to the newest
version.. 5.002 LOL
I did buy it in 1996 however. .so I guess I got my mileage out of it..
------------------------------
Date: 23 Jan 2003 23:03:55 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Converting a string to a valid date..
Message-Id: <slrnb30t6r.7hg.damian@puma.qimr.edu.au>
On Thu, 23 Jan 2003 19:41:41 GMT, Bullet said:
>Thanks for the clear explanations guys.. that explains a lot..
>
>I guess its not too surprising I didnt know what they were since my Perl
>book doesnt discuss them at all..
>
>I guess that means its finally time for a new PERL book .. but I should have
>known that already
>considering mine talks about how you should really upgrade to the newest
>version.. 5.002 LOL
Keep in mind that the authoritative text for all Perl issues is the
online documentation that comes for free with perl itself. This is
what Tad and Anno both were referring you to above. I can't stress
enough that, once you have spent some time becoming familiar with the
language, and a book is a great help for this, you should eventually
spend some time at least reading through perldata, perlvar, perlrun,
perlref, perldsc, perlop, perlfunc and perlfaq. You can access any of
these with the perldoc command, and even search the last two.
>I did buy it in 1996 however. .so I guess I got my mileage out of it..
Well, you *could* get yourself a 3rd edition Camel book...
--damian
------------------------------
Date: Thu, 23 Jan 2003 13:31:46 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Dynamically Declaring Variables
Message-Id: <slrnb30gp2.b94.tadmc@magna.augustmail.com>
Dave Fraleigh <dave@fraleigh.net> wrote:
> Subject: Dynamically Declaring Variables
I suggest you do your best to find a way of getting your job
done without declaring variables dynamically.
> I'm trying to write a statement that will take values read from a
> config file and declare variables based on these values...
I suggest you declare _hash keys_ instead of variables.
> I'm trying to force my script to generate a variable called
> "%subjectsTestHash" which contains the hash value tossed by a function
> "theFunction()".
How about having your program instead generate a hash key called
"subjectsTestHash" whose value is a hash?
my %vars; # my own private "symbol table"
$vars{ subjectsTestHash } = {}; # empty anon hash as value
or
$vars{ subjectsTestHash } = { theFunction() };
or, if theFunction() returns a hash ref rather than a flattened out
list of key/value pairs:
$vars{ subjectsTestHash } = theFunction();
> So, in short, does anybody know how to dynamically create variables
> based on values stored in other variables?
Yes.
> If so, how?
I'm not going to tell you, because it can hurt you, and
you do not need it.
See also:
http://www.plover.com/~mjd/perl/varvarname.html
http://www.plover.com/~mjd/perl/varvarname2.html
http://www.plover.com/~mjd/perl/varvarname3.html
> Please reply via email.
Why do you want to hoard answers?
That is not very community-minded, some might say it is outright selfish.
Why not share the answers here so everyone can see them?
Ask it here, get the answer here (maybe).
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 23 Jan 2003 20:30:13 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Dynamically Declaring Variables
Message-Id: <x7el73pq23.fsf@mail.sysarch.com>
>>>>> "DF" == Dave Fraleigh <dave@fraleigh.net> writes:
DF> I'm trying to write a statement that will take values read from a
DF> config file and declare variables based on these values...
DF> I'm trying to force my script to generate a variable called
DF> "%subjectsTestHash" which contains the hash value tossed by a function
DF> "theFunction()".
WHY?
DF> So, in short, does anybody know how to dynamically create variables
DF> based on values stored in other variables?
DF> If so, how?
there is no reason for you to do it. i just posted a polemic about the
evils of symbolic references. creating symbols like that with eval is
just as bad. go look for the other post and read it.
DF> Thanks very much. Please reply via email.
post here read here.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Thu, 23 Jan 2003 19:37:34 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: hash of arrays using variable array names
Message-Id: <x7iswfpshu.fsf@mail.sysarch.com>
>>>>> "BM" == Brian McCauley <nobull@mail.com> writes:
BM> Uri Guttman <uri@stemsystems.com> writes:
>> >>>>> "q" == qanda <fumail@freeuk.com> writes:
>>
q> Hi all, the following script appears to work (but only if I turn off
q> strict). I'm still learning, so can anyone tell me if anything is
q> particularly bad about this, could it be done more elegantly? The
q> objective is to pass a string into a function that can then be used to
q> load an array with certain records.
>>
>> ok, i now have a chance to use my new polemic about the evils of
>> symrefs. enjoy!
BM> Actually if you look carefully you'll see the OP wasn't, despite what
BM> he said in the suject line, trying to use symbolic references.
BM> I'd got fairly far into expounding the evils of symbolic references
BM> before I realised this.
i just read the opening paragraph and didn't even bother with the
code. i just wanted a frssh reason to publish that polemic. :)
doing that is helping me refine the reasoning of why symrefs are evil.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Thu, 23 Jan 2003 12:35:21 -0800
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: Is there a better way to check to see if a date lies within a certain range of dates
Message-Id: <3e305135$1@usenet.ugs.com>
[snipped]
> SORRY...that should be
> if ( Date_Cmp($start_date, $_) < 0 &&
> Date_Cmp($_, $end_date) < 0)
>
Great!! That was what I was looking for!!
Thanks
Mothra
------------------------------
Date: Thu, 23 Jan 2003 21:11:53 GMT
From: Marc Bissonnette <dragnet@internalysis.com>
Subject: Is there a better way to format numbers to use commas?
Message-Id: <Xns930CA56513669dragnetinternalysisc@206.172.150.13>
Hi all;
I've got some output that a client insists be formatted with commas every
three characters. The code below works perfectly, as far as I can tell,
but I am wondering if I just went overboard in how I did it - is there a
simpler way than the following to turn 1234567890 into 1,234,567,890 ?
Working code follows:
###############################################################
#!/usr/bin/perl -w
use strict;
# test number to be formatted
my $number=1234567891011;
# get the length of the number to be formatted
my $numlength= length $number;
# find out how many three digit groups are in the number to be formatted
my $quotient = int($numlength/3);
# get the first, non-three digit group from the number to be formatted
my $remainder = $numlength%3;
# get the starting postition to do a substr on
my $placetoselect=$remainder;
my $formattednum=substr $number,0,$placetoselect;
# add the first comma
$formattednum.=',';
# for each three-char group of numerals in the number to be formatted,
# add it to $formatternum and add a comma
while ($quotient > 0) {
$formattednum.=substr $number,$placetoselect,3;
$formattednum.=',';
# set the substr counter to the next group of three chars
$placetoselect = $placetoselect+3;
# one less group of numbers to grab
--$quotient;
}
# get rid of the trailing comma
chop $formattednum;
print "Orig Number: $number\nQuotient: $quotient\nRemainder: $remainder
\n";
print "Formatted Number: $formattednum\n";
###############################################################
Outputs:
Orig Number: 1234567891011
Quotient: 0
Remainder: 1
Formatted Number: 1,234,567,891,011
Many thanks for comments or insight.
--
Marc Bissonnette
Perl CGI. MySQL Databases. Dynamic Web Content Control.
http://www.internalysis.com
Looking for a new ISP? http://www.canadianisp.com
------------------------------
Date: Thu, 23 Jan 2003 22:33:15 +0100
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: Is there a better way to format numbers to use commas?
Message-Id: <2445168.9nIL9k8Hjm@nyoga.dubu.de>
Marc Bissonnette wrote:
> - is there a simpler way than the following to turn 1234567890 into
> 1,234,567,890 ?
Oh, yes! ;-)
See perldoc -q 'with commas':
How can I output my numbers with commas added?
Ciao,
Harald
--
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Face it, Bill Gates is a Persian cat and a monocle away from being
a villain in a James Bond movie. -- Dennis Miller
------------------------------
Date: Thu, 23 Jan 2003 21:47:42 GMT
From: Marc Bissonnette <dragnet@internalysis.com>
Subject: Re: Is there a better way to format numbers to use commas?
Message-Id: <Xns930CAB77196DBdragnetinternalysisc@206.172.150.13>
"Harald H.-J. Bongartz" <bongie@gmx.net> wrote in
news:2445168.9nIL9k8Hjm@nyoga.dubu.de:
> Marc Bissonnette wrote:
>> - is there a simpler way than the following to turn 1234567890 into
>> 1,234,567,890 ?
>
> Oh, yes! ;-)
>
> See perldoc -q 'with commas':
> How can I output my numbers with commas added?
Wow, thanks - That's one of those (for me, anyways) "black box" type of
solutions where I get a brain-ache trying to comprehend what the command
is doing (for those who don't look it up in perldoc, my big massive hunk
of code can be replaced with:
$number=1234567891011;
$number=~s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g;
print "$number\n";
Thank you very much for pointing that out for me!
--
Marc Bissonnette
Perl CGI. MySQL Databases. Dynamic Web Content Control.
http://www.internalysis.com
Looking for a new ISP? http://www.canadianisp.com
------------------------------
Date: Thu, 23 Jan 2003 16:24:56 -0600
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: Is there a better way to format numbers to use commas?
Message-Id: <b0pq3q$tr73@onews.collins.rockwell.com>
On 1/23/03 3:47 PM, Marc Bissonnette wrote:
> "Harald H.-J. Bongartz" <bongie@gmx.net> wrote in
> news:2445168.9nIL9k8Hjm@nyoga.dubu.de:
>
>> Marc Bissonnette wrote:
>>> - is there a simpler way than the following to turn 1234567890 into
>>> 1,234,567,890 ?
>>
>> Oh, yes! ;-)
>>
>> See perldoc -q 'with commas':
>> How can I output my numbers with commas added?
>
> Wow, thanks - That's one of those (for me, anyways) "black box" type of
> solutions where I get a brain-ache trying to comprehend what the command
> is doing (for those who don't look it up in perldoc, my big massive hunk
> of code can be replaced with:
>
> $number=1234567891011;
> $number=~s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g;
> print "$number\n";
/x to the rescue!
s/( # begin capture to $1
^ # at the beginning of the string
[-+]? # match an optional sign
\d+? # one or more digits (maybe)
(?= # look ahead for (but don't match!):
(?> # an atomic group (no backtracking) of
(?:\d{3})+ # one or more sets of 3 digits
) # end atomic grouping
(?!\d) # that isn't followed by a digit
) # end lookahead
| # match what's above OR what's below
\G # start at the end of the last match
\d{3} # three digits
(?=\d) # that are followed by other digits
) # end capture to $1
/$1,/xg # replace by the value of "$1," -- repeat
That tells you *what* it's doing. As for *how*... the first part of the
alternation (everything before the '|') is to match any leading digits
that are followed by an integer multiple of three digits. Everything
after the '|' is taken in chunks of three digits as long as it's not the
last chunk. Whatever matches has a comma appended. The /g modifier tells
us to do this repeatedly; which is why the second half of the
alternation uses \G to pick up where the last match left off.
-mjc
------------------------------
Date: Thu, 23 Jan 2003 23:40:55 +0100
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: Is there a better way to format numbers to use commas?
Message-Id: <3357203.W3vcA9nGfl@nyoga.dubu.de>
Marc Bissonnette wrote:
> "Harald H.-J. Bongartz" <bongie@gmx.net> wrote in
> news:2445168.9nIL9k8Hjm@nyoga.dubu.de:
>> See perldoc -q 'with commas':
>> How can I output my numbers with commas added?
>
> Wow, thanks - That's one of those (for me, anyways) "black box" type
> of solutions where I get a brain-ache trying to comprehend what the
> command is doing (for those who don't look it up in perldoc, my big
> massive hunk of code can be replaced with:
>
> $number=1234567891011;
> $number=~s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g;
> print "$number\n";
Maybe easier to understand, but more code, this should also work:
my $num = 1234567891011;
(my $numformatted = reverse $num) =~ s/(\d{3})(?=\d)/$1,/g;
my $numformatted = reverse $numformatted;
This reverses the number, then replaces every sequence of three numbers
(if followed by another number) by this sequence and a comma. Then the
result is reversed again.
(If you want to print the number directly, please keep in mind, that
"print reverse $tmp" won't work, but "print scalar reverse $tmp" will.)
Ciao,
Harald
--
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
"A low voter turnout is an indication of fewer people going to the
polls." -- George W. Bush Jr.
------------------------------
Date: Thu, 23 Jan 2003 23:04:04 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Is there a better way to format numbers to use commas?
Message-Id: <x7n0lro4d8.fsf@mail.sysarch.com>
>>>>> "MC" == Michael Carman <mjcarman@mchsi.com> writes:
>> $number=~s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g;
MC> /x to the rescue!
MC> s/( # begin capture to $1
MC> ^ # at the beginning of the string
MC> [-+]? # match an optional sign
MC> \d+? # one or more digits (maybe)
not maybe, rather non-greedy
MC> (?= # look ahead for (but don't match!):
MC> (?> # an atomic group (no backtracking) of
MC> (?:\d{3})+ # one or more sets of 3 digits
MC> ) # end atomic grouping
MC> (?!\d) # that isn't followed by a digit
MC> ) # end lookahead
that first part is trying to grab all the digits before any groups of 3
digits (ending with a non-digit). this will be the first section of 1,2
or 3 digits which will then be replaced with itself and a comma.
MC> | # match what's above OR what's below
MC> \G # start at the end of the last match
MC> \d{3} # three digits
MC> (?=\d) # that are followed by other digits
MC> ) # end capture to $1
since any previous match grabbed the first section, this will grab the
next three digits but not the last one (more digits must follow).
MC> /$1,/xg # replace by the value of "$1," -- repeat
i would have used indenting on the | groups as well as the grabs.
MC> That tells you *what* it's doing. As for *how*... the first part of the
MC> alternation (everything before the '|') is to match any leading digits
MC> that are followed by an integer multiple of three digits. Everything
MC> after the '|' is taken in chunks of three digits as long as it's not the
MC> last chunk. Whatever matches has a comma appended. The /g modifier tells
MC> us to do this repeatedly; which is why the second half of the
MC> alternation uses \G to pick up where the last match left off.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: 23 Jan 2003 11:06:40 -0800
From: gbathgate2000@yahoo.com (Grayson Bathgate)
Subject: Need a Perl Programmer
Message-Id: <e89f00b6.0301231106.18376acc@posting.google.com>
Can anyone assist me in a small perl project? Please email me your
resume if you want a contract job.
We have Perl 5.003 soon to be upgraded to 5.6.
email me at: webzhead@yahoo.com
------------------------------
Date: Thu, 23 Jan 2003 13:36:47 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Need a Perl Programmer
Message-Id: <slrnb30h2f.b94.tadmc@magna.augustmail.com>
Grayson Bathgate <gbathgate2000@yahoo.com> wrote:
> Can anyone assist me in a small perl project?
Job ads are not welcome in this newsgroup.
> Please email me your
> resume if you want a contract job.
David will be along shortly I'm sure, but in the meantime, consider
posting your job advertisement on the Perl jobs mailing list:
http://lists.perl.org/showlist.cgi?name=jobs
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 23 Jan 2003 20:31:11 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Need a Perl Programmer
Message-Id: <x7adhrpq0h.fsf@mail.sysarch.com>
>>>>> "GB" == Grayson Bathgate <gbathgate2000@yahoo.com> writes:
GB> Can anyone assist me in a small perl project? Please email me your
GB> resume if you want a contract job.
GB> We have Perl 5.003 soon to be upgraded to 5.6.
post it on the perl jobs list: http://jobs.perl.org
(waiting for the adlerbot).
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Thu, 23 Jan 2003 22:41:55 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: parse scalar into array
Message-Id: <3e306fa6.59877640@news.erols.com>
monkeys paw <fm_duendeBASURA@yahoo.com> wrote:
: How can i take a string and put each char into an
: array.
@array = split //, $string;
or
@array = $string =~ /./gs;
: For instance, i have $i = 134675. I simply
: need to add each digit together like so:
:
: 1 + 3 + 4 + 6 + 7 + 5 = 26
You mention characters before, and digits here.
Not all characters are digits.
#!perl -l
use List::Util;
print List::Util::sum( 134675 =~ /\d/g );
------------------------------
Date: Thu, 23 Jan 2003 22:34:12 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: parse scalar into array
Message-Id: <pan.2003.01.23.21.07.16.43071@kamelfreund.de>
On Thu, 23 Jan 2003 18:20:02 +0000, monkeys paw wrote:
> How can i take a string and put each char into an
> array. For instance, i have $i = 134675. I simply
> need to add each digit together like so:
>
> 1 + 3 + 4 + 6 + 7 + 5 = 26
>
> I could do this with a series of modulus 10
> but there must be an easy way to do:
>
> @each_digit = parsing_func($i);
>
> where @each_digit would result in:
>
> qw(1 3 4 6 7 5)
As TMTWTDI, here's a solution working with regexes:
y $i = 134675;
my $sum;
$value += $1 while ($i =~ /(.)/);
# or
# $value += $& while ($i =~ /./);
print $value;
And here's another solution exploiting a standard module,
so that is perhaps easier to read:
use List::Util qw/sum/;
my $i = 134675;
print sum ($i =~ /./g);
Cheerio,
Janek
------------------------------
Date: 23 Jan 2003 13:38:09 -0800
From: dominik.furger@gmx.net (Dominik)
Subject: Perl Batch Job without DOS window popup
Message-Id: <b58b92f7.0301231338.2e5d8a61@posting.google.com>
Is it possible to run a batch job in XP without having the DOS windows
always poped up when the perl job runs?
I think it must be possible to run the job as a background job and
have the DOS window suppressed during the run.
Can anyone help on this?
Thanks.
------------------------------
Date: 23 Jan 2003 12:21:33 -0800
From: dominik.furger@gmx.net (Dominik)
Subject: Perl Batch Job without start of a DOS box
Message-Id: <b58b92f7.0301231221.6707173d@posting.google.com>
Ist it possible to run a perl script on XP as an batch job without the
popup of a DOS window?
It must be possible to run the job in the backgrund, but how?
Can anyone help on this?
Thx.
------------------------------
Date: Thu, 23 Jan 2003 15:37:09 -0500
From: "Charles R. Thompson" <charlest@indysoft.com>
Subject: Re: Perl Batch Job without start of a DOS box
Message-Id: <v30kjln9iq70a8@corp.supernews.com>
you need to use wperl.exe instead. A working example can be found in the
Popfile project at sourceforge.net or by perusing ActiveState.com
"Dominik" <dominik.furger@gmx.net> wrote in message
news:b58b92f7.0301231221.6707173d@posting.google.com...
> Ist it possible to run a perl script on XP as an batch job without the
> popup of a DOS window?
>
> It must be possible to run the job in the backgrund, but how?
>
> Can anyone help on this?
>
> Thx.
------------------------------
Date: 23 Jan 2003 13:21:33 -0800
From: jmasters@pcocd2.intelat.com (Justin Masters - remove at to reply)
Subject: Re: Problem printing January "The Perl Journal"
Message-Id: <cavn0lrmujm.fsf@pcocd2.intel.com>
Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net> writes:
> In article <cavn0ltlzkn.fsf@pcocd2.intel.com>, Justin Masters - remove
> at to reply wrote:
> > I am a subscriber to The Perl Journal. I downloaded my January copy, and
> > cannot print it out. I attempted to contact Kevin Carlson (listed on The Perl
> > Journal homepage) and he has not responded after 2-3 weeks.
> >
> > Does anybody know why it's not printable? I'd like to take it with me to read
> > without lugging a computer around with me.
>
> [...]
>
>
> What is your Perl question?
>
I found the solution myself. Bad printer driver. Thanks.
Justin (remove at to reply)
>
> Cheers,
> Bernard
> --
> echo 42|perl -pe '$#="Just another Perl hacker,"'
--
------------------------------------------------------------------------------
Justin Masters (Systems Programmer) PH: 916 356-6735
Intel Corp. FM6-17 FAX: 916 377-2288
1900 Prairie City Rd, Folsom, CA 95630 jmasters@pcocd2.intelat.com
------------------------------
Date: 23 Jan 2003 12:12:17 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: Regex: optional word boundary
Message-Id: <776e0325.0301231212.750c26@posting.google.com>
"Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de> wrote in message news:<b0ouk4$2ua$1@nets3.rz.RWTH-Aachen.DE>...
> Also sprach Sara:
>
> > tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnb2u59r.8ha.tadmc@magna.augustmail.com>...
>
> >> We can't really tell, because Amittai did not show us the operator,
> >> only the regex.
> >>
> >> /\bfan(mail | base)?/x
> ^
> ^
> >>
> >> can indeed be prettied up with spaces. :-)
> >
> > Actually I retract my previous response, Tad. I can't get this
> > solution to work. As I suspected it matches only 'fanmail ' and 'fan',
> > not 'fanbase'. Yes it can be prettied up this way, only problem is it
> > no longer works!
> >
> >
> > s/\b(fan(mail | base)?)\b/[$1]/g;
> ^^
> ^^
>
> Spot the difference? You left off the x-modifier which causes
> whitespaces to be ignored. In your pattern whitespaces do matter.
>
> Tassilo
Thanks Tassilo- yes I did miss that "x". Interesting switch I may use
that to dazzle and confuse my coworkers :)
Cheers,
Gx
------------------------------
Date: Thu, 23 Jan 2003 16:16:52 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regex: optional word boundary
Message-Id: <slrnb30qek.brq.tadmc@magna.augustmail.com>
Sara <genericax@hotmail.com> wrote:
> "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de> wrote in message news:<b0ouk4$2ua$1@nets3.rz.RWTH-Aachen.DE>...
>> > tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnb2u59r.8ha.tadmc@magna.augustmail.com>...
>> >> /\bfan(mail | base)?/x
>> ^
>> ^
>> Spot the difference? You left off the x-modifier which causes
>> whitespaces to be ignored. In your pattern whitespaces do matter.
> Thanks Tassilo- yes I did miss that "x". Interesting switch I may use
> that to dazzle and confuse my coworkers :)
You might as well start getting used to it, as "x" behavior will
be the default in Perl 6, ie. spaces will be ignored in regexes. :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 23 Jan 2003 21:54:09 +0100
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: slow grep
Message-Id: <gmk03v01gvo1mtmhvl34bab0sh25pft16f@4ax.com>
X-Ftn-To: Benjamin Goldberg
Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> a => sub { my @a = grep /5\z/, 0..99; 0 },
> b => sub { my @a = grep { /5\z/ } 0..99; 0 },
> c => sub { my @a; /5\z/ && push @a, $_ for 0..99; 0 },
>} );
>__END__
>Benchmark: running a, b, c, each for at least 5 CPU seconds...
>a: 5 wallclock secs ( 5.06 usr + 0.00 sys = 5.06 CPU) @ 2106.13/s (n=10657)
>b: 6 wallclock secs ( 5.06 usr + 0.00 sys = 5.06 CPU) @ 716.01/s (n=3623)
>c: 6 wallclock secs ( 6.10 usr + 0.00 sys = 6.10 CPU) @ 1133.11/s (n=6912)
> Rate b c a
>b 716/s -- -37% -66%
>c 1133/s 58% -- -46%
>a 2106/s 194% 86% --
>
>So, grep without a block is fastest, then foreach, and in last place comes
>grep with a block.
Hm, braceless grep is only 194% faster. :) IMHO this should go into grep
perldoc.
--
Matija
------------------------------
Date: Thu, 23 Jan 2003 21:54:10 +0100
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: slow grep
Message-Id: <1gl03vsodctds0q6m666q88ek2du59csov@4ax.com>
X-Ftn-To: Anno Siegel
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>> sub sub3 {
>> my @rest = grep {!/^mato/} @arr;
>> 0;
>> }
>
>Errrm... are you aware that sub1() and sub3() don't do the same
>thing? For an emulation of grep, use something like this:
>
> sub sub1 {
> my @rest;
> !/^mato/ and push @rest, $_ for @arr;
> @rest;
> }
Tnx, this is better. Prior to that I was experimenting with two arrays,
pushing elements in first or second, depending on condition.
--
Matija
------------------------------
Date: Thu, 23 Jan 2003 22:37:13 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: unlink()
Message-Id: <3e306e6a.59561370@news.erols.com>
Joel Konkle-Parker <joeljkp@tabdemo.larc.nasa.gov> wrote:
: I have the following lines at the end of my script:
:
: unlink ("./temp_trail.txt") || die $!;
: unlink ("./prt0001__out.log.1") || die $!;
:
: But when my script ends each time, the files are still there. The 'die'
: doesn't produce any output. This is Perl 5.004. What's wrong here?
Perhaps the lines aren't being executed at all. A program can
terminate without getting to the last lines of the script.
Try a debug print immediately before those lines, e.g.
print "Getting ready to unlink. This time for sure!\n";
# put unlink()s here
Or wrap the unlinks in an END{} block to ensure they happen just
before the program terminates.
------------------------------
Date: Thu, 23 Jan 2003 22:38:47 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: unlink()
Message-Id: <3e306e9d.59612250@news.erols.com>
Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net> wrote:
: BTW, you can combine those two commands into one:
:
: unlink ('./temp_trail.txt', 'prt0001__out.log.1') || die $!;
There's a chance for that to successfully unlink only one of the files
and not say anything about the other's failure.
unlink('./temp_trail.txt', 'prt0001__out.log.1') == 2 || die $!;
------------------------------
Date: Thu, 23 Jan 2003 22:11:45 GMT
From: "Peter Vlaciky" <peterv@delete.catuity.com.au>
Subject: video grab problem with Video::Capture::V4l
Message-Id: <BMZX9.995$YU1.20085@news.optus.net.au>
Hi,
I have been trying to use the Video::Capture::V4l package on my linux box,
but with not much luck so far.
When I installed it, I was able to capture a single frame from my bttv.o
module and v4l but then it suddenly stopped working.
I know it sounds weird, but I have not changed anything other than trying
the different sample code snippets.
Rebooting the machine or reinstalling the V4l package did not help either.
I know my TV capture card is working, because I can still use other tools to
view TV on my monitor. I searched the net but there seems very little
information on this module. This is the link where I found it in first
place: http://www.samag.com/documents/s=1273/sam05020008/
The problem I have is with this line: my $fr=$grab->capture ($frame, 640,
480);
$fr normally holds the entire grabbed frame as a series of bytes where each
group of 3 bytes represents a pixel (RGB), but for no apparent reason it
just returns all 0's.
I though maybe it could be a memory problem since 640x480x3 is a pretty
large chunk, but changing it to capture ($frame, 64, 48) did not help
either. Besides I got it working at least once on a freshly installed
system.
Does anyone have any experience with this Video::Capture::V4l module?
Alternatively, can anyone suggest an alternative? I just need to be able to
tune into a channel on my TV card, grab a frame and then manipulate it
(resize, save, etc) using perl. The V4l module can do all that and more,
provided it works. :-(
Thank you for any help you can give me.
Peter
------------------------------
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.
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 4457
***************************************