[31299] in Perl-Users-Digest
Perl-Users Digest, Issue: 2544 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 9 21:09:45 2009
Date: Sun, 9 Aug 2009 18:09:09 -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 Sun, 9 Aug 2009 Volume: 11 Number: 2544
Today's topics:
capturing stdout and stderr? <mikee@mikee.ath.cx>
Re: capturing stdout and stderr? <ben@morrow.me.uk>
Re: DBI fetchall_arratref, JSON and converting numeric <seven.reeds@gmail.com>
DBI query does not fetch all data <henribaeyens_0713@orange.fr>
Re: DBI query does not fetch all data <johann.kappacher@gmail.com>
Re: DBI query does not fetch all data <fiacre.patrick@gmail.com>
Re: DBI query does not fetch all data <tadmc@seesig.invalid>
Re: FAQ 8.14 How do I modify the shadow password file o (Alan Curry)
Re: FAQ 8.18 How can I do an atexit() or setjmp()/longj <xhoster@gmail.com>
Re: FAQ 8.18 How can I do an atexit() or setjmp()/longj <derykus@gmail.com>
Help with simple compare condition? <r.mariotti@fdcx.net>
Re: Help with simple compare condition? <tadmc@seesig.invalid>
Re: Help with simple compare condition? <r.mariotti@fdcx.net>
Re: Help with simple compare condition? <tadmc@seesig.invalid>
Re: Help with simple compare condition? (Doug Miller)
Re: Help with simple compare condition? sln@netherlands.com
regular expressions <mud_saisem@hotmail.com>
Re: regular expressions <alexander.bartolich@gmx.at>
Re: regular expressions <mud_saisem@hotmail.com>
Re: substitution with computed replacements <johann.kappacher@gmail.com>
Taliban sows doubt over Mehsud's death <asim.ssat@gmail.com>
Re: using file globs and regex <xhoster@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 9 Aug 2009 21:33:28 +0000 (UTC)
From: Mike <mikee@mikee.ath.cx>
Subject: capturing stdout and stderr?
Message-Id: <h5nfb8$hl6$1@news.eternal-september.org>
Morning,
I'm asking where do I start my research, recommendations for a module
or function. I'm not asking for code that does what I need.
I have a need to start a command then read the command's stdout and
stderr streams, capturing each line individually, prepending 'STDOUT:'
or 'STDERR:' to the line depending on which stream the line came from,
then writing the line to a central log file.
In C I would fork(), exec(), then from the parent just use select()
to grab each line that comes from the child.
Is the same approach the simpleist way in Perl or should I look at
IPC::Open3 or IPC::Run?
This script needs to run on linux, HP-UX, Solaris, IRIX, Mac OS X,
cygwin/win32, and cygwin/win64.
Thanks for your thoughts.
Mike
------------------------------
Date: Sun, 9 Aug 2009 23:08:26 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: capturing stdout and stderr?
Message-Id: <qvt3l6-uhn1.ln1@osiris.mauzo.dyndns.org>
Quoth Mike <mikee@mikee.ath.cx>:
>
> I'm asking where do I start my research, recommendations for a module
> or function. I'm not asking for code that does what I need.
>
> I have a need to start a command then read the command's stdout and
> stderr streams, capturing each line individually, prepending 'STDOUT:'
> or 'STDERR:' to the line depending on which stream the line came from,
> then writing the line to a central log file.
>
> In C I would fork(), exec(), then from the parent just use select()
> to grab each line that comes from the child.
>
> Is the same approach the simpleist way in Perl or should I look at
> IPC::Open3 or IPC::Run?
Any of those approaches would be fine. If you're a C programmer, you may
find an explicit pipe/fork/exec/select sequence easiest to understand;
the various modules that do this are just wrappers around that.
Personally I would probably use IPC::Run.
Ben
------------------------------
Date: Sat, 8 Aug 2009 20:59:12 -0700 (PDT)
From: "seven.reeds" <seven.reeds@gmail.com>
Subject: Re: DBI fetchall_arratref, JSON and converting numeric "sting" to "number"
Message-Id: <e5ba2f44-2ef4-4af1-b995-21874005c483@d4g2000vbm.googlegroups.com>
> Something like
>
> =A0 =A0 use Scalar::Util qw/looks_like_number/;
>
> =A0 =A0 for (@$results) {
> =A0 =A0 =A0 =A0 $_ +=3D 0
> =A0 =A0 =A0 =A0 =A0 =A0 if looks_like_number $_;
> =A0 =A0 }
Brilliant, thanks. Much more elegant
------------------------------
Date: 08 Aug 2009 14:06:51 GMT
From: Henri Baeyens <henribaeyens_0713@orange.fr>
Subject: DBI query does not fetch all data
Message-Id: <4a7d867b$0$23454$ba4acef3@news.orange.fr>
Hello,
I'm using DBI and an ODBC driver to get data from an Access database. The
query is executed but only part of the data is fetched. I know that the
database contains over 1500 rows. My query returns only 28 rows.
use DBI;
use strict;
use warnings;
my $dbh = DBI->connect('dbi:ODBC:boutique', {RaiseError => 1} );
my $query;
my $table = "articles";
my @row_array;
$query = $dbh->prepare("SELECT * FROM $table");
$query->execute;
while (@row_array=$query->fetchrow_array) {
foreach my $item (@row_array){
if ($item eq ""){
print qq~ NULL |~;
} else {
print qq~ $item |~;
}
}
}
my $numrows = $query->rows;
print qq~Number of rows fetched: $numrows~;
etc...
There's also the fact that columns are not fetched in the same order as
they are in the source database, but that's a minor problem.
I can't figure it out. Anything I am missing?
H
www.henribaeyens.com
------------------------------
Date: Sun, 9 Aug 2009 13:00:08 -0700 (PDT)
From: kappa <johann.kappacher@gmail.com>
Subject: Re: DBI query does not fetch all data
Message-Id: <485328e2-01b8-4f71-aa69-25e9fbb3cbba@f33g2000vbm.googlegroups.com>
On 8 Aug., 16:06, Henri Baeyens <henribaeyens_0...@orange.fr> wrote:
> Hello,
>
> I'm using DBI and an ODBC driver to get data from an Access database. The
> query is executed but only part of the data is fetched. I know that the
> database contains over 1500 rows. My query returns only 28 rows.
>
> use DBI;
> use strict;
> use warnings;
>
> my $dbh =3D DBI->connect('dbi:ODBC:boutique', {RaiseError =3D> 1} );
> my $query;
> my $table =3D "articles";
> my @row_array;
>
> $query =3D $dbh->prepare("SELECT * FROM $table");
> $query->execute;
>
> while (@row_array=3D$query->fetchrow_array) {
> =A0 =A0foreach my $item (@row_array){
> =A0 =A0 =A0 if ($item eq ""){
> =A0 =A0 =A0 =A0 print qq~ NULL |~;
> =A0 =A0 =A0 } else {
> =A0 =A0 =A0 =A0 print qq~ $item |~;
> =A0 =A0 =A0 }
> =A0 =A0}}
>
> my $numrows =3D $query->rows;
> print qq~Number of rows fetched: $numrows~;
>
> etc...
>
> There's also the fact that columns are not fetched in the same order as
> they are in the source database, but that's a minor problem.
>
> I can't figure it out. Anything I am missing?
>
> H
>
> www.henribaeyens.com
try "select count(*) from table" to be sure!
------------------------------
Date: Sun, 9 Aug 2009 13:55:02 -0700 (PDT)
From: Andrew Lee <fiacre.patrick@gmail.com>
Subject: Re: DBI query does not fetch all data
Message-Id: <ed23ab6a-7d07-447d-ba71-5aa61c7f09f2@p9g2000vbl.googlegroups.com>
On Aug 8, 10:06=A0am, Henri Baeyens <henribaeyens_0...@orange.fr> wrote:
> Hello,
>
>
> $query =3D $dbh->prepare("SELECT * FROM $table");
> $query->execute;
...
A point of good practice:
if ( $dbh->errstr) { die $dbh->errstr; }
Just as with file or network I/O, don't assume a database command
worked.
------------------------------
Date: Sun, 09 Aug 2009 16:41:44 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: DBI query does not fetch all data
Message-Id: <slrnh7ug5t.2i0.tadmc@tadmc30.sbcglobal.net>
Andrew Lee <fiacre.patrick@gmail.com> wrote:
> On Aug 8, 10:06 am, Henri Baeyens <henribaeyens_0...@orange.fr> wrote:
>>
>> $query = $dbh->prepare("SELECT * FROM $table");
>> $query->execute;
>
>
> ...
>
> A point of good practice:
> if ( $dbh->errstr) { die $dbh->errstr; }
The OP turned "RaiseError" on, so there is no need for an explicit check.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sun, 9 Aug 2009 04:38:09 +0000 (UTC)
From: pacman@kosh.dhis.org (Alan Curry)
Subject: Re: FAQ 8.14 How do I modify the shadow password file on a Unix system?
Message-Id: <h5ljrh$tp7$1@aioe.org>
In article <080820090231545586%brian.d.foy@gmail.com>,
brian d foy <brian.d.foy@gmail.com> wrote:
>In article <h5g1d9$k5m$1@aioe.org>, Alan Curry <pacman@kosh.dhis.org>
>wrote:
>> This whole FAQ entry is nothing but a disguised rant (originally written by
>> Tom Christiansen, I'll bet)
>
>I think you are right, and this question should disappear from the FAQ.
It's hard to constructively answer, because so many things are lurking under
it. The header says "modify" but the answer is partly about reading. If
there's a CPAN module that exposes setspent(), getspent(), putspent(), from
the libc, that would be nice to know.
For changing passwords, or other fields of the shadow file, if you don't want
to run an external program dedicated to that purpose, you should at least be
sure you cooperate with their locking scheme. Your libc may have a lckpwdf()
to help with that, or may not.
--
Alan Curry
------------------------------
Date: Fri, 07 Aug 2009 19:16:38 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: FAQ 8.18 How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
Message-Id: <4a7deecb$0$26187$ed362ca5@nr5-q3a.newsreader.com>
brian d foy wrote:
> In article <lniqh4o31c.fsf@nuthaus.mib.org>, Keith Thompson
> <kst-u@mib.org> wrote:
>
>> PerlFAQ Server <brian@stonehenge.com> writes:
>>> 8.18: How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
>>>
>>> Release 5 of Perl added the END block, which can be used to simulate
>>> atexit(). Each package's END block is called when the program or thread
>>> ends (see perlmod manpage for more details).
>
>
>> Since Perl 5 is so old, I suggest it's not worth mentioning when this
>> was added. The END block is just a feature of Perl.
>
> I'm not even sure what the point of the question is. END blocks aren't
> good for exception handling because you're not really handling
> anything; you're just getting ready to stop.
But the same can be said about atexit in C, can't it?
>
> This might be another candidate for the bit bucket.
I think it still makes sense, just as two different questions.
atexit and setjmp/longjmp seem to be two rather different topics, I
don't know why they are combined.
Xho
------------------------------
Date: Sat, 8 Aug 2009 15:27:38 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: FAQ 8.18 How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
Message-Id: <6929b43c-1556-4ebc-9f96-2f250f624ba8@m3g2000pri.googlegroups.com>
On Aug 7, 6:37=A0pm, brian d foy <brian.d....@gmail.com> wrote:
> In article <lniqh4o31c....@nuthaus.mib.org>, Keith Thompson
>
> <ks...@mib.org> wrote:
> > PerlFAQ Server <br...@stonehenge.com> writes:
> > > 8.18: How can I do an atexit() or setjmp()/longjmp()? (Exception hand=
ling)
>
> > > =A0 =A0 Release 5 of Perl added the END block, which can be used to s=
imulate
> > > =A0 =A0 atexit(). Each package's END block is called when the program=
or thread
> > > =A0 =A0 ends (see perlmod manpage for more details).
> > Since Perl 5 is so old, I suggest it's not worth mentioning when this
> > was added. =A0The END block is just a feature of Perl.
>
> I'm not even sure what the point of the question is. END blocks aren't
> good for exception handling because you're not really handling
> anything; you're just getting ready to stop.
END{} though could be viewed as exception handling
in the sense of enabling code insertion before
terminating if the program die()'s.
--
Charles DeRykus
------------------------------
Date: Sat, 08 Aug 2009 12:47:10 -0400
From: bobmct <r.mariotti@fdcx.net>
Subject: Help with simple compare condition?
Message-Id: <ejar75l3sfac9scjptnr7rn7bl8pl9fj8i@4ax.com>
Fellow mongers;
I've done research in my many perl books as well as numerous perl
references on the web and still am confused on this rather simple
situation (embarrassingly so):
I need to compare two variables for presence of content to meet the
following tests:
VarA = present and VarB = present then false
VarA = empty and VarB = empty then false
VarA = present and VarB = empty then true
VarA = empty and VarB = present then true
-or-
As I more simply thought of if:
VarA ne VarB then true
Each Var could contain
1) an empty string
2) a string value
3) a numeric value
4) a space
I cannot seem to get a consistent result from the various methods I've
used.
Any recommendations or suggestions greatly appreciated.
Thanks - B
------------------------------
Date: Sat, 08 Aug 2009 12:53:48 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Help with simple compare condition?
Message-Id: <slrnh7reep.f9v.tadmc@tadmc30.sbcglobal.net>
bobmct <r.mariotti@fdcx.net> wrote:
> I need to compare two variables for presence of content to meet the
> following tests:
What does "presence of content" mean when you say it?
If "content" is "foo", then is it "present" in
foo
foobar
barfoo
barfoobaz
?
> VarA = present and VarB = present then false
> VarA = empty and VarB = empty then false
> VarA = present and VarB = empty then true
> VarA = empty and VarB = present then true
That is the truth table for the xor operator, so I'd start with that.
You have only 4 cases, if you wrote a short and complete program
that shows VarA and VarB for the 4 cases, then we could probably
help you solve your problem.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sat, 08 Aug 2009 14:28:52 -0400
From: bobmct <r.mariotti@fdcx.net>
Subject: Re: Help with simple compare condition?
Message-Id: <frgr75du8q52s9errnohd8uosvqhmgj4e4@4ax.com>
On Sat, 08 Aug 2009 12:53:48 -0500, Tad J McClellan
<tadmc@seesig.invalid> wrote:
presence as in non-empty and non-space.
My test is: if (($VarA and !$VarB) or (!$VarA and $VarB)) { ...
>bobmct <r.mariotti@fdcx.net> wrote:
>
>> I need to compare two variables for presence of content to meet the
>> following tests:
>
>
>What does "presence of content" mean when you say it?
>
>If "content" is "foo", then is it "present" in
>
> foo
> foobar
> barfoo
> barfoobaz
>
>?
>
>> VarA = present and VarB = present then false
>> VarA = empty and VarB = empty then false
>> VarA = present and VarB = empty then true
>> VarA = empty and VarB = present then true
>
>
>That is the truth table for the xor operator, so I'd start with that.
>
>You have only 4 cases, if you wrote a short and complete program
>that shows VarA and VarB for the 4 cases, then we could probably
>help you solve your problem.
------------------------------
Date: Sat, 08 Aug 2009 14:41:59 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Help with simple compare condition?
Message-Id: <slrnh7rkpk.gi8.tadmc@tadmc30.sbcglobal.net>
bobmct <r.mariotti@fdcx.net> wrote:
> On Sat, 08 Aug 2009 12:53:48 -0500, Tad J McClellan
>>What does "presence of content" mean when you say it?
>>
> presence as in non-empty and non-space.
print "true\n" if $vara !~ /^\s*$/ xor $varb !~ /^\s*$/;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sat, 08 Aug 2009 20:29:40 GMT
From: spambait@milmac.com (Doug Miller)
Subject: Re: Help with simple compare condition?
Message-Id: <h5knmu$2e7$2@news.eternal-september.org>
In article <ejar75l3sfac9scjptnr7rn7bl8pl9fj8i@4ax.com>, bobmct <r.mariotti@fdcx.net> wrote:
>Fellow mongers;
>
>I've done research in my many perl books as well as numerous perl
>references on the web and still am confused on this rather simple
>situation (embarrassingly so):
>
>I need to compare two variables for presence of content to meet the
>following tests:
>
>VarA = present and VarB = present then false
>VarA = empty and VarB = empty then false
>VarA = present and VarB = empty then true
>VarA = empty and VarB = present then true
I think you need a more precise definition of "present". Do you mean:
a) the variable exists
b) the variable exists and has a value (e.g. non-empty)
c) the variable exists and has a *specific* value (e.g. non-space if a string,
non-zero if a number)
>
>-or-
>
>As I more simply thought of if:
>
>VarA ne VarB then true
That, of course, is an entirely different condition. Two different non-empty
strings are "present", but not equal. The numbers 1 and 2 are present, but,
again, not equal. Moreover, the numbers 1 and 1 are present, and *are* equal.
>
>Each Var could contain
What if the variable doesn't exist?
>
>1) an empty string
Is that "present", or not?
>2) a string value
Presumably, that's "present" -- but what if its value is entirely whitespace
characters (blank, tab, line feed, etc.)?
>3) a numeric value
Presumably, that's "present" too -- but what if the value is zero? Is that
"present"? Do you distinguish between integer zero and floating-point
zero-point-zero?
>4) a space
Is that "present", or not?
>I cannot seem to get a consistent result from the various methods I've
>used.
Perhaps if you posted some of those methods...?
I suspect that the largest part of your trouble is a failure to define clearly
exactly what you mean by "present".
>
>Any recommendations or suggestions greatly appreciated.
Sure -- show us what you've tried, and what happens when you try it.
------------------------------
Date: Sun, 09 Aug 2009 14:44:37 -0700
From: sln@netherlands.com
Subject: Re: Help with simple compare condition?
Message-Id: <jdgu75tiq80vjqrbrnnovu2co19j71ncb3@4ax.com>
On Sat, 08 Aug 2009 14:28:52 -0400, bobmct <r.mariotti@fdcx.net> wrote:
>On Sat, 08 Aug 2009 12:53:48 -0500, Tad J McClellan
><tadmc@seesig.invalid> wrote:
>
>presence as in non-empty and non-space.
>
>My test is: if (($VarA and !$VarB) or (!$VarA and $VarB)) { ...
>
>
>>bobmct <r.mariotti@fdcx.net> wrote:
>>
>>> I need to compare two variables for presence of content to meet the
>>> following tests:
>>
>>
>>What does "presence of content" mean when you say it?
>>
>>If "content" is "foo", then is it "present" in
>>
>> foo
>> foobar
>> barfoo
>> barfoobaz
>>
>>?
>>
>>> VarA = present and VarB = present then false
>>> VarA = empty and VarB = empty then false
>>> VarA = present and VarB = empty then true
>>> VarA = empty and VarB = present then true
>>
>>
>>That is the truth table for the xor operator, so I'd start with that.
>>
>>You have only 4 cases, if you wrote a short and complete program
>>that shows VarA and VarB for the 4 cases, then we could probably
>>help you solve your problem.
"non-empty and non-space"
Would this be TRUE and all others be FALSE?
...
Logic conditions:
VarA = present and VarB = present then false
VarA = empty and VarB = empty then false
VarA = present and VarB = empty then true
VarA = empty and VarB = present then true
A && B false
!A && !B false
A && !B true
!A && B true
Convert to 'true'/logical or:
#1 !(!A || !B) true logical
#2 !( A || B) true logical
#3 !A || B true A xor B
#4 A || !B true A xor B
The xor operator can cover #3#4 in once statement because its atomic.
(Xor = only one can/must be true)
#5 (from #3#2) A xor B true
The 'truth' breaks down when you consider #1#2 in relation to each other
and #5.
For instance A xor B is not necessarily equal to !(!A || !B)) nor !( A || B).
You have to ask yourself "what is the truth I am actually looking for?"
Not all 'truths' are equal. Some are falshood in disguise.
Truth as a whole is often confused with 'truth' as a subset.
The absolute truth MUST be a combination of all incremental truth.
Your attempt at logic is pffft..
You should attempt to take a junior college course called 'Formal Symbolic Logic',
something that will help you immensly.
-sln
---------------------------------
use strict;
use warnings;
my ($VarA,$VarB,$A,$B);
$VarA = 'asg';
$VarB = '';
$A = defined($VarA) && $VarA =~ /^\s*.+/ ? 1:0;
$B = defined($VarB) && $VarB =~ /^\s*.+/ ? 1:0;
print "$A $B\n";
if ( ($A xor $B) ) {
print "Xor condition is true\n";
} else {
print "Xor cndition is false\n";
}
if ( (!(!$A || !$B)) && !($A || $B) ) {
print "Logical condition is true\n";
} else {
print "Logical cndition is false\n";
}
------------------------------
Date: Sun, 9 Aug 2009 15:25:24 -0700 (PDT)
From: mud_saisem <mud_saisem@hotmail.com>
Subject: regular expressions
Message-Id: <c3a8f307-e841-4646-8284-6a2c23f2f12e@u16g2000pru.googlegroups.com>
Hi There,
Could anybody please let me know how I would be able to extract the
words that have a = in the middle and print the whole word out. Also I
will never know how many : and in the word either.
eg: "This is a example item, order=TEST:ITEM:123 on shelf
shelf=1:4:23:f"
output: order=TEST:ITEM:123
shelf=1:4:23:f
This is what I have done so far but only prints out the word until the
first :
eg: order=TEST
#!/usr/bin/perl
system(clear);
$string = "This is a example item, order=TEST:ITEM:123 on shelf
shelf=1:4:23:f";
$str = $string;
print "String: $string\n\n";
sub extract
{
$x = shift;
print "Checking: $x\n";
return $x;
}
$string =~ s/(\w+=\w+)/extract $1/ge;
print "\n";
------------------------------
Date: Sun, 9 Aug 2009 22:42:46 +0000 (UTC)
From: Alexander Bartolich <alexander.bartolich@gmx.at>
Subject: Re: regular expressions
Message-Id: <h5njd6$d1n$1@news.albasani.net>
mud_saisem wrote:
> [...]
> $string =~ s/(\w+=\w+)/extract $1/ge;
$string =~ s/(\w+=[\w:]+)/extract $1/ge;
Checking: order=TEST:ITEM:123
Checking: shelf=1:4:23:f
--
Brüder, in die Tonne die Freiheit,
Brüder, ein Stoppschild davor.
Egal was die Schwarzen Verlangen
Rufen wir: Ja! Brav im Chor.
------------------------------
Date: Sun, 9 Aug 2009 15:53:46 -0700 (PDT)
From: mud_saisem <mud_saisem@hotmail.com>
Subject: Re: regular expressions
Message-Id: <0021bd87-863b-4fb4-90ee-f53779946da4@l5g2000pra.googlegroups.com>
On Aug 10, 8:42=A0am, Alexander Bartolich <alexander.bartol...@gmx.at>
wrote:
> mud_saisem wrote:
> > [...]
> > $ String =3D ~ s / (\ w + =3D \ w +) / $ 1/ge extract;
>
> $ string =3D ~ s / (\ w + =3D [\ w :]+)/ $ 1/ge extract;
>
> Checking: order =3D TEST: ITEM: 123
> Checking: shelf =3D 1:4:23: f
>
> --
> Brothers, in a ton of freedom,
> Brothers, a stop sign in front.
> Regardless of what the blacks request
> Call us: Yes! Brave in the choir.
Great work !!
Thanks
------------------------------
Date: Sun, 9 Aug 2009 12:33:03 -0700 (PDT)
From: kappa <johann.kappacher@gmail.com>
Subject: Re: substitution with computed replacements
Message-Id: <8365bc57-8dd3-492d-bf6b-9802a8edd1f2@v2g2000vbb.googlegroups.com>
On 3 Aug., 16:57, fred <fred78...@yahoo.com> wrote:
> I took this from Minimal perl by Tim Maher.
>
> s/\d+ /$& * 1.6/ge
>
> I am trying to add numbers instead of converting miles to KM.
>
> input
> 2 3 4 1
> 3 4 6
>
> output
> 2 3 4 1 = 10
> 2 4 6 = 12
>
> 1. What would the replacement part be ?
> 2. What should the seach part be if we have ten numbers instead of
> four?
>
> Thanks
If you want to practice regexp stuff:
kappa@kappa:~$ head -2 /etc/hosts | perl -lne 'use List::Util "sum";
@a = /(\d+)/g; print "@a = ",sum @a'
127 0 0 1 = 128
127 0 1 1 = 129
------------------------------
Date: Sat, 8 Aug 2009 06:54:44 -0700 (PDT)
From: asim malik <asim.ssat@gmail.com>
Subject: Taliban sows doubt over Mehsud's death
Message-Id: <5fe75265-7821-438b-bf89-aa063a4753ef@x6g2000prc.googlegroups.com>
A fellow Taliban commander insisted that Baitullah Mehsud, the
movement's leader, was alive, the BBC reported on Saturday, rejecting
government
www.nfa786.blogspot.com
------------------------------
Date: Fri, 07 Aug 2009 19:25:56 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: using file globs and regex
Message-Id: <4a7deece$0$14601$ed362ca5@nr5-q3a.newsreader.com>
Tad J McClellan wrote:
> pgodfrin <pgodfrin@gmail.com> wrote:
>> Greetings,
>> This program works fine (with file names f1..f8 in the directory):
>>
>> #!/usr/bin/perl
>> use warnings;
>> use strict;
>> $\="\n";
>> while(<f*>)
>> {
>> print "$_";
>> if(/f5/)
>> {
>> my $fn=$_;
>> print "File name $fn found..." and exit;
>> }
>> }
>> exit;
>>
>> But I was hoping to be able to do something like:
>> my $fn=grep (/f5/,<f*>);
>>
>> Basically just trying to have less lines of code...any suggestions?
>
>
> use grep() in a list context instead of in a scalar context.
>
> I don't like using overloaded angle brackets in my code.
>
> If I want equality, I use an operator that tests for equality.
>
> my($fn) = grep ( $_ eq 'f5' , glob 'f*');
Or just don't remove the equality in the first place.
my($fn) = glob 'f5';
Although it seems like a file test operator would make more sense here.
Xho
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2544
***************************************