[19641] in Perl-Users-Digest
Perl-Users Digest, Issue: 1836 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 28 11:05:34 2001
Date: Fri, 28 Sep 2001 08:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1001689510-v10-i1836@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 28 Sep 2001 Volume: 10 Number: 1836
Today's topics:
Re: AutoSplitting referenced subroutines nobull@mail.com
Can I use ')' as field separator? (David Djajaputra)
Re: Can I use ')' as field separator? <wyzelli@yahoo.com>
Re: Can I use ')' as field separator? <Thomas@Baetzler.de>
cgi-llib.pl and 'use strict' <nobody@nowhere.com>
Re: cgi-llib.pl and 'use strict' <Thomas@Baetzler.de>
Re: cgi-llib.pl and 'use strict' <bart.lateur@skynet.be>
Clearcase & perl <jan.buys@mie.alcatel.be>
Re: Clearcase & perl <mjcarman@home.com>
Re: Clearcase & perl <jan.buys@mie.nospam.alcatel.be>
counting occurence of character in string. <eramaqu@set132.gsm.ericsson.se>
Re: counting occurence of character in string. <Thomas@Baetzler.de>
Re: counting occurence of character in string. <eramaqu@set132.gsm.ericsson.se>
Re: counting occurence of character in string. <eramaqu@set132.gsm.ericsson.se>
Re: counting occurence of character in string. <Thomas@Baetzler.de>
Re: counting occurence of character in string. <eramaqu@set132.gsm.ericsson.se>
Re: counting occurence of character in string. <eramaqu@set132.gsm.ericsson.se>
Re: counting occurence of character in string. <Thomas@Baetzler.de>
Re: DBI/MySQL "$sth->fetch" help needed <fty@mediapulse.com>
Re: grap url <Thomas@Baetzler.de>
Re: grap url <Thomas@Baetzler.de>
Re: grap url <ilya@martynov.org>
Re: grap url <Thomas@Baetzler.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Sep 2001 13:04:18 +0100
From: nobull@mail.com
Subject: Re: AutoSplitting referenced subroutines
Message-Id: <u93d5734jh.fsf@wcl-l.bham.ac.uk>
brendonr@web.co.nz (Brendon Ryniker) writes:
> use AutoLoader;
> *AUTOLOAD = \&AutoLoader::AUTOLOAD;
>
> my %Dispatcher = (
> 11 => \&subroutine11,
> etc...
> );
> __END__
>
> # autoloaded routines
>
> sub subroutine11 {}
> etc...
> By introducing these code references in the *non* autoloaded section
> of the module, am I forcing the AutoSplit routines to be instantiated
> in memory regardless?
No, all you are doing is creating the symbol table entries pointing to
non-instanciated CODE blocks. (i.e. until soemthing tries to call
subroutine11 exists(&subroutine11) is true but defined(&subroutine11)
is false).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 28 Sep 2001 06:59:22 -0700
From: whatafish@hotmail.com (David Djajaputra)
Subject: Can I use ')' as field separator?
Message-Id: <1f57124c.0109280559.3fa6487d@posting.google.com>
I want to extract the 13 (or similar field) from this Fortran string:
1000 write(6,13) myvar
My approach is to first split it using the comma as the field
separator:
@tempfield = split(/,/);
to obtain: $tempfield[1] = "13) myvar"
and then split it again using ')' as the field separator. The problem
is that I can't seem to do this. Perl always complains about unmatched
parentheses etc. My current solution is to split using anything other
than numbers:
local $/ = undef;
@field = split(/[^0-9]/, $tempfield[1]);
But supposing I need to split using ")" as the field separator, can
this be done?
Sorry if this question is so stupid...
David
------------------------------
Date: Sat, 29 Sep 2001 00:02:43 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Can I use ')' as field separator?
Message-Id: <Ou%s7.7$BR4.1104@wa.nnrp.telstra.net>
"David Djajaputra" <whatafish@hotmail.com> wrote in message
news:1f57124c.0109280559.3fa6487d@posting.google.com...
> I want to extract the 13 (or similar field) from this Fortran string:
>
> 1000 write(6,13) myvar
>
> My approach is to first split it using the comma as the field
> separator:
>
> @tempfield = split(/,/);
>
> to obtain: $tempfield[1] = "13) myvar"
>
> and then split it again using ')' as the field separator. The problem
> is that I can't seem to do this. Perl always complains about unmatched
> parentheses etc. My current solution is to split using anything other
> than numbers:
You need to excape the paren in the regex if you want it to be a literal ).
I am guessing you are doing something like
split /)/, etc
You need to do
split /\)/, etc
Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: Fri, 28 Sep 2001 16:25:58 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Can I use ')' as field separator?
Message-Id: <fo19rtkhehceaag1aibavl33mhvrftkujl@4ax.com>
On Sat, 29 Sep 2001, "Wyzelli" <wyzelli@yahoo.com> wrote:
>"David Djajaputra" <whatafish@hotmail.com> wrote in message
>news:1f57124c.0109280559.3fa6487d@posting.google.com...
>> I want to extract the 13 (or similar field) from this Fortran string:
>>
>> 1000 write(6,13) myvar
Why use split at all?
#!/usr/bin/perl -w
use strict;
my $line = "1000 write(6,13) myvar";
if(my($start,$end)=($line=~m/write\(\s*(\d+)\s*,\s*(\d+)\s*\)/)){
print "start is $start, end is $end.\n";
}
__END__
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 28 Sep 2001 20:27:14 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: cgi-llib.pl and 'use strict'
Message-Id: <7eYs7.1007$812.1855@newsfeeds.bigpond.com>
I'm having a problem with 'use strict' and cgi-lib.pl version 2.18.
The following fragment works:
#!/usr/bin/perl -U
#use strict;
push (@INC, '.');
require 'lib.pl';
require 'price_table.pl';
require 'cgi-bin.pl';
ReadParse();
print $in{'test'};
However adding 'use strict' gives the error: Global symbol "%in" requires
explicit package name at ./stock.cgi line 10.
#!/usr/bin/perl -U
use strict;
push (@INC, '.');
require 'lib.pl';
require 'price_table.pl';
require 'cgi-bin.pl';
ReadParse();
print $in{'test'};
I've tried adding 'my %in' but no values are returned. I don't want to use
cgi.pm for performance reasons.
What is the right why to 'use strict' and cgi-bin.pl?
gtoomey
------------------------------
Date: Fri, 28 Sep 2001 13:00:38 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: cgi-llib.pl and 'use strict'
Message-Id: <sel8rtoda7fp5teup9c40icicep2odrgvp@4ax.com>
On Fri, 28 Sep 2001, "Gregory Toomey" <nobody@nowhere.com> wrote:
>I'm having a problem with 'use strict' and cgi-lib.pl version 2.18.
[...]
>However adding 'use strict' gives the error: Global symbol "%in" requires
>explicit package name at ./stock.cgi line 10.
[...]
>I've tried adding 'my %in' but no values are returned.
Try "our %in;" and put the declaration above your require statement.
>I don't want to use
>cgi.pm for performance reasons.
>What is the right why to 'use strict' and cgi-bin.pl?
If you can't use CGI.pm for performance reasons, it would probably be
better to switch to mod_perl (or CGI::Fast, although I haven't tried
that personally) altogether.
BTW, has anyone actually benchmarked CGI.pm vs. cgi-lib.pl?
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 28 Sep 2001 11:43:55 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: cgi-llib.pl and 'use strict'
Message-Id: <eho8rto3cdu4c1i56tnqmijuulttv65q35@4ax.com>
Thomas Bätzler wrote:
>>However adding 'use strict' gives the error: Global symbol "%in" requires
>>explicit package name at ./stock.cgi line 10.
>[...]
>>I've tried adding 'my %in' but no values are returned.
Of course not, 'my' limits the scope of %in to your script file, so
cgi-lib.pl can't reach it.
>Try "our %in;" and put the declaration above your require statement.
or:
use vars '%in';
if running 5.005 or earlier (or later, too...)
--
Bart.
------------------------------
Date: Fri, 28 Sep 2001 14:55:26 +0200
From: Jan Buys <jan.buys@mie.alcatel.be>
Subject: Clearcase & perl
Message-Id: <3BB4733E.5962B9D0@mie.nospam.alcatel.be>
This is a multi-part message in MIME format.
--------------65306066B8ED09B6DC252E5E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hello,
As clearcase admin, I'm attempting to create a script that should tell me the size of each dynamic view. But it fails and I don't understand why. Any CC & perl'er out there that might be able to
help me ?
$CT = "/usr/atria/bin/cleartool";
$viewsinfo = `$CT lsview`;
@views = split(/\n/, $viewsinfo);
$numviews = @views;
foreach $view(@views)
{
$view =~ /^*? +([\w\d_.\-]+) +([\w\d_.\-\/]+)/;
#$view looks like : " meursj_test2 /homes/meursj/views/meursj_test2.vws"
$viewtag = $1; $storagepath = $2; chomp($storagepath);
$viewsizestring = `du -ks $storagepath`;
#$viewsizestring looks like : "72 /homes/meursj/views/meursj_test2.vws"
print "$viewsizestring\n";
$viewsizestring =~ /^(\d+) /;
$viewsize = $1;
---->Here's where things go wrong. I'd expect to see a number as value of $viewsize. Instead I get again the previous value of $1 (being "meursj_test2"). Anyone an idea ?
print "$viewsize\n";
$viewhashtable{$viewtag} = $viewsize;
};
Thanks,
--------------65306066B8ED09B6DC252E5E
Content-Type: text/x-vcard; charset=us-ascii;
name="jan.buys.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Jan Buys
Content-Disposition: attachment;
filename="jan.buys.vcf"
begin:vcard
n:Buys;Jan
tel;fax:+32-15-29.36.37
tel;work:+32-15-29.36.03
x-mozilla-html:FALSE
org:Alcatel Microelectronics;Wireless Division
version:2.1
email;internet:jan.buys@mie.alcatel.be
title:Tools and Methodology Engineer
adr;quoted-printable:;;Generaal De Wittelaan 11A,=0D=0A2800 Mechelen;;;;
fn:Jan Buys
end:vcard
--------------65306066B8ED09B6DC252E5E--
------------------------------
Date: Fri, 28 Sep 2001 08:32:31 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Clearcase & perl
Message-Id: <3BB47BEF.C6B56B66@home.com>
Jan Buys wrote:
>
> As clearcase admin, I'm attempting to create a script that should
> tell me the size of each dynamic view. But it fails and I don't
> understand why.
>
> [...]
>
> foreach $view(@views)
> {
> $view =~ /^*? +([\w\d_.\-]+) +([\w\d_.\-\/]+)/;
>
> $viewtag = $1; $storagepath = $2; chomp($storagepath);
You're making life much too difficult. You don't need a fancy regex
here; split() will do nicely:
foreach (@views) {
chomp;
s/^\s+//; # strip leading whitespace
my ($viewtag, $storagepath) = split;
#...
}
> $viewsizestring =~ /^(\d+) /;
> $viewsize = $1;
>
> ---->Here's where things go wrong. I'd expect to see a number
> as value of $viewsize. Instead I get again the previous value
> of $1 (being "meursj_test2"). Anyone an idea ?
This is why you should always test your match for success before you use
$1, $2, etc. $1 contains the first captured value from the last
*successful* match. A failed match will not reset it. Apparently
$viewsizestring doesn't contain what you think it does, because your
match is failing.
if ($viewsizestring =~ /^(\d+) /) {
$viewsize = $1;
}
else {
warn "Couldn't extract size from '$viewsizestring'\n";
}
It looks like du is using a tab delimiter instead of a literal space.
-mjc
------------------------------
Date: Fri, 28 Sep 2001 15:55:24 +0200
From: Jan Buys <jan.buys@mie.nospam.alcatel.be>
Subject: Re: Clearcase & perl
Message-Id: <3BB4814C.129787A3@mie.nospam.alcatel.be>
This is a multi-part message in MIME format.
--------------535490652E3D6E126D28BF37
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
It was the tab thing. Thanks !
Michael Carman wrote:
> Jan Buys wrote:
> >
> > As clearcase admin, I'm attempting to create a script that should
> > tell me the size of each dynamic view. But it fails and I don't
> > understand why.
> >
> > [...]
> >
> > foreach $view(@views)
> > {
> > $view =~ /^*? +([\w\d_.\-]+) +([\w\d_.\-\/]+)/;
> >
> > $viewtag = $1; $storagepath = $2; chomp($storagepath);
>
> You're making life much too difficult. You don't need a fancy regex
> here; split() will do nicely:
>
> foreach (@views) {
> chomp;
> s/^\s+//; # strip leading whitespace
> my ($viewtag, $storagepath) = split;
> #...
> }
>
> > $viewsizestring =~ /^(\d+) /;
> > $viewsize = $1;
> >
> > ---->Here's where things go wrong. I'd expect to see a number
> > as value of $viewsize. Instead I get again the previous value
> > of $1 (being "meursj_test2"). Anyone an idea ?
>
> This is why you should always test your match for success before you use
> $1, $2, etc. $1 contains the first captured value from the last
> *successful* match. A failed match will not reset it. Apparently
> $viewsizestring doesn't contain what you think it does, because your
> match is failing.
>
> if ($viewsizestring =~ /^(\d+) /) {
> $viewsize = $1;
> }
> else {
> warn "Couldn't extract size from '$viewsizestring'\n";
> }
>
> It looks like du is using a tab delimiter instead of a literal space.
>
> -mjc
--------------535490652E3D6E126D28BF37
Content-Type: text/x-vcard; charset=us-ascii;
name="jan.buys.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Jan Buys
Content-Disposition: attachment;
filename="jan.buys.vcf"
begin:vcard
n:Buys;Jan
tel;fax:+32-15-29.36.37
tel;work:+32-15-29.36.03
x-mozilla-html:FALSE
org:Alcatel Microelectronics;Wireless Division
version:2.1
email;internet:jan.buys@mie.alcatel.be
title:Tools and Methodology Engineer
adr;quoted-printable:;;Generaal De Wittelaan 11A,=0D=0A2800 Mechelen;;;;
fn:Jan Buys
end:vcard
--------------535490652E3D6E126D28BF37--
------------------------------
Date: Fri, 28 Sep 2001 12:28:33 +0200
From: Martin Quensel <eramaqu@set132.gsm.ericsson.se>
Subject: counting occurence of character in string.
Message-Id: <3BB450D1.8385443D@set132.gsm.ericsson.se>
Hello!
I am reading nntp messages from an internal news server with company
specific newsgroups, and posting these messages on an internal webserver
at our company.
I am placing the body of the message within <pre> tags. The only thing i
do to the message is converting some characters to HTML entities.
I wanted to use diffrent font colours to mark quotes from previous
messages. So i took the approach of searching for lines starting with
">" and placing font tags.
Now the problem is that i want diffrent colours depending on the numbers
of ">" in the beginning of lines.
So i wrote the following peice of code.
foreach (@bodytext)
{
# getting the number of ">" chars at
# beginning of file.
my $colorindex = 0;
my @color = ("660066","007777","990000","BB6600");
# start by making a copy of line.
my $txtline = $_;
# now go through and count all the ">"
while ($txtline =~ /\>/g) {$colorindex++;}
# there could be tags here, so take away "<" from the count
while ($txtline =~ /\</g) { $colorindex--; }
if ($colorindex > 0)
{
my $colortxt = @color[$colorindex -1];
print "<font color=\"#$colortxt\">";
print prefilter($_);
print "</font>";
}
else
{
print prefilter($_);
}
}
What i am doing is counting the occurance of ">" in the line. But
sometimes lines can include tags.. Specially in the internal newsgroup
that discusses SGML DTDs, so i also count the number of "<" to try an
catch matched pairs. I then print out a font tag in the beginning of the
line if there are any ">" in the string.
The prefilter function is only a function that replaces some chars with
their HTML entities.
My question is: am i doint this the right way?
I am not good at regexps so what i would like is a regexp that counts
the ">" in the beginning of the line, unless there are other characters
between the ">". Like ">> >" but not ">> bla bla > bla bla".
Am i doing this the totally wrong way?
What kind of problems do you see with my approach? Should i try a
completly diffrent approach?
Thank you very much for looking at this!
Best Regards
Martin Quensel
------------------------------
Date: Fri, 28 Sep 2001 13:23:10 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: counting occurence of character in string.
Message-Id: <55n8rtg9f1qcmqltf5opokclit0ll1h46t@4ax.com>
On Fri, 28 Sep, Martin Quensel <eramaqu@set132.gsm.ericsson.se> wrote:
>I am reading nntp messages from an internal news server with company
>specific newsgroups, and posting these messages on an internal webserver
>at our company.
[...]
>I wanted to use diffrent font colours to mark quotes from previous
>messages. So i took the approach of searching for lines starting with
>">" and placing font tags.
This doesn't always work as expected: Line wrapping can cause quotes
to break and you'll have a hard time catching this. People also use
all kinds of symbols to indicate quotes. Nevertheless:
>What i am doing is counting the occurance of ">" in the line. But
>sometimes lines can include tags.. Specially in the internal newsgroup
>that discusses SGML DTDs, so i also count the number of "<" to try an
Don't do that. How about a quoted unix command like "echo > test".
Below is a small rework of your sub that deduces indentation depth by
grabbing all > and whitespace chars at the beginning of a line. The
first > char has to be at the beginnning of a line. I then count the
number of > chars in the match.
#!/usr/bin/perl -w
use strict;
# dunno what this is supposed to do
sub prefilter { return @_ };
# get my sample data
my @bodytext = <DATA>;
# inside the foreach this would've created this
# array in each loop iteration.
my @color = ("660066","007777","990000","BB6600");
foreach (@bodytext){
# grab all > / blank combos at the start of a line
if( m/^(>[\s>]*)/ ){
# squeeze all blanks from the string
( my $marks = $1 ) =~ tr/ //;
# use length of $marks string as offset into the
# color array.
print "<font color=\"\#$color[length($marks)-1]\">";
print prefilter($_);
print "</font>";
} else {
# no match, no color.
print prefilter($_);
}
}
__DATA__
In sdfsdf, sdfsd wrote:
> In sdfsdf, sdfsd wrote:
> > bla. bla bla. bla bla bla.
bla bli blu:
# echo bla > blu
> bli bla blubb.
blip.
--
bli@bla.blu
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 28 Sep 2001 14:29:34 +0200
From: Martin Quensel <eramaqu@set132.gsm.ericsson.se>
Subject: Re: counting occurence of character in string.
Message-Id: <3BB46D2E.ABC3BFB0@set132.gsm.ericsson.se>
Thomas Bätzler wrote:
>
> On Fri, 28 Sep, Martin Quensel <eramaqu@set132.gsm.ericsson.se> wrote:
> >I am reading nntp messages from an internal news server with company
> >specific newsgroups, and posting these messages on an internal webserver
> >at our company.
> [...]
> >I wanted to use diffrent font colours to mark quotes from previous
> >messages. So i took the approach of searching for lines starting with
> >">" and placing font tags.
>
> This doesn't always work as expected: Line wrapping can cause quotes
> to break and you'll have a hard time catching this. People also use
> all kinds of symbols to indicate quotes. Nevertheless:
I know. I am building this webnntp client thing because a lot of people
at our company does not even know that news exist (except the unix
designers), and i want to increase traffic to our internal newsgroups.
Since a lot of people will access the news by the webinterface i hope to
be able to solve most of these problems.
> >What i am doing is counting the occurance of ">" in the line. But
> >sometimes lines can include tags.. Specially in the internal newsgroup
> >that discusses SGML DTDs, so i also count the number of "<" to try an
>
> Don't do that. How about a quoted unix command like "echo > test".
Exactly what i was afraid could happen, but did not know how to solve,
thank you!
> Below is a small rework of your sub that deduces indentation depth by
> grabbing all > and whitespace chars at the beginning of a line. The
> first > char has to be at the beginnning of a line. I then count the
> number of > chars in the match.
Excellent!
Thank you also for finding my obvious stupidity of recreating the array
for every line.
Once again Thank you!
And thanx to all who have taken the time to read my post and using
brainresources to try an help me.
Best Regards
Martin Quensel
------------------------------
Date: Fri, 28 Sep 2001 14:47:10 +0200
From: Martin Quensel <eramaqu@set132.gsm.ericsson.se>
Subject: Re: counting occurence of character in string.
Message-Id: <3BB4714E.E4ADE0DB@set132.gsm.ericsson.se>
Thomas Bätzler wrote:
>
[snip]
> Below is a small rework of your sub that deduces indentation depth by
> grabbing all > and whitespace chars at the beginning of a line. The
> first > char has to be at the beginnning of a line. I then count the
> number of > chars in the match.
>
[snip]
But it seems that this regexp also counts the amount of whitespace..
Forexample
> bla bla
>bla bla
> Bla bla bla
Will generate diffrent colours for every line..
How do i fix this so that it only takes the ">" into account ?
Best Regards
Martin Quensel
------------------------------
Date: Fri, 28 Sep 2001 15:27:32 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: counting occurence of character in string.
Message-Id: <hgu8rtogt7ukpb0er81kjril71edc3jvdp@4ax.com>
On Fri, 28 Sep 2001 14:47:10 +0200, Martin Quensel
<eramaqu@set132.gsm.ericsson.se> wrote:
>But it seems that this regexp also counts the amount of whitespace..
The regexp is fine. The problem is the assignment afterwards. Replace
"tr/ //" with "s/ //g" and you're fine.
I could of course claim that I put this in intentionally to test your
attention, but who would ever believe me? :-)
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 28 Sep 2001 15:38:13 +0200
From: Martin Quensel <eramaqu@set132.gsm.ericsson.se>
Subject: Re: counting occurence of character in string.
Message-Id: <3BB47D45.270336FC@set132.gsm.ericsson.se>
Thomas Bätzler wrote:
> The regexp is fine. The problem is the assignment afterwards. Replace
> "tr/ //" with "s/ //g" and you're fine.
>
> I could of course claim that I put this in intentionally to test your
> attention, but who would ever believe me? :-)
:-)
Well now it is starting to work.
Only some small things left, but i can fix them myself. Things like a
single ">" on a single line will get the second colour in the array.
> bla bla "color one in array
> " will trigger colour 2 in array"
>>bla bla
Thanx for all your help.
Very nice homepage you got by the way.
I am an old c64 and amiga fan.
Best Regards
Martin Quensel
------------------------------
Date: Fri, 28 Sep 2001 15:47:13 +0200
From: Martin Quensel <eramaqu@set132.gsm.ericsson.se>
Subject: Re: counting occurence of character in string.
Message-Id: <3BB47F61.8B0572D0@set132.gsm.ericsson.se>
Martin Quensel wrote:
>
> Thomas Bätzler wrote:
>
> > The regexp is fine. The problem is the assignment afterwards. Replace
> > "tr/ //" with "s/ //g" and you're fine.
I changed the "s/ //g" to "s/\s//g"
and now it seems to work fine.
:-)
But as you said before catching every kind of exception, and way people
mark their posts is impossible.
Martin Quensel
------------------------------
Date: Fri, 28 Sep 2001 15:54:55 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: counting occurence of character in string.
Message-Id: <div8rt0h37un3iaasqim08eobi7i0bg59d@4ax.com>
On Fri, 28 Sep 2001 15:38:13 +0200, Martin Quensel
<eramaqu@set132.gsm.ericsson.se> wrote:
>Well now it is starting to work.
>Only some small things left, but i can fix them myself. Things like a
>single ">" on a single line will get the second colour in the array.
*slaps head* Of course. If you have a line like '>\n' then the \n will
be in the match, too, because it is also a whitespace character.
So I really should have used "s/\s//g" to strip spaces, \t and \n.
But anyways, since I really wanted to use tr///, here's a diff:
[...]
if( my($marks) = ( m/^(>[\s>]*)/ ) ){
# use count of > characters in $marks string as offset into the
# color array.
print "<font color=\"\#$color[$marks =~ tr/>/>/ -1]\">";
[...]
The change in the if assigns the $1 value from the match result to
$marks.
$marks =~ tr/>/>/ evaluates to the number of > characters in marks -
so there is no need to check the length of the string anymore.
>Very nice homepage you got by the way.
>I am an old c64 and amiga fan.
Thanks you!
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 28 Sep 2001 15:01:47 GMT
From: "Jay Flaherty" <fty@mediapulse.com>
Subject: Re: DBI/MySQL "$sth->fetch" help needed
Message-Id: <vh0t7.706957$ai2.54779497@bin2.nnrp.aus1.giganews.com>
"martinblack" <martinblack26@yahoo.com> wrote in message
news:c025943b.0109271235.5c1c5537@posting.google.com...
> Hi, I am having trouble with a DBI script. I can't seem to access the
> rows returned from the SQL command. I have tried numerous methods to
> grab the rows, but no such luck. I am not getting any error messages
> from this script, and I am at my wits end. Any help would be very much
> appreciated. Thanks in advance.
> Cheers.
> Martinblack.
>
> Below is a copy of the script:
> $SQL = "select company_id, product_id, title,
> description, spex, price, sex
> from product
> where product_id='$product_id' and
> company_id='$company_id';";
------------------------------^ semicolon is only needed when running the
query from the mysql client.
> $SQL = "select company_id, product_id, title,
> description, spex, price, sex
> from product
> where title='$title';";
-------------------^
> sub DBstart() {
> $DBname= "dbi:mysql:blabla";
> $DBhost = "localhost";
> $DBusername = "myuname";
> $DBpassword = "mypswrd";
>
> $dbh = DBI->connect("$DBname:$DBhost", $DBusername, $DBpassword) ||
> die "connection problem: ", $dbh->errstr;
if the connect fails then $dbh is not defined. Therefore $dbh->errstr is
meaningless. Use $DBI::errstr instead
> $dbh->{'RaiseError'} = 1;
should also add:
$dbh->{'PrintError'} = 1;
You can also add these to the connect method as an anonymous hash:
$dbh = DBI->connect("$DBname:$DBhost", $DBusername, $DBpassword,
{RasieError=>1,PrintError=>1}) or
die "connection problem: $DBI::errstr\n";
------------------------------
Date: Fri, 28 Sep 2001 12:09:13 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: grap url
Message-Id: <4ji8rtg73c86gusk3n9mglk01cv3c0nor1@4ax.com>
On Fri, 28 Sep 2001, "felix" <mr.thanquol@gmx.de> wrote:
[...]
>> my $new_uri = URI->new_abs($response->header('Location'), $uri);
> ^^^^^^^^^^^^^^^line 12 of my script
[...]
>why do I get a "missing base argument at test.pl line 12"
>sorry for that question, but I don't know the URI.pm and the perldoc doesn't
>help me at all...
Looks like Ilya is using a different version of URI.pm.
Try "perl -MURI -e'print URI->VERSION'" to see what you have.
Anyways, it looks like new_abs() is an undocumented method - at least
I can't find it in my local URI.pm manpage, even though the function
is defined in there and Ilya's code works.
As a work-around, you could try:
my $new_uri = URI->new(
$response->header('Location'),
$uri
)->abs($uri);
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Fri, 28 Sep 2001 12:13:48 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: grap url
Message-Id: <h4j8rt4ilnjr2afutp7i1rjr71bloe24mv@4ax.com>
On 28 Sep 2001, Ilya Martynov <ilya@martynov.org> wrote:
>TB> Yeah, you'll have to do it my way, then :-) TIMTOWTDI sure is cool.
>Yep. It should also work. However in theory in some cases it is not
>feasible to do second request.
If that's the case, you can always derive a subclass from
LWP::UserAgent and overload the redirect_ok() method.
Anyways, the OP asked for the destination he's been redirected to, so
that implies that he wants to be redirected.
Cheers,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: 28 Sep 2001 18:25:14 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: grap url
Message-Id: <87r8srjstx.fsf@abra.ru>
>>>>> On Fri, 28 Sep 2001 12:09:13 +0200, Thomas Bätzler <Thomas@Baetzler.de> said:
>> why do I get a "missing base argument at test.pl line 12"
>> sorry for that question, but I don't know the URI.pm and the perldoc doesn't
>> help me at all...
TB> Looks like Ilya is using a different version of URI.pm.
No. I see exactly same message if $response->header('Location')
returns undef.
TB> Try "perl -MURI -e'print URI->VERSION'" to see what you have.
TB> Anyways, it looks like new_abs() is an undocumented method - at least
TB> I can't find it in my local URI.pm manpage, even though the function
TB> is defined in there and Ilya's code works.
I have 1.10 (and mine manpage documents it). According ChangeLog it
was introduced in 1.00.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Fri, 28 Sep 2001 16:33:24 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: grap url
Message-Id: <9529rt8u4dt4r31sl8f8vmk3u8mqfdfu9m@4ax.com>
On 28 Sep 2001, Ilya Martynov <ilya@martynov.org> wrote:
[URI->new_abs() and URI.pm version]
>I have 1.10 (and mine manpage documents it). According ChangeLog it
>was introduced in 1.00.
OK, I'm retracting everything and now claim the opposite :-) I was
only scanning the Synopsis section of the manpage and assumed that it
would list all methods, when in fact new_abs() was mentioned in the
Description.
Cheers,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 1836
***************************************