[30031] in Perl-Users-Digest
Perl-Users Digest, Issue: 1274 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 13 11:10:20 2008
Date: Wed, 13 Feb 2008 08:09: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 Wed, 13 Feb 2008 Volume: 11 Number: 1274
Today's topics:
DBI:mysql how to do multiple inserts/modification? <tch@nospam.syneticon.net>
Re: DBI:mysql how to do multiple inserts/modification? <abigail@abigail.be>
Re: DBI:mysql how to do multiple inserts/modification? <mritty@gmail.com>
Re: DBI:mysql how to do multiple inserts/modification? <john@castleamber.com>
Help: Display the specific line in a file <openlinuxsource@gmail.com>
Re: Help: Display the specific line in a file <abigail@abigail.be>
Re: Help: Display the specific line in a file <achimpeters@gmx.de>
Re: Help: Display the specific line in a file <openlinuxsource@gmail.com>
Re: Help: Display the specific line in a file <someone@example.com>
Re: Help: Display the specific line in a file <achimpeters@gmx.de>
Re: Help: Display the specific line in a file <openlinuxsource@gmail.com>
Inverted RegEx on list of numbers <groups@stephan-mann.de>
Re: Inverted RegEx on list of numbers <damian@tvk.rwth-aachen.de>
Re: Inverted RegEx on list of numbers <abigail@abigail.be>
Re: Inverted RegEx on list of numbers <achimpeters@gmx.de>
Re: Inverted RegEx on list of numbers <groups@stephan-mann.de>
Re: Inverted RegEx on list of numbers <groups@stephan-mann.de>
Re: Inverted RegEx on list of numbers <someone@example.com>
Re: Inverted RegEx on list of numbers <abigail@abigail.be>
Re: oracle RAW data type and dbi (Heinrich Mislik)
Regex /(X*)/ ulrich_martin@seznam.cz
Re: Regex /(X*)/ <damian@tvk.rwth-aachen.de>
Re: Regex /(X*)/ <mritty@gmail.com>
Re: SOAP::Lite - getting WSDL using basic authenticatio <john1949@yahoo.com>
Re: Win32::MMF What's going on? <blaine@worldweb.com>
Re: Win32::MMF What's going on? <someone@example.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 13 Feb 2008 15:03:37 +0100
From: Tomasz Chmielewski <tch@nospam.syneticon.net>
Subject: DBI:mysql how to do multiple inserts/modification?
Message-Id: <foutbp$tuk$1@online.de>
How can I do multiple database modifications without writing too much code?
For a single modification, I would write:
$SQL = "INSERT INTO aaaaa..";
$db->do($SQL);
How can I do it without repeating "$db->do($SQL);" each time?
Something like this throws an error, so obviously I must be missing
something.
$SQL = "INSERT INTO aaaaa... ;
INSERT INTO bbbbb... ;
INSERT INTO bbbbb... ;";
$db->do($SQL);
--
Tomasz Chmielewski
http://wpkg.org
------------------------------
Date: 13 Feb 2008 14:57:36 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: DBI:mysql how to do multiple inserts/modification?
Message-Id: <slrnfr61b0.t9a.abigail@alexandra.abigail.be>
_
Tomasz Chmielewski (tch@nospam.syneticon.net) wrote on VCCLXXIX September
MCMXCIII in <URL:news:foutbp$tuk$1@online.de>:
-: How can I do multiple database modifications without writing too much code?
-:
-: For a single modification, I would write:
-:
-: $SQL = "INSERT INTO aaaaa..";
-: $db->do($SQL);
-:
-: How can I do it without repeating "$db->do($SQL);" each time?
The same as you do to avoid repeating writing the same line of code
which has nothing to do with databases: you'd write a loop.
-: Something like this throws an error, so obviously I must be missing
-: something.
-:
-: $SQL = "INSERT INTO aaaaa... ;
-: INSERT INTO bbbbb... ;
-: INSERT INTO bbbbb... ;";
-: $db->do($SQL);
for my $SQL ("INSERT INTO aaaaa...",
"INSERT INTO bbbbb...",
"INSERT INTO bbbbb...") {
$db -> do ($SQL);
}
Abigail
--
print 74.117.115.116.32.97.110.111.116.104.101.114.
32.80.101.114.108.32.72.97.99.107.101.114.10;
------------------------------
Date: Wed, 13 Feb 2008 07:08:29 -0800 (PST)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: DBI:mysql how to do multiple inserts/modification?
Message-Id: <51564d1d-5dc1-4e3b-b3d4-3569e6149d70@q77g2000hsh.googlegroups.com>
On Feb 13, 9:03=A0am, Tomasz Chmielewski <t...@nospam.syneticon.net>
wrote:
> How can I do multiple database modifications without writing too much code=
?
>
> For a single modification, I would write:
>
> $SQL =3D "INSERT INTO aaaaa..";
> $db->do($SQL);
>
> How can I do it without repeating "$db->do($SQL);" each time?
>
> Something like this throws an error, so obviously I must be missing
> something.
>
> $SQL =3D "INSERT INTO aaaaa... ;
> =A0 =A0 =A0 =A0 INSERT INTO bbbbb... ;
> =A0 =A0 =A0 =A0 INSERT INTO bbbbb... ;";
> $db->do($SQL);
uh. How about...
for my $stmt (split /;\n/, $SQL) {
$db->do($stmt);
}
Paul Lalli
------------------------------
Date: 13 Feb 2008 15:51:59 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: DBI:mysql how to do multiple inserts/modification?
Message-Id: <Xns9A43645D0B6D9castleamber@130.133.1.4>
Tomasz Chmielewski <tch@nospam.syneticon.net> wrote:
> How can I do multiple database modifications without writing too much
> code?
>
> For a single modification, I would write:
>
> $SQL = "INSERT INTO aaaaa..";
> $db->do($SQL);
>
> How can I do it without repeating "$db->do($SQL);" each time?
prepare the statement, and in a loop do $sth->execute( values )
--
John
Arachnids near Coyolillo - part 1
http://johnbokma.com/mexit/2006/05/04/arachnids-coyolillo-1.html
------------------------------
Date: Wed, 13 Feb 2008 22:48:19 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Help: Display the specific line in a file
Message-Id: <pan.2008.02.13.14.48.18.615262@gmail.com>
Hello,
I'm a sysadmin, I wanna write a small script to show information about
/proc directory. For example, I wanna show the cpuinfo file and just two
items "vendor_id" and "model name".
Here's the file (part):
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 8
model name : Pentium III (Coppermine)
stepping : 10
cpu MHz : 1000.045
..........
I suppose that I should use grep command to do that. However, I don't know
how to accomplish it.
Could you give me some tips?
Thank you very much.
Amy Lee
------------------------------
Date: 13 Feb 2008 15:00:14 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Help: Display the specific line in a file
Message-Id: <slrnfr61fu.t9a.abigail@alexandra.abigail.be>
_
Amy Lee (openlinuxsource@gmail.com) wrote on VCCLXXIX September MCMXCIII
in <URL:news:pan.2008.02.13.14.48.18.615262@gmail.com>:
@@ Hello,
@@
@@ I'm a sysadmin, I wanna write a small script to show information about
@@ /proc directory. For example, I wanna show the cpuinfo file and just two
@@ items "vendor_id" and "model name".
@@
@@ Here's the file (part):
@@ processor : 0
@@ vendor_id : GenuineIntel
@@ cpu family : 6
@@ model : 8
@@ model name : Pentium III (Coppermine)
@@ stepping : 10
@@ cpu MHz : 1000.045
@@ ..........
@@
@@ I suppose that I should use grep command to do that. However, I don't know
@@ how to accomplish it.
I'd use 'grep' as well, but I would ask my grep question in a Unix and/or
shell scripting group, not in a Perl language group.
Anyway, I'd use:
$ egrep '^vendor_id|^model name' /proc/cpuinfo
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
------------------------------
Date: Wed, 13 Feb 2008 16:06:29 +0100
From: Achim Peters <achimpeters@gmx.de>
Subject: Re: Help: Display the specific line in a file
Message-Id: <47B30775.3090307@gmx.de>
Amy Lee schrieb:
> I'm a sysadmin, I wanna write a small script to show information about
> /proc directory. For example, I wanna show the cpuinfo file and just two
> items "vendor_id" and "model name".
>
> Here's the file (part):
> processor : 0
> vendor_id : GenuineIntel
> cpu family : 6
> model : 8
> model name : Pentium III (Coppermine)
> stepping : 10
> cpu MHz : 1000.045
> ..........
>
> I suppose that I should use grep command to do that. However, I don't know
> how to accomplish it.
What's wrong with
#!/bin/sh
grep "^vendor_id" /proc/cpuinfo
grep "^model name" /proc/cpuinfo
except that it's not perl? For a "script" that has to "show the cpuinfo
file and just two items" you would not need perl, I presume.
If it has to be perl, the following might work for you
#!/usr/bin/perl
use strict;
use warnings;
open CPUINFO, "<", "/proc/cpuinfo"
or die "Can't open /proc/cpuinfo. $!";
while (<CPUINFO>) {
if ( /^vendor_id/ or /^model name/) {
print;
}
}
Bye
Achim
------------------------------
Date: Wed, 13 Feb 2008 23:20:00 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Re: Help: Display the specific line in a file
Message-Id: <pan.2008.02.13.15.19.59.465173@gmail.com>
On Wed, 13 Feb 2008 16:06:29 +0100, Achim Peters wrote:
> Amy Lee schrieb:
>> I'm a sysadmin, I wanna write a small script to show information about
>> /proc directory. For example, I wanna show the cpuinfo file and just two
>> items "vendor_id" and "model name".
>>
>> Here's the file (part):
>> processor : 0
>> vendor_id : GenuineIntel
>> cpu family : 6
>> model : 8
>> model name : Pentium III (Coppermine)
>> stepping : 10
>> cpu MHz : 1000.045
>> ..........
>>
>> I suppose that I should use grep command to do that. However, I don't know
>> how to accomplish it.
>
> What's wrong with
>
> #!/bin/sh
> grep "^vendor_id" /proc/cpuinfo
> grep "^model name" /proc/cpuinfo
>
> except that it's not perl? For a "script" that has to "show the cpuinfo
> file and just two items" you would not need perl, I presume.
>
> If it has to be perl, the following might work for you
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> open CPUINFO, "<", "/proc/cpuinfo"
> or die "Can't open /proc/cpuinfo. $!";
>
> while (<CPUINFO>) {
> if ( /^vendor_id/ or /^model name/) {
> print;
> }
> }
>
> Bye
> Achim
Thanks very much. Anyway, if I wanna change the output, just like replace
vendor_id to VENDOR, how can I do in your perl codes?
Thanks again.
Amy Lee
------------------------------
Date: Wed, 13 Feb 2008 15:29:01 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Help: Display the specific line in a file
Message-Id: <11Esj.21460$w57.1928@edtnps90>
Amy Lee wrote:
> On Wed, 13 Feb 2008 16:06:29 +0100, Achim Peters wrote:
>
>> Amy Lee schrieb:
>>> I'm a sysadmin, I wanna write a small script to show information about
>>> /proc directory. For example, I wanna show the cpuinfo file and just two
>>> items "vendor_id" and "model name".
>>>
>>> Here's the file (part):
>>> processor : 0
>>> vendor_id : GenuineIntel
>>> cpu family : 6
>>> model : 8
>>> model name : Pentium III (Coppermine)
>>> stepping : 10
>>> cpu MHz : 1000.045
>>> ..........
>>>
>>> I suppose that I should use grep command to do that. However, I don't know
>>> how to accomplish it.
>> What's wrong with
>>
>> #!/bin/sh
>> grep "^vendor_id" /proc/cpuinfo
>> grep "^model name" /proc/cpuinfo
>>
>> except that it's not perl? For a "script" that has to "show the cpuinfo
>> file and just two items" you would not need perl, I presume.
>>
>> If it has to be perl, the following might work for you
>>
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>>
>> open CPUINFO, "<", "/proc/cpuinfo"
>> or die "Can't open /proc/cpuinfo. $!";
>>
>> while (<CPUINFO>) {
>> if ( /^vendor_id/ or /^model name/) {
>> print;
>> }
>> }
>
> Thanks very much. Anyway, if I wanna change the output, just like replace
> vendor_id to VENDOR, how can I do in your perl codes?
while (<CPUINFO>) {
if ( s/^vendor_id/VENDOR/ or /^model name/ ) {
print;
}
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: Wed, 13 Feb 2008 16:34:16 +0100
From: Achim Peters <achimpeters@gmx.de>
Subject: Re: Help: Display the specific line in a file
Message-Id: <47B30DF8.6030500@gmx.de>
Amy Lee schrieb:
> On Wed, 13 Feb 2008 16:06:29 +0100, Achim Peters wrote:
>
>> Amy Lee schrieb:
>>> I'm a sysadmin, I wanna write a small script to show information about
>>> /proc directory.
>> If it has to be perl, the following might work for you
> Thanks very much. Anyway, if I wanna change the output, just like replace
> vendor_id to VENDOR, how can I do in your perl codes?
How about
$good_book = "Learning Perl";
$preferred_beverage = "Cup o'Tea";
# don't wanna recommend Cup o'Java here ...
open BOOK "<" $good_book or die $!;
while (<BOOK>) {
read;
sip($preferred_beverage);
}
first?
Bye
Achim
------------------------------
Date: Wed, 13 Feb 2008 23:38:40 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Re: Help: Display the specific line in a file
Message-Id: <pan.2008.02.13.15.38.39.259243@gmail.com>
On Wed, 13 Feb 2008 15:29:01 +0000, John W. Krahn wrote:
> Amy Lee wrote:
>> On Wed, 13 Feb 2008 16:06:29 +0100, Achim Peters wrote:
>>
>>> Amy Lee schrieb:
>>>> I'm a sysadmin, I wanna write a small script to show information about
>>>> /proc directory. For example, I wanna show the cpuinfo file and just two
>>>> items "vendor_id" and "model name".
>>>>
>>>> Here's the file (part):
>>>> processor : 0
>>>> vendor_id : GenuineIntel
>>>> cpu family : 6
>>>> model : 8
>>>> model name : Pentium III (Coppermine)
>>>> stepping : 10
>>>> cpu MHz : 1000.045
>>>> ..........
>>>>
>>>> I suppose that I should use grep command to do that. However, I don't know
>>>> how to accomplish it.
>>> What's wrong with
>>>
>>> #!/bin/sh
>>> grep "^vendor_id" /proc/cpuinfo
>>> grep "^model name" /proc/cpuinfo
>>>
>>> except that it's not perl? For a "script" that has to "show the cpuinfo
>>> file and just two items" you would not need perl, I presume.
>>>
>>> If it has to be perl, the following might work for you
>>>
>>> #!/usr/bin/perl
>>> use strict;
>>> use warnings;
>>>
>>> open CPUINFO, "<", "/proc/cpuinfo"
>>> or die "Can't open /proc/cpuinfo. $!";
>>>
>>> while (<CPUINFO>) {
>>> if ( /^vendor_id/ or /^model name/) {
>>> print;
>>> }
>>> }
>>
>> Thanks very much. Anyway, if I wanna change the output, just like replace
>> vendor_id to VENDOR, how can I do in your perl codes?
>
> while (<CPUINFO>) {
> if ( s/^vendor_id/VENDOR/ or /^model name/ ) {
> print;
> }
> }
>
>
> John
Thank you very much!
------------------------------
Date: Wed, 13 Feb 2008 12:24:59 +0100 (CET)
From: Stephan Mann <groups@stephan-mann.de>
Subject: Inverted RegEx on list of numbers
Message-Id: <fouk2b$rnt$1@aioe.org>
Hi!
I'm relatively new to Perl and I'm not a RegEx guru either. I'd like to
understand, why the following code does not work as I expect.
Obviously, I'm oblivious to some detail of how the RegEx engine works.
my @foo = ('one', 'two', 'three');
print join " ", grep { /[^(two)]/ } @foo, "\n";
my @bar = ('123:44', '123:45', '123:46');
print join " ", grep { /[^(123:45)]/ } @bar, "\n";
print join " ", grep { !/123:45/ } @bar, "\n";
Output:
one three
123:46
123:44 123:46
I'm completely lost as to why the second grep doesn't work like the first
one. The colon doesn't seem to be the problem, since the behavior stays
the same without it. How or why are numbers handled differently?!
The third grep works, but it forces me to handle this in a separate
RegEx which I can't extend if a want to do more with one RegEx.
tia, stephan
PS: This is my first post to a non-test group with slrn. Please let me
know if there is anything wrong with my post.
------------------------------
Date: Wed, 13 Feb 2008 12:40:46 +0100
From: Damian Lukowski <damian@tvk.rwth-aachen.de>
Subject: Re: Inverted RegEx on list of numbers
Message-Id: <61g39vF1s8fqmU1@mid.dfncis.de>
Stephan Mann schrieb:
> Hi!
>
> I'm relatively new to Perl and I'm not a RegEx guru either. I'd like to
> understand, why the following code does not work as I expect.
> Obviously, I'm oblivious to some detail of how the RegEx engine works.
>
> my @foo = ('one', 'two', 'three');
> print join " ", grep { /[^(two)]/ } @foo, "\n";
>
> my @bar = ('123:44', '123:45', '123:46');
> print join " ", grep { /[^(123:45)]/ } @bar, "\n";
> print join " ", grep { !/123:45/ } @bar, "\n";
[^(two)] is a character class, meaning a character which is neither '('
nor ')', nor 't', nor 'w', nor 'o', nor ')'.
"one" matches by /[^(two)]/, because there is a character 'n', which is
matched by [^(two)]. The same holds for 'h' in "three".
On the other hand, there is no character in "123:44" which is not an
'1', not an '2', and so on.
------------------------------
Date: 13 Feb 2008 12:06:20 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Inverted RegEx on list of numbers
Message-Id: <slrnfr5n9s.t9a.abigail@alexandra.abigail.be>
_
Stephan Mann (groups@stephan-mann.de) wrote on VCCLXXIX September
MCMXCIII in <URL:news:fouk2b$rnt$1@aioe.org>:
:} Hi!
:}
:} I'm relatively new to Perl and I'm not a RegEx guru either. I'd like to
:} understand, why the following code does not work as I expect.
:} Obviously, I'm oblivious to some detail of how the RegEx engine works.
:}
:} my @foo = ('one', 'two', 'three');
:} print join " ", grep { /[^(two)]/ } @foo, "\n";
:}
:} my @bar = ('123:44', '123:45', '123:46');
:} print join " ", grep { /[^(123:45)]/ } @bar, "\n";
:} print join " ", grep { !/123:45/ } @bar, "\n";
:}
:} Output:
:}
:} one three
:} 123:46
:} 123:44 123:46
:}
:} I'm completely lost as to why the second grep doesn't work like the first
:} one.
Because [] doesn't do what you think it does.
[...] always (*) matches exactly one character. Not zero. Not two. One
character. You list the characters you want to match inside the []; or,
if the first character is a ^, you list the characters that shouldn't match.
So, [^(two)] matches any character that isn't a '(', 't', 'w', 'o' or ')'.
Hence, the first grep returns "one" (as the 'n' is matched by /[^(two)]/)
and "three" (because of the match of 'h').
/[^(123:45)]/ matches anything that isn't a '(', '1', '2', '3', ':', '4',
'5', or ')'. Both '123:44' and '123:45' doesn't contain any character that
isn't listed, so they don't match. '123:46' contains a 6, so the regexp
matches.
:} The colon doesn't seem to be the problem, since the behavior stays
:} the same without it. How or why are numbers handled differently?!
:} The third grep works, but it forces me to handle this in a separate
:} RegEx which I can't extend if a want to do more with one RegEx.
It's not quite clear to me what you want.
Abigail
--
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s};;;
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)}; # Perl 5.6.0 broke this...
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))
------------------------------
Date: Wed, 13 Feb 2008 13:28:17 +0100
From: Achim Peters <achimpeters@gmx.de>
Subject: Re: Inverted RegEx on list of numbers
Message-Id: <47B2E261.9030108@gmx.de>
Stephan Mann schrieb:
> I'm relatively new to Perl and I'm not a RegEx guru either. I'd like to
> understand, why the following code does not work as I expect.
> Obviously, I'm oblivious to some detail of how the RegEx engine works.
You have a mere RE "problem". There is nothing perl specific in your
observations. I recommend reading more about RegExps. (Since your
problem is not perl related, any documentation about REs will do)
>
> my @foo = ('one', 'two', 'three');
> print join " ", grep { /[^(two)]/ } @foo, "\n";
>
> my @bar = ('123:44', '123:45', '123:46');
> print join " ", grep { /[^(123:45)]/ } @bar, "\n";
> print join " ", grep { !/123:45/ } @bar, "\n";
>
> Output:
>
> one three
> 123:46
> 123:44 123:46
>
> I'm completely lost as to why the second grep doesn't work like the first
> one.
The second grep _does_ work like the first one. Both just not the way
you expect them to work. ;-)
> How or why are numbers handled differently?!
Numbers per se are _not_ handled differently.
"[]" matches a single (one!) character, no matter how many characters
you list in between the "[" and the "]". A character of the expression
to be "grepped" matches the "[]" if and only if it is listed within the
"[]" (ranges and classes of matching characters are possible), given the
first character after the "[" is not a "^", or respectively matches if
and only if it is *not* listed, given the first character after the "["
is a "^".
So, it doesn't matter, whether you write
grep { /[^(two)]/ }
or
grep { /[^otw()]/ }
In both cases the expression will match _a_ _single_ _character_ which
is neither "o" nor "t" nor "w" nor "(" nor ")". Parentheses have no
special meaning within [].
'one' has a character which fulfills this expression: "n" ('one' has
even one more character, which does, but since your regex consisted only
of the [] the list item is already matched by the one matching character.
'two' does not have any such character (one that is not a "t" nor a "w"
nor an "o" nor a "(" nor a ")"
'three' has the "h" --> match (and furthermore the "r" and the "e".
I hope, you see by now, why
print join " ", grep { /[^(123:45)]/ } @bar, "\n";
worked the way it worked.
Bye
Achim
------------------------------
Date: Wed, 13 Feb 2008 13:57:57 +0100 (CET)
From: Stephan Mann <groups@stephan-mann.de>
Subject: Re: Inverted RegEx on list of numbers
Message-Id: <foupgl$e6r$1@aioe.org>
On 2008-02-13, Damian Lukowski <damian@tvk.rwth-aachen.de> wrote:
> Stephan Mann schrieb:
>> my @foo = ('one', 'two', 'three');
>> print join " ", grep { /[^(two)]/ } @foo, "\n";
>>
>> my @bar = ('123:44', '123:45', '123:46');
>> print join " ", grep { /[^(123:45)]/ } @bar, "\n";
>> print join " ", grep { !/123:45/ } @bar, "\n";
>
> [^(two)] is a character class, meaning a character which is neither '('
> nor ')', nor 't', nor 'w', nor 'o', nor ')'.
>
> "one" matches by /[^(two)]/, because there is a character 'n', which is
> matched by [^(two)]. The same holds for 'h' in "three".
>
> On the other hand, there is no character in "123:44" which is not an
> '1', not an '2', and so on.
Thank you very much, Damian. I was under the impression that the ()
inside the character class would be recognized and concatenate the
characters to a string (If I ever find this website again... Grr!).
After yet another hour of reading it became clear to me that there is no
way to write RegEx like "Match anything but this string" other than with
look-ahead/-behind. So my solution for now is
print join(" ", grep { /^(?!123:45)/ } @bar), "\n";
Hopefully this now works as intended, not only by accident.
greetings, stephan
------------------------------
Date: Wed, 13 Feb 2008 14:16:42 +0100 (CET)
From: Stephan Mann <groups@stephan-mann.de>
Subject: Re: Inverted RegEx on list of numbers
Message-Id: <fouqjq$i4q$1@aioe.org>
On 2008-02-13, Achim Peters <achimpeters@gmx.de> wrote:
> Stephan Mann schrieb:
>
>> I'm relatively new to Perl and I'm not a RegEx guru either. I'd like to
>> understand, why the following code does not work as I expect.
>> Obviously, I'm oblivious to some detail of how the RegEx engine works.
>
> You have a mere RE "problem". There is nothing perl specific in your
> observations. I recommend reading more about RegExps. (Since your
> problem is not perl related, any documentation about REs will do)
>
>> print join " ", grep { !/123:45/ } @bar, "\n";
The !/../ solution is Perl specific, isn't it? But of course you are
right, I got the RegEx completely wrong. Thank you and Abigail for the
detailed explanation.
greetings, stephan
------------------------------
Date: Wed, 13 Feb 2008 14:32:58 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Inverted RegEx on list of numbers
Message-Id: <ucDsj.21451$w57.18288@edtnps90>
Stephan Mann wrote:
> On 2008-02-13, Damian Lukowski <damian@tvk.rwth-aachen.de> wrote:
>> Stephan Mann schrieb:
>>> my @foo = ('one', 'two', 'three');
>>> print join " ", grep { /[^(two)]/ } @foo, "\n";
>>>
>>> my @bar = ('123:44', '123:45', '123:46');
>>> print join " ", grep { /[^(123:45)]/ } @bar, "\n";
>>> print join " ", grep { !/123:45/ } @bar, "\n";
>> [^(two)] is a character class, meaning a character which is neither '('
>> nor ')', nor 't', nor 'w', nor 'o', nor ')'.
>>
>> "one" matches by /[^(two)]/, because there is a character 'n', which is
>> matched by [^(two)]. The same holds for 'h' in "three".
>>
>> On the other hand, there is no character in "123:44" which is not an
>> '1', not an '2', and so on.
>
> Thank you very much, Damian. I was under the impression that the ()
> inside the character class would be recognized and concatenate the
> characters to a string (If I ever find this website again... Grr!).
>
> After yet another hour of reading it became clear to me that there is no
> way to write RegEx like "Match anything but this string" other than with
> look-ahead/-behind. So my solution for now is
>
> print join(" ", grep { /^(?!123:45)/ } @bar), "\n";
>
> Hopefully this now works as intended, not only by accident.
It looks like from your example you could also do:
print join( " ", grep !/^123:45$/, @bar ), "\n";
Or:
print join( " ", grep $_ ne '123:45', @bar ), "\n";
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: 13 Feb 2008 15:03:13 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Inverted RegEx on list of numbers
Message-Id: <slrnfr61lg.t9a.abigail@alexandra.abigail.be>
_
Stephan Mann (groups@stephan-mann.de) wrote on VCCLXXIX September
MCMXCIII in <URL:news:foupgl$e6r$1@aioe.org>:
@@ On 2008-02-13, Damian Lukowski <damian@tvk.rwth-aachen.de> wrote:
@@ > Stephan Mann schrieb:
@@ >> my @foo = ('one', 'two', 'three');
@@ >> print join " ", grep { /[^(two)]/ } @foo, "\n";
@@ >>
@@ >> my @bar = ('123:44', '123:45', '123:46');
@@ >> print join " ", grep { /[^(123:45)]/ } @bar, "\n";
@@ >> print join " ", grep { !/123:45/ } @bar, "\n";
@@ >
@@ > [^(two)] is a character class, meaning a character which is neither '('
@@ > nor ')', nor 't', nor 'w', nor 'o', nor ')'.
@@ >
@@ > "one" matches by /[^(two)]/, because there is a character 'n', which is
@@ > matched by [^(two)]. The same holds for 'h' in "three".
@@ >
@@ > On the other hand, there is no character in "123:44" which is not an
@@ > '1', not an '2', and so on.
@@
@@ Thank you very much, Damian. I was under the impression that the ()
@@ inside the character class would be recognized and concatenate the
@@ characters to a string (If I ever find this website again... Grr!).
@@
@@ After yet another hour of reading it became clear to me that there is no
@@ way to write RegEx like "Match anything but this string" other than with
@@ look-ahead/-behind. So my solution for now is
Well, it can, but it's awkward. Even I would use look-ahead if I can't
take the negation out of the regexp.
@@ print join(" ", grep { /^(?!123:45)/ } @bar), "\n";
@@
@@ Hopefully this now works as intended, not only by accident.
That would filter out '123:456' - I do not know whether you intent that
or not.
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
------------------------------
Date: 13 Feb 2008 11:25:16 GMT
From: Heinrich.Mislik@univie.ac.at (Heinrich Mislik)
Subject: Re: oracle RAW data type and dbi
Message-Id: <47b2d39b$0$11610$3b214f66@usenet.univie.ac.at>
In article <fosetf024fq@drn.newsguy.com>, dcruncher4@aim.com says...
>we are storing binary data in an oracle table as RAW data type. Oracle
>converts RAW data type into hex values at the time of storing. When I
>view the data thru sqlplus I see it as hex.
>
>Obviously it has to be converted back to original value when we fetch it.
>It seems it is not happening.
>
>use DBD::Oracle qw(:ora_types);
>$o_sth->bind_col(1,\$binvalue,{ ora_type => ORA_RAW } ) ;
>
>when I do print $binvalue, I see it as hex only? Why?
>Curiously Pro-C converts that to original form.
perldoc DBD::Oralce does not mention bin_col anywhere. It seems, that ora_types can only be used with bin_param.
Here is a crazy workaround that seems to work:
use DBD::Oracle ':ora_types';
my $sth=$dbh->prepare('begin select my_raw_column into ? from some_table;end;');
$sth->bind_param_inout(1,\my $val,100,{ora_type => ORA_RAW});
$sth->execute;
print $val'
Cheers
Heinrich
--
Heinrich Mislik
Zentraler Informatikdienst der Universitaet Wien
A-1010 Wien, Universitaetsstrasse 7
Tel.: (+43 1) 4277-14056, Fax: (+43 1) 4277-9140
------------------------------
Date: Wed, 13 Feb 2008 00:25:14 -0800 (PST)
From: ulrich_martin@seznam.cz
Subject: Regex /(X*)/
Message-Id: <d33c34f4-2e9a-4760-97f1-ff2637e82d4c@v46g2000hsv.googlegroups.com>
Hello,
I would like to ask you for help. Could anybody explain me, why regex
"/(X*)/" is not able to catch X in string "aXXXb". Quantifier "*" in
this regex is a greedy one and there is not anchor "^", so I would
expect, that $1 would contain XXX. I know (I have read it), that it is
possible to use + instead of *, but I would like to know, why the "*"
quantifier doesn't catch it.
I have found this example in perlretut:
Finally,
"aXXXb" =~ /(X*)/; # matches with $1 = ''
because it can match zero copies of 'X' at the beginning of
the string. If you definitely want to match at least one
'X', use "X+", not "X*".
M.
------------------------------
Date: Wed, 13 Feb 2008 09:38:43 +0100
From: Damian Lukowski <damian@tvk.rwth-aachen.de>
Subject: Re: Regex /(X*)/
Message-Id: <61fokjF1uvutaU1@mid.dfncis.de>
ulrich_martin@seznam.cz schrieb:
> I have found this example in perlretut:
> Finally,
> "aXXXb" =~ /(X*)/; # matches with $1 = ''
> because it can match zero copies of 'X' at the beginning of
> the string. If you definitely want to match at least one
> 'X', use "X+", not "X*".
Well, that is the explanation. Perl tries to match as soon as possible.
"Sooner" is more important than "longer".
------------------------------
Date: Wed, 13 Feb 2008 07:04:12 -0800 (PST)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Regex /(X*)/
Message-Id: <b5c04816-10c0-4ee5-8366-a134abebfed9@v46g2000hsv.googlegroups.com>
On Feb 13, 3:25=A0am, ulrich_mar...@seznam.cz wrote:
> Hello,
>
> I would like to ask you for help. Could anybody explain me, why regex
> "/(X*)/" is not able to catch X in string "aXXXb". Quantifier "*" in
> this regex is a greedy one and there is not anchor "^", so I would
> expect, that $1 would contain XXX. I know (I have read it), that it is
> possible to use + instead of *, but I would like to know, why the "*"
> quantifier doesn't catch it.
>
> I have found this example in perlretut:
> Finally,
> "aXXXb" =3D~ /(X*)/; # matches with $1 =3D ''
> because it can match zero copies of 'X' at the beginning of
> the string. =A0If you definitely want to match at least one
> 'X', use "X+", not "X*".
Because greediness takes second place to position. Perl attempts to
find the FIRST match that it can. Once it's started successfully
matching, only then does the greediness of quantifiers come into play.
Take a look at all the places /(X*)/ could match aXXXb....
while ("aXXXb" =3D~ /(X*)/g) {
print "$`<<$&>>$'\n";
}
<<>>aXXXb
a<<XXX>>b
aXXX<<>>b
aXXXb<<>>
The first time through, it matches right at the beginning of the
string.
The second time through, it matches the XXX
The third time through, it matches between the X and the b
The final time through, it maches after the b, at the end of the
string.
Paul Lalli
------------------------------
Date: Wed, 13 Feb 2008 15:25:53 -0000
From: "John" <john1949@yahoo.com>
Subject: Re: SOAP::Lite - getting WSDL using basic authentication
Message-Id: <p_Odncg5QfudkS7anZ2dnUVZ8qydnZ2d@eclipse.net.uk>
"J. Gleixner" <glex_no-spam@qwest-spam-no.invalid> wrote in message
news:47b209b7$0$3575$815e3792@news.qwest.net...
> I'm trying to find "the" method, using SOAP::Lite or SOAP::Schema,
> to get a WSDL that requires HTTP authentication.
>
> The only way I've been able to get a WSDL that requires basic
> authentication is by over-riding the SOAP::Schema::access method:
>
> e.g.
>
> use SOAP::Lite;
>
> my $login = 'mylogin';
> my $pw = 'mypassword';
>
> my $service = SOAP::Lite
> -> service( 'http://some.server.com/some/protected/path/my.wsdl' );
> #$service->some_method();
>
> # over-ride method to handle authentication
> sub SOAP::Schema::access
> {
> my $self = shift->new;
> my $url = shift || $self->schema_url || Carp::croak 'Nothing to access.
> URL is not specified';
>
> my $req = HTTP::Request->new(GET => $url);
>
> # this is why it's over-ridden
> $req->authorization_basic($login, $pw);
>
> my $resp = $self->useragent->request($req);
> $resp->is_success ? $resp->content : die "Service description '$url'
> can't be loaded: ", $resp->status_line, "\n";
> }
>
> # and get_basic_credentials for the service calls,
> # if they require authentication
> sub SOAP::Transport::HTTP::Client::get_basic_credentials
> {
> return $login => $pw;
> }
>
>
>
> In the Changelog for SOAP::Lite it shows:
>
> 0.65-beta2 Mon Oct 25 2004
> [...]
> + Added SOAP::Schema->useragent - which returns the LWP::UserAgent
> instance that will be used when accessing WSDLs via the
> SOAP::Lite->service call. This is helpful when access to a WSDL
> requires authentication, etc.
>
> Using S::S->useragent() and the additional LWP methods for
> authentication, I can GET the WDSL, however I don't see how that
> can be used in SOAP::Schema and by SOAP::Lite without over-riding
> the access method. Over-riding it does work, but I'm looking for
> how it should be done.
Hi
I appreciate that WDSL and SOAP are not the same thing, but the following
may help.
I've cut and pasted from our site.
Regards
John
sub new {
# constructor always called new
my $type=shift;
my $self={};
$self->{USERNAME}='hallo';
$self->{PASSWORD}='goodbye';
$self->{NAMESPACE}='http://webservices.example.com';
$self->{ENDPOINT}='https://example.com/B2BGateway/service/XMLSelect';
return bless $self,$type
}
# ------------------------------------------------------------------------------------------
sub connect_Server {
my $self=shift; # grab the 'self' pointer to this object
use Compress::Zlib;
use SOAP::Lite +trace => 'debug';
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{return $self->{USERNAME} => $self->{PASSWORD}}
return
}
# ------------------------------------------------------------------------------------------
------------------------------
Date: Wed, 13 Feb 2008 07:05:43 -0800 (PST)
From: "blaine@worldweb.com" <blaine@worldweb.com>
Subject: Re: Win32::MMF What's going on?
Message-Id: <8c1d1240-1673-4da8-948d-1e6a585082a0@c23g2000hsa.googlegroups.com>
On Feb 13, 12:10 am, "John W. Krahn" <some...@example.com> wrote:
> bla...@worldweb.com wrote:
>
> > I'm trying to write perl in windows environment and need to use the
> > package win32::mmf. Anyhow, I've got some test code below that will
> > write to the windows namespace but will not retrieve from it. Please
> > note it's just an example in production I would be writing to the ns
> > in one script and grabbing from the ns in another.
>
> > For some reason the second instance of mmf is not accessing the same
> > namespace. Any ideas?
>
> > my $mmf = Win32::MMF->new( -swapfile => "data.swp",
> > -namespace => "MyDataShare",
> > -size => 1024 * 1024 )
> > or die "\n\n\n\nCan not create namespace";
>
> > $mmf->setvar($tokenKey, $hashRef);
> > print "\n\n " . $mmf->debug();
>
> > print "\n\n<BR>--------------";
>
> > undef $mmf;
>
> perldoc Win32::MMF
> [ SNIP ]
> Note that there is no need to explicitly unmap the view, close the
> namespace and close the swap file in object-oriented mode, the view,
> namespace and swap file handles are automatically closed-off and
> disposed of when the Win32::MMF object falls out of scope.
>
> "undef $mmf" effectively closes and disposes of the MMF. Opening a new
> MMF will open a new clean disk file.
>
> > my $mmf = Win32::MMF->new( -swapfile => "data.swp",
> > -namespace => "MyDataShare",
> > -size => 1024 * 1024 ,
>
> > )
> > or die "\n\n\n\nCan not create namespace";
>
> > print Data::Dumper->Dump( [ $mmf->getvar($tokenKey) ] );
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. -- Larry Wall
Hi John,
The above was an example of trying to use the same MMF in two
programs. So I just undef in between to show this example. However
that being said I see your point about disposing of the MMF.
How can I
1) Create a mmf in a script and save variables
2) Access the mmf in a different script ran at a different time and
get retreive the saved variables
Thanks!
Blaine
------------------------------
Date: Wed, 13 Feb 2008 15:24:31 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Win32::MMF What's going on?
Message-Id: <PYDsj.21459$w57.18278@edtnps90>
blaine@worldweb.com wrote:
>
> On Feb 13, 12:10 am, "John W. Krahn" <some...@example.com> wrote:
>>
>> bla...@worldweb.com wrote:
>>
>>> I'm trying to write perl in windows environment and need to use the
>>> package win32::mmf. Anyhow, I've got some test code below that will
>>> write to the windows namespace but will not retrieve from it. Please
>>> note it's just an example in production I would be writing to the ns
>>> in one script and grabbing from the ns in another.
>>> For some reason the second instance of mmf is not accessing the same
>>> namespace. Any ideas?
>>> my $mmf = Win32::MMF->new( -swapfile => "data.swp",
>>> -namespace => "MyDataShare",
>>> -size => 1024 * 1024 )
>>> or die "\n\n\n\nCan not create namespace";
>>> $mmf->setvar($tokenKey, $hashRef);
>>> print "\n\n " . $mmf->debug();
>>> print "\n\n<BR>--------------";
>>> undef $mmf;
>>
>> perldoc Win32::MMF
>> [ SNIP ]
>> Note that there is no need to explicitly unmap the view, close the
>> namespace and close the swap file in object-oriented mode, the view,
>> namespace and swap file handles are automatically closed-off and
>> disposed of when the Win32::MMF object falls out of scope.
>>
>> "undef $mmf" effectively closes and disposes of the MMF. Opening a new
>> MMF will open a new clean disk file.
>
> The above was an example of trying to use the same MMF in two
> programs. So I just undef in between to show this example. However
> that being said I see your point about disposing of the MMF.
>
> How can I
>
> 1) Create a mmf in a script and save variables
> 2) Access the mmf in a different script ran at a different time and
> get retreive the saved variables
Just from reading the documentation (I don't have Windows to test on)
create the namespace file in a known location and use the -reuse option
to prevent the deletion of the file.
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
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 1274
***************************************