[24079] in Perl-Users-Digest
Perl-Users Digest, Issue: 6273 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 18 09:05:50 2004
Date: Thu, 18 Mar 2004 06:05:08 -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, 18 Mar 2004 Volume: 10 Number: 6273
Today's topics:
a doubt in unicode sub-properties <yamini_rajan@nospam.com>
Re: array of array (Andrea Spitaleri)
Re: CPAN module install error <roel-perl@st2x.net>
Re: Empty hash key produces funky results <gnari@simnet.is>
Re: Empty hash key produces funky results <vetro@online.no>
Re: Empty hash key produces funky results <roel-perl@st2x.net>
Re: Having problems with with the s/// substitution <tore@aursand.no>
Re: Having problems with with the s/// substitution <tore@aursand.no>
Re: How to fill a hash from the products of a split moller@notvalid.se
Re: HOW TO PARSE A VAST FILE! <luke@program.com.tw>
Re: HOW TO PARSE A VAST FILE! <gnari@simnet.is>
Re: List Scalar Hash question moller@notvalid.se
Newbie: Problem w/ increasing memory allocation <calliesam@ev1.net>
Re: Our Robin has flown the nest <me@privacy.net>
Re: perl2exe can't locate DBI.pm (Bunny)
Problem solved! (Piet)
Re: Problem solved! (Anno Siegel)
Reseting numbered variables (Toni)
Re: Reseting numbered variables (Anno Siegel)
Re: Reseting numbered variables <gnari@simnet.is>
Re: Reseting numbered variables (Anno Siegel)
reverse search modifier (S Raven)
Re: reverse search modifier (Anno Siegel)
Searching on the internet with regex (stef)
Re: stripping out ASCII chars using regexp? (Anno Siegel)
Re: truncated data after INSERT with undef in DBI - bug <irhm@clara.net>
Re: Variable interpolation in regular expressions (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 18 Mar 2004 04:51:04 -0600
From: "yamini" <yamini_rajan@nospam.com>
Subject: a doubt in unicode sub-properties
Message-Id: <28f8f44f19dc014df60ed525a0315faf@localhost.talkaboutprogramming.com>
hi,
i want to minus the words "of ","in" from the \p{Ll} class.
[\p{Ll}&&[^ofin]] i tried with this.but its not working.
can anyone help me in tracing the mistake i have done here?
thanks
------------------------------
Date: 18 Mar 2004 03:16:04 -0800
From: spiritelllo@interfree.it (Andrea Spitaleri)
Subject: Re: array of array
Message-Id: <4de1519a.0403180316.409ff066@posting.google.com>
about (untested):
>
> use strict;
> open(FILE,"test") || die "cannot open test: $!";
> my %foo;
> while (<FILE>) {
> chomp;
> my ($key, $value) = split(' ', $_, 2);
> push @{$foo{$key}}, $value;
> }
> print "$_ @{$foo{$_}}\n" for sort keys %foo;
good....and of course:
.......
my ($key, $value,$res) = split(' ', $_, 3);
push @{$foo{$key}}, $value,$res;
}
print "$_ @{$foo{$_}}\n" for sort keys %foo;
I changed in such way (so the input) because sometime my keys are equal. i.e.:
0.1 a --> 1 0.1 a
0.2 b --> 2 0.2 b
0.2 c --> 3 0.2 c
0.1 d --> 4 0.1 d
0.2 e --> 5 0.2 e
0.2 f --> 6 0.2 f
it works .....
and
------------------------------
Date: 18 Mar 2004 08:52:16 GMT
From: Roel van der Steen <roel-perl@st2x.net>
Subject: Re: CPAN module install error
Message-Id: <slrnc5ioq8.vku.roel-perl@localhost.localdomain>
On Wed, 17 Mar 2004 at 21:26 GMT, Page <dummymb@hotmail.com> wrote:
> I tried to install a module on my WinXP machine using the CPAN
> installer. Everything seemed to go well, but the modules aren't being
Have you built other modules with success using this setup? Otherwise
I'd say the nmake/make difference is confusing the CPAN module. You
can try to "perl Makefile.PL && nmake test install" from the command
prompt though. Make sure you have "nmake.exe".
------------------------------
Date: Thu, 18 Mar 2004 08:48:34 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Empty hash key produces funky results
Message-Id: <c3bnr2$5aa$1@news.simnet.is>
"Aaron DeLoach" <aaron@deloachcorp.com> wrote in message
news:ENidnQUIQLxpz8TdRVn-sw@eatel.net...
[still top-posting, i see]
> I found a solution to the problem. Thought I might share it.
>
> I was assigning parameter values to a hash like so:
> 1=>param('one'), 2=>param('two') ... and so on.
this was not your problem.
gnari
------------------------------
Date: Thu, 18 Mar 2004 10:27:06 +0100
From: Vetle Roeim <vetro@online.no>
Subject: Re: Empty hash key produces funky results
Message-Id: <m3ish24iad.fsf@quimby.dirtyhack.org>
* Aaron DeLoach
> "Uri Guttman" <uri@stemsystems.com> wrote in message
> news:x74qsmg3mk.fsf@mail.sysarch.com...
>> >>>>> "AD" == Aaron DeLoach <aaron@deloachcorp.com> writes:
>>
>> AD> Well explain this:
>> AD> 1=>"one", 2=>"two", 3=>, 4=>"four";
>>
>> AD> Let's say: 3=>param('some_param') - where "some_param" had no value
> or
>> AD> didn't exist.
>>
>> and why would that be any different? what is =>? why would it change
>> things?
>
> That's why I'm asking a question. Looking for an answer to something I
> don't understand.
>
> How would one compensate for the empty/missing param in the example above?
> I don't know?
First, look up the meaning of => in perlop... It will proably help
you understand the difference between writing '3 =>,' and '3,,'.
Second, why don't you use an empty string or undef value? For instance
3 => '' or 3 => undef?
(...)
--
#!/usr/bin/vr
------------------------------
Date: 18 Mar 2004 09:43:09 GMT
From: Roel van der Steen <roel-perl@st2x.net>
Subject: Re: Empty hash key produces funky results
Message-Id: <slrnc5irpl.vnt.roel-perl@localhost.localdomain>
On Thu, 18 Mar 2004 at 07:42 GMT, Aaron DeLoach <aaron@deloachcorp.com> wrote:
> I was assigning parameter values to a hash like so:
> 1=>param('one'), 2=>param('two') ... and so on.
<snip>
> The solution:
> 1=>param('one')||"", 2=>param('two')||"" ... and so on.
To avoid this dreadfull syntax I'd recommend creating the hash first
and subsequently changing the values by calling param() in a seperate pass.
#!/usr/bin/perl
use strict;
use warnings;
my %hash = (
1 => 'one',
2 => 'two',
3 => 'three',
4 => 'four',
);
$_ = param($_) foreach values %hash; # values get aliased to $_ one by one
print "$_ ==> $hash{$_}\n" foreach sort keys %hash; # (little private dumper)
# "param" would be a complex sub in real life
sub param { uc shift }
__END__
------------------------------
Date: Thu, 18 Mar 2004 13:18:47 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Having problems with with the s/// substitution
Message-Id: <pan.2004.03.17.11.50.32.792042@aursand.no>
On Tue, 16 Mar 2004 21:00:00 +0000, John W. Krahn wrote:
>>> line 1 while (<WEBINP>){
>>> line 2
>>> line 3 while (m{(\D)(\d{4})(\D)}g){ line 4 $l =
>>> find($2,@list);
>>> line 5 s/$2/$l/; }
>>> line 6
>>> line 7 print WEBOUT $_;
>>> line 8 }
>> Why do you set $1? From the code above, $1 will always be set by the
>> script to a non-digit value.
> Put your reading glasses on Tore. :-) The OP is using a lower case L,
> not the digit one.
Agh. Whoa. Try typing '$1' and '$l' by using the Courier font; I think
there's only one pixel which differs, or something like that, and imagine
spotting that one pixel when you're running 1600x1200. :)
--
Tore Aursand <tore@aursand.no>
"A teacher is never a giver of truth - he is a guide, a pointer to the
truth that each student must find for himself. A good teacher is
merely a catalyst." -- Bruce Lee
------------------------------
Date: Thu, 18 Mar 2004 13:28:18 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Having problems with with the s/// substitution
Message-Id: <pan.2004.03.18.12.27.35.540857@aursand.no>
On Wed, 17 Mar 2004 10:01:58 -0800, Hakan Bacakoglu wrote:
> Thank you all for the response.
Don't top-post!
> First, someone was asking for the sample data file:
>
> -----------------------------------------------------
> <TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
> COLOR=#000000>0970</FONT></TD>
> <TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
> COLOR=#000000>0976</FONT></TD>
> <TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
> COLOR=#000000>0061</FONT></TD>
> <TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
> COLOR=#000000>0349<BR>0350<BR>0351<BR>0352<BR>0353<BR>0354<BR>0355<BR>0356<BR>0357<BR>0358</FONT></TD>
> <TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
> COLOR=#000000>125</FONT></TD>
> <TD BORDERCOLOR=#c0c0c0 ><FONT SIZE=2 FACE="Arial"
> COLOR=#000000><BR></FONT></TD>
> -----------------------------------------------------
>
> Second, I ended up using the following code (probably not a very
> graceful code, but worked for a beginner like me). I will try the
> other suggestions.
>
> while (<WEBINP>){
> $codes = $_;
> $codes =~ s/(\D)(\d{4})(\D)/(&find($2,@list))/ge;
> print WEBOUT $codes;
> }
IMO, this is better written as:
while ( <WEBINP> ) {
s{>(\d{4})<}{ find($1, \@list) }eg;
print;
}
--
Tore Aursand <tore@aursand.no>
"The purpose of all war is ultimately peace." -- Saint Augustine
------------------------------
Date: Thu, 18 Mar 2004 08:20:22 GMT
From: moller@notvalid.se
Subject: Re: How to fill a hash from the products of a split
Message-Id: <uish2k1mc.fsf@notvalid.se>
Jim Gibson <jgibson@mail.arc.nasa.gov> writes:
> In article <uznafjepf.fsf@notvalid.se>, <moller@notvalid.se> wrote:
>
> > Uri Guttman <uri@stemsystems.com> writes:
> >
> > > >>>>> "ga" == gabe anzelini <usenet@c0s.org> writes:
> > >
> > > ga> what I would do:
> > > ga> map{
> > > ga> $img_titles{$1}=$2 if /(.*?)\t(.*)/;
> > > ga> }<TITLEFILE>;
> > >
> > > another map in void context!!!
> > >
> > > and in this case not needed so no fighting.
> > >
> > > use File::Slurp ;
> > >
> > > my $text = read_file( 'whatever' ) ;
> > >
> > > my %img_titles = $text =~ /^(.*?)\t(.*)/gm ;
> >
> > Please someone!! Explain this line to a noob.....
>
> I'll give it a shot (and I am sure someone will correct me if I am
> wrong).
>
> $text contains the contents of the file as a scalar string with
> embedded newlines. The lines consist of two words separated by tab
> characters. The expression '$text =~ /^(.*?)\t(.*)/gm' returns all of
> the pairs of words in the file (see the g and m modifiers to the match
> operator m/// and the non-greedy qualifier '?'). These pairs are used
> to populate the %img_titles hash, with the first word in each pair
> becoming the key and the second becoming the value. So if the line
> "key\tvalue\n" exists in the file, $img_titles{'key'} will be equal to
> 'value'.
>
> Good enough?
Yes. I got the regular expression part. It was the assignment bit that
threw me off.
Im not used to things returning two or more things.
And I have not used =~ yet so I'm a bit unsure how it works. But no
need to tell me I'm reading the Programming Perl 3:d ed when I have
time.
And I'm not used to languages that help you as much as perl does. In
retrospekt it seems obvious that if you assign a pair to a hash one
becomes the key and the other the value...
After using perl for two months I'm still trying not to write c-code in perl.
Thanks
------------------------------
Date: Thu, 18 Mar 2004 16:11:32 +0800
From: "news.hinet.net" <luke@program.com.tw>
Subject: Re: HOW TO PARSE A VAST FILE!
Message-Id: <c3blmp$4lv@netnews.hinet.net>
No ! This logfile is single one in every hour and i will parse data from
top to bottom everytime
I must load history from mysql to hash today and pasre this file avoid
duplicate data!
Query data from mysql and put into hash is fast,but i must load file
and use do loop to find duplicate data. if yes then reject or insert into
database.
The bottleneck may be in do loop procedure.
Have any other method can do this job?
"Todd de Gruyl" <todd@tdegruyl.com> ???
news:190oi1-9l8.ln1@espresso.tdegruyl.com ???...
> news.hinet.net wrote:
>
> > I must parse 500M's logfile!
>
> EEEK! the horror! Does the file have to grow that huge? Is it a
> standard log format, with new records being appended to the bottom of
> the file? If so, I would suggest that you (or appeal to the powers that
> be) split the file up, and save the parsed data from the pieces that
> will not change (that is, the parts of the file that are not the one
> being appeneded to). That would cut the process down to a managable
> size if it is done on a reasonable basis. All of this only makes sense
> if the log isn't being generated in its entirety between each running of
> the parser.
>
> > How to do this job while speed up.
> > Someone can give me good idea for this job.
> > Split file to small one and use fork to do that or
> > other method can make good result.
>
> YMMV depending on what kind of processor(s) you are running the process
> on, your disk setup, etc, whether fork()ing will do any good. All i
> can suggest is try it and see.
>
> > ps: its spend 3 hours to complete now!
>
> How often does the job run?
> What else is involved?
> What's the bottleneck? (disk access? the parsing subs? trying to slurp a
> 500MB file?) Without further info, it is difficult to help.
>
> --
> Todd de Gruyl
> todd@tdegruyl.com
> http://www.tdegruyl.com
------------------------------
Date: Thu, 18 Mar 2004 08:39:13 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: HOW TO PARSE A VAST FILE!
Message-Id: <c3bn5a$58u$1@news.simnet.is>
"news.hinet.net" <luke@program.com.tw> TOP-POSTED in message
news:c3blmp$4lv@netnews.hinet.net...
[please do not top-post]
> I must load history from mysql to hash today and pasre this file avoid
> duplicate data!
be more specific.
to avoid duplicate data, use a hash
what do you mean "from mysql to hash" ? what is the problem?
>
> Query data from mysql and put into hash is fast,but i must load file
> and use do loop to find duplicate data. if yes then reject or insert into
> database.
>
> Have any other method can do this job?
sounds like a hash should do it
gnari
[snip rest of fullu quoted thread]
------------------------------
Date: Thu, 18 Mar 2004 08:05:28 GMT
From: moller@notvalid.se
Subject: Re: List Scalar Hash question
Message-Id: <uoequk2ba.fsf@notvalid.se>
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> writes:
> Also sprach moller@notvalid.se:
>
> > "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> writes:
> >
> >> Also sprach moller@notvalid.se:
> >>
> >> > Please look at my small example below.
> >> >
> >> > Why does @cdir get an extra undefined element in
> >> > the first assignment?
> >> >
<snip of code>
> >>
> >> Maybe this post is a good example why sometimes spurious initialization
> >> (when done improperly) can harm. We had this discussion recently.
> >
> > Do you remember the subject so that I can google for it?
>
> The thread started with ID <FoL3c.7518$xL3.215@bignews1.bellsouth.net>.
> Subject was "variable initialization question".
>
> > What should I do instead? Should I test to see if the hash is undefined
> > and then use an empty list instead?
>
> Yes:
>
> my @cdir = defined $UserID{'(000883)'}{ dir }
> ? $UserID{'(000883)'}{ dir }
> : ();
>
> Another way would be:
>
> my @cdir;
> if (defined $UserID{'(000883)'}{ dir }) {
> push @cdir, $UserID{'(000883)'}{ dir };
> }
>
> Or you just assign regardless of definedness, and later nuke all
> undefined values from the @array:
>
> my @cdir = $UserID{'(000883)'}{ dir };
> ...
>
> @cdir = grep defined, @cdir;
>
> I'd probably go for the latter as it is less to type and doesn't clutter
> the initialization process. "$UserID{'(000883)'}{ dir }" is a pretty
> long hash subscript which I would try to avoid using too often.
In the normal code '(000883)' is a variable collected elswhere. I'll go with
your last example. Less typing and it looks like I know what I'm doing :-)
Thank you very much.
------------------------------
Date: Thu, 18 Mar 2004 02:39:06 -0600
From: Samuel H Roseman <calliesam@ev1.net>
Subject: Newbie: Problem w/ increasing memory allocation
Message-Id: <4059602A.2090903@ev1.net>
OS: SuSE Linux 8.1
Version: Summary of my perl5 (revision 5.0 version 8 subversion 0)
Problem: Processing output from "tcpdump" cause increasing memory
allocation.
I have to stop and restart to release the memory.
Question: What am I doing wrong in my script? THANKS
Excerpts from my perl script:
#
# start tcpdump and pipe its output to this perl script
#
open NETDMP
,"tcpdump -i $ARGV[0] -nttttvvv 2>/dev/null |"
or
die "can't fork $!"
;
#
.
.
.
#
# Loop where increasing memory allocation must be occurring.
#
while (<NETDMP>)
{
if (m#(\d{2}\/\d{2}/\d{4} \d{2}:\d{2}:\d{2}\.\d{6})
(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\.(\d{1,}) >
(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\.(
\d{1,})(.*)#)
{
#
# Insert non ARP information
#
$sth->execute("$1 00:00","$ARGV[0]","$2","$4",$3,$5,"$6")
or die "Unable to perform insert\n"
;
$dbh->commit;
}
elsif (m#(\d{2}\/\d{2}/\d{4} \d{2}:\d{2}:\d{2}\.\d{6}) arp who-has
(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) tell (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{
1,3}).*#)
{
#
# Insert ARP information
#
$sth2->execute("$1 00:00","$ARGV[0]","$2","$3")
or die "Unable to perform insert\n"
;
$dbh->commit;
} # end if
} # end while
------------------------------
Date: Thu, 18 Mar 2004 23:37:15 +1300
From: "Tintin" <me@privacy.net>
Subject: Re: Our Robin has flown the nest
Message-Id: <c3bu86$26ipa2$1@ID-172104.news.uni-berlin.de>
>"Kirk Strauser" <kirk@strauser.com> wrote in message
news:87lllzgv27.fsf@strauser.com...
>
>
>OK, I really don't want to be a jerk, but I just couldn't resist this
"where
>are they now?" update. Something reminded me of our young acolyte, Robin,
>and his attempts to learn Perl without actually having to learn Perl.
>
>His web board (yes, he really put it online):
>
> http://www.infusedlight.net/design/bbs/bbs.pl?action=view&user=sysop
>
> Choice quote:
>
> "post: I think this board is awesome. Props to robin for his amazing cgi
> skills, and self-props to me for the style sheet."
Even better is the comments in lib.pl
"# Distribute at your own risk
# Please do not modify library functions attempt to profit from distribution
# Or I will hunt you down and prosecute your ass"
Damm!! I was so tempted to use that quality code for my next mission
critical web application.
------------------------------
Date: 18 Mar 2004 04:00:57 -0800
From: bunny1112@yahoo.com (Bunny)
Subject: Re: perl2exe can't locate DBI.pm
Message-Id: <d4a4789a.0403180400.74da7c8d@posting.google.com>
Thanks Todd,
I know I am using an old version of Linux & Perl.. But now I want to
create
binary executables for the perl files present on this old linux......
So I have loaded an old version of perl2exe compatable with that
version of
Linux. I tried creating the binary executable for the perl files
after loading
it on the Linux system...
The binary executables created without the use of DBI are working
fine. But in the perl files having "use DBI;" the binary executables
are not creating and in
the logs for these I find
Can't locate DBI.pm in @INC (@INC contains: PERLTOEXE_STORAGE /tmp
lib\site
~../cgi-bin/lib/5.00503/i-686/linux
~../cgi-bin/lib/site_perl/5.005/i686-linux
~../cgi-bin/lib/site_perl/5.005 .) at newsample.pl line 4.
BEGIN failed--compilation aborted at newsample.pl line 4.
It would be more helpful if you can explain how I can make the DBI.pm
available for perl2exe in order for it to create the binary
executables.
thanks in advance
Bunny
Todd de Gruyl <todd@tdegruyl.com> wrote in message news:<elvni1-1k8.ln1@espresso.tdegruyl.com>...
> Bunny wrote:
> > I have perl5.00503 loaded on my Linux and I have downloaded and loaded
> > perl2exe V1.09U on Linux 6.1
>
> <nitpicking>
>
> I can't answer the question, but I am a little bit confused about what
> you are running:
>
> According to <http://kernel.org/> the latest stable version of linux is
> 2.6.4, so either you're running some fifteen years or so in the future,
> or you're looking at the wrong number (perhaps your distribution release
> number? IIRC Red Hat had a popular 6.1 release from about the same time
> as the perl you're running)
>
> Also, you might want to upgrade your perl, perl5.005_03.tar.gz is from
> 29-Mar-1999, we're up to 5.8.3 (stable), or 5.9.0 (dev)
>
> </nitpicking>
------------------------------
Date: 18 Mar 2004 01:10:36 -0800
From: pit.grinja@gmx.de (Piet)
Subject: Problem solved!
Message-Id: <39cbe663.0403180110.2aa152fb@posting.google.com>
Just in case someone else has similar problems...
Apparently the grid must not be drawn on the WxPanel, but directly on
or better inside the wxFrame. Additionally, when the panel and the
grid are both drawn inside the frame, I get nothing...no panel, no
grid, just the frame. Maybe a sizer problem. At least the first steps
are made.
Best wishes
Peter
------------------------------
Date: 18 Mar 2004 09:38:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Problem solved!
Message-Id: <c3bqn1$se1$1@mamenchi.zrz.TU-Berlin.DE>
Piet <pit.grinja@gmx.de> wrote in comp.lang.perl.misc:
> Just in case someone else has similar problems...
Similar to what?
I you're continuing a discussion, post a followup to the thread.
If you have lost the thread, but really think you need to add something,
you must explain the context again. No-one is going to remember your
problem just by the name "Piet".
[snip]
Anno
------------------------------
Date: 18 Mar 2004 00:50:15 -0800
From: ante.cepic@siemens.com (Toni)
Subject: Reseting numbered variables
Message-Id: <8b22fe57.0403180050.3cbb584a@posting.google.com>
Hello!
I have next example:
foreach $feature (sort keys %features_perc){
$result =~ /Users of $feature: Total of (\d+) licenses issued/;
$total_lic = $1;
print "\$total_lic = $total_lic\n";
}
Problem:
In a variable "$total_lic" I get value from the string "$result" if
there exists a pattern match.
But, if I get value in one iteration, and in the next there is no
match, I still have in a variable
"$total_lic" last value found in the previous iteration.
How do I reset $1 in every iteration?
Thanks!
------------------------------
Date: 18 Mar 2004 09:16:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Reseting numbered variables
Message-Id: <c3bpe5$rl9$1@mamenchi.zrz.TU-Berlin.DE>
Toni <ante.cepic@siemens.com> wrote in comp.lang.perl.misc:
> Hello!
> I have next example:
> foreach $feature (sort keys %features_perc){
> $result =~ /Users of $feature: Total of (\d+) licenses issued/;
Uh oh. $result must be a pretty long string. This doesn't look very
efficient, but if it's fast enough, there's nothing wrong with it.
> $total_lic = $1;
>
> print "\$total_lic = $total_lic\n";
> }
>
> Problem:
> In a variable "$total_lic" I get value from the string "$result" if
> there exists a pattern match.
> But, if I get value in one iteration, and in the next there is no
> match, I still have in a variable
Sure. You need to check if you have a match before using $1 etc.
foreach $feature ( (sort keys %features_perc) {
my $total_lic = 0;
if ( $result =~ /Users of $feature: Total of (\d+) licenses issued/ ) {
$total_lic = $1;
}
# etc
Anno
------------------------------
Date: Thu, 18 Mar 2004 09:09:18 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Reseting numbered variables
Message-Id: <c3botn$5hb$1@news.simnet.is>
"Toni" <ante.cepic@siemens.com> wrote in message
news:8b22fe57.0403180050.3cbb584a@posting.google.com...
> Hello!
> I have next example:
> foreach $feature (sort keys %features_perc){
> $result =~ /Users of $feature: Total of (\d+) licenses issued/;
> $total_lic = $1;
>
> print "\$total_lic = $total_lic\n";
> }
>
> Problem:
> In a variable "$total_lic" I get value from the string "$result" if
> there exists a pattern match.
> But, if I get value in one iteration, and in the next there is no
> match, I still have in a variable
> "$total_lic" last value found in the previous iteration.
> How do I reset $1 in every iteration?
you are fixated on $1
think about $1 as part of the //, that should not be used
unless the // succeeds.
so you code should contain:
if ($result =~ /Users of $feature: Total of (\d+) licenses issued/) {
$total_lic = $1;
}
now you should not ask "How do I reset $1 ?"
but "How do I reset $total_lic ?"
one way would be an 'else {} '
gnari
------------------------------
Date: 18 Mar 2004 10:29:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Reseting numbered variables
Message-Id: <c3btmq$15m$2@mamenchi.zrz.TU-Berlin.DE>
gnari <gnari@simnet.is> wrote in comp.lang.perl.misc:
> one way would be an 'else {} '
How would that change anything, ever?
Anno
------------------------------
Date: 18 Mar 2004 01:45:11 -0800
From: blacraven@hotmail.com (S Raven)
Subject: reverse search modifier
Message-Id: <6826327b.0403180145.60c00734@posting.google.com>
Hi all,
Is there is any reverse search modifier that can be used in regexes?
Something like, $text =~ s/me/mine/r;
I have not seen anything like that before, so was wondering whether
there was one. Can anyone please clarify.
Thanks,
Raven
------------------------------
Date: 18 Mar 2004 10:27:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: reverse search modifier
Message-Id: <c3btim$15m$1@mamenchi.zrz.TU-Berlin.DE>
S Raven <blacraven@hotmail.com> wrote in comp.lang.perl.misc:
> Hi all,
> Is there is any reverse search modifier that can be used in regexes?
What is a reverse search modifier?
> Something like, $text =~ s/me/mine/r;
Giving the thing a name doesn't make clearer what it does.
> I have not seen anything like that before, so was wondering whether
> there was one. Can anyone please clarify.
Not before you do.
If you mean a right-to-left search, no, there isn't. You can
match the last occurrence of "me" and replace it:
s/(.*)me/$1mine/;
or you can reverse everything before and after matching:
$text = reverse $text;
$text =~ s/em/enim/;
$text = reverse $text;
Anno
------------------------------
Date: 18 Mar 2004 04:55:26 -0800
From: stef_g@gmx.net (stef)
Subject: Searching on the internet with regex
Message-Id: <369e81eb.0403180455.218a8e1@posting.google.com>
Does anybody know an internet search engine that allows search-queries
with regular expressions as in perl?
Thanks in advance
Stef
------------------------------
Date: 18 Mar 2004 11:55:28 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: stripping out ASCII chars using regexp?
Message-Id: <c3c2ng$35f$2@mamenchi.zrz.TU-Berlin.DE>
Greg <djbitchpimp@snowboard.com> wrote in comp.lang.perl.misc:
> I am trying to get rid of the ASCII chars from the end of a string
> that I download from a webpage using LWP::Simple. The script downloads
> the HTML from a webpage and then uses HTML::TableExtract to extract
> the information from specific tables on the page.
>
> This basically gives me a string like this:
>
> ���,Temper Tantrum�,Take Care Comb Your
> Hair�,,,CD�,23.56��,�,0 Days
> Ago�,Scotla�
>
> which I then split into an array using:
>
> my @line = split (',', $line) ;
>
> I then do a comparison on $line [6]:
>
> if ($line [6] >= 75) {
>
> ... do something
>
> When I run this using -w, I get the following error:
>
> Argument "15.99M- M- " isn't numeric in numeric ge (>=) at
> ./parse_wants.pl line 49.
You seem to be confused about what's in your string. With your
data, $line[ 6] is "23.56��", not "15.99M- M- ".
> This is because somehow some extended ASCII chars got in the end of
> the string. If I do:
Somehow? So they shouldn't be there and you don't know how they get
there?
That's a reason to check the logic where these elements are produced.
Fixing this by deleting the unwanted characters is nothing but band aid.
The bug remains.
[snip attempts]
> Can anyone figure out a way to get rid of these trailing ASCII
> characters using a regular expression?
The only correct way is not to pick them up from wherever they
come from.
Anno
------------------------------
Date: Thu, 18 Mar 2004 11:35:01 -0000
From: "iain" <irhm@clara.net>
Subject: Re: truncated data after INSERT with undef in DBI - bug?
Message-Id: <40598965$0$8566$4c56ba96@master.news.zetnet.net>
Success! Brian pointed me in the right direction. trace shows no problem
with DBI. All your versions are lower than mine except for the SQL Server
ODBC driver (I had 2000.80.194.00 - from the original SQLsvr CD).
I've now installed SP3a on desktop, and got ODBC driver sqlsvr32.dll v
2000.081.9031.038. And my test program works OK. Your version still has a
higher number, but who cares?
There is a MS knowledge base article (814410) describing a memory leak
problem introduced with SQL Server SP3 & earlier ODBC drivers, fixed in
SP3a. I guess my problem is a similar cause.
thanks for your help,
Iain
"Brian McCauley" <nobull@mail.com> wrote in message
news:u9smg7i958.fsf@wcl-l.bham.ac.uk...
> "iain" <irhm@clara.net> writes:
>
> > With DBI and SQL Server ODBC driver I have prepared an INSERT statement
with
> > placeholders. But if the first execute has a undef (aka NULL), the
execute
> > for the following row is truncated to just the first character for the
same
> > field.
> >
> > Has anyone else found this, or got a workaround? Is it a problem with
DBI,
> > the DBD::ODBC driver or the SQL Server ODBC driver or SQL Server itself?
>
> I've run your test script here and not reproduced the problem with:
> perl5.8.0 (ActiveState 806).
> DBI 1.37
> DBD::ODBC 1.05
> SQL server ODBC driver 2000.81.9042.00
> odbc32.dll,odbccp32.dll 3.520.9042.0
> odbccr32.dll,odbccu32.dll 3.520.9030.0
> SQL server 8.00.534 (SP2)
>
> In addition to DBI tracing options mentioned by someone else you may
> also want to trace the SQL server using the SQL Profiler tool.
>
> I've experienced equally strnage problems on SQL servers lacking SP2.
>
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
------------------------------
Date: 18 Mar 2004 11:19:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Variable interpolation in regular expressions
Message-Id: <c3c0jv$35f$1@mamenchi.zrz.TU-Berlin.DE>
Dave <dave@nospam.com> wrote in comp.lang.perl.misc:
> I realize that this "gotcha" has been discussed here ad nauseum
> (verified by Google), but I don't understand why the Camel book says:
> "Since patterns are processed as double-quoted strings, the normal
> double-quoted interpolations will work." (Page 60 of Programming Perl,
> 2nd Ed.)
>
> Wouldn't it be more appropriate to say that they're subject to "double
> interpolation," for lack of better words? In a double quoted string, a
> scalar variable is substituted by its value; however, that value is not
> subject to interpolation itself. In a regular expression, the pattern
> is also substituted by its corresponding value, but the resulting value
> is *also* subject to interpolation.
>
> Example:
> my $string1 = 'A\n single\n quoted\n string\n';
> print "\$string1 prints \"A\\n single\\n quoted\\n string\\n\" as one
> would expect: $string1\n";
> $_ = $string1;
> print "This won't print\n" if m/$string1/;
> print "But this will\n" if m/\Q$string1/;
>
> So, how is it that "patterns are processed as double-quoted strings?"
> I'm not trying to split hairs; I just want to understand why my logic
> does not seem to agree with that statement, with the hope of avoiding
> needless traps further down the road.
I'm not sure what your confusion is. Patterns and double-quoting
behave the same way, just like the documentation says. Look at
this:
my $string1 = 'A\n single\n quoted\n string\n';
print qr/$string1/, "\n";
print qr/\Q$string1/, "\n";
print "\n";
print "$string1", "\n";
print "\Q$string1", "\n";
That prints
(?-xism:A\n single\n quoted\n string\n)
(?-xism:A\\n\ single\\n\ quoted\\n\ string\\n)
A\n single\n quoted\n string\n
A\\n\ single\\n\ quoted\\n\ string\\n
So, apart from the "(?-xism:" ... ")", the result is the same in both
cases. There is no double interpolation in patterns.
Anno
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6273
***************************************