[25144] in Perl-Users-Digest
Perl-Users Digest, Issue: 7393 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 11 14:10:40 2004
Date: Thu, 11 Nov 2004 11:10:10 -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, 11 Nov 2004 Volume: 10 Number: 7393
Today's topics:
Re: perldoc problem on linux (Anno Siegel)
Re: perldoc problem on linux <jwillmore@fastmail.us>
Re: perldoc problem on linux (Anno Siegel)
Re: regexp s// too greedy (Anno Siegel)
Re: regexp s// too greedy <bigj@kamelfreund.de>
Re: Tail a File using POE and Tk <notvalid@email.com>
Two operations with one last if? <ramsaram@jpl-devvax.jpl.nasa.gov>
URI canonicalization (was: how greedy is nongreedy in r <nobull@mail.com>
what to do with special characters like "é","ë",... <lievemario@hotmail.com>
Re: what to do with special characters like "é","ë",... <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Nov 2004 12:44:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perldoc problem on linux
Message-Id: <cmvmrb$54g$2@mamenchi.zrz.TU-Berlin.DE>
James Willmore <jwillmore@fastmail.us> wrote in comp.lang.perl.misc:
> On Wed, 10 Nov 2004 13:30:34 -0800, Zhiliang Hu wrote:
>
> <snip>
> > Yes, I did - 'perldoc' is in /usr/local/bin/ and it is in both my and
> > ~root's path. (I double checked them and I still got the same as
> > before).
> >
> > Following commands work fine:
> > > perloc -V
> > > perldoc -h
> > > perldoc NONEexist (this returns "No documentation found")
> > > perldoc -l WWW::Search
> >
> > but "perldoc WWW::Search" will show nothing but login prompts.
>
> As a "quick fix", you could (since you're on a *nix box) try:
> perldoc -t WWW::Search | less
>
> If this works, then you can at least use perldoc until you hunt down the
> cause of the problem.
What makes you think "perldoc -t" would work? My guess is it's a
permission problem that doesn't exist for root.
Anno
------------------------------
Date: Thu, 11 Nov 2004 10:38:49 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: perldoc problem on linux
Message-Id: <pan.2004.11.11.15.38.48.747783@fastmail.us>
On Thu, 11 Nov 2004 12:44:27 +0000, Anno Siegel wrote:
> James Willmore <jwillmore@fastmail.us> wrote in comp.lang.perl.misc:
>> On Wed, 10 Nov 2004 13:30:34 -0800, Zhiliang Hu wrote:
>>
>> <snip>
>> > Yes, I did - 'perldoc' is in /usr/local/bin/ and it is in both my and
>> > ~root's path. (I double checked them and I still got the same as
>> > before).
>> >
>> > Following commands work fine:
>> > > perloc -V
>> > > perldoc -h
>> > > perldoc NONEexist (this returns "No documentation found")
>> > > perldoc -l WWW::Search
>> >
>> > but "perldoc WWW::Search" will show nothing but login prompts.
>>
>> As a "quick fix", you could (since you're on a *nix box) try:
>> perldoc -t WWW::Search | less
>>
>> If this works, then you can at least use perldoc until you hunt down the
>> cause of the problem.
>
> What makes you think "perldoc -t" would work? My guess is it's a
> permission problem that doesn't exist for root.
I took it the poster at his word that the only thing he couldn't do was
view the documentation. I was under the impression that if you try to run
perldoc as root, then it would always issue an error message about it
being unsafe to run as root - regardless of what option. The error
mentioned in the OP was he tried to run perldoc to view documentation and
got nothing.
I agree that it might be a permission problem ... OTOH, if it's working
for an unprivileged user, it might be the pager setting for root. Trying
to run perldoc with the -t option might (dis)prove this. Besides, as I
mentioned, this was a temporary fix ... what does it hurt to try it and
find it doesn't work. :-)
Jim
------------------------------
Date: 11 Nov 2004 17:05:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perldoc problem on linux
Message-Id: <cn065m$f3q$1@mamenchi.zrz.TU-Berlin.DE>
James Willmore <jwillmore@fastmail.us> wrote in comp.lang.perl.misc:
> On Thu, 11 Nov 2004 12:44:27 +0000, Anno Siegel wrote:
>
> > James Willmore <jwillmore@fastmail.us> wrote in comp.lang.perl.misc:
> >> On Wed, 10 Nov 2004 13:30:34 -0800, Zhiliang Hu wrote:
> >>
> >> <snip>
> >> > Yes, I did - 'perldoc' is in /usr/local/bin/ and it is in both my and
> >> > ~root's path. (I double checked them and I still got the same as
> >> > before).
> >> >
> >> > Following commands work fine:
> >> > > perloc -V
> >> > > perldoc -h
> >> > > perldoc NONEexist (this returns "No documentation found")
> >> > > perldoc -l WWW::Search
> >> >
> >> > but "perldoc WWW::Search" will show nothing but login prompts.
> >>
> >> As a "quick fix", you could (since you're on a *nix box) try:
> >> perldoc -t WWW::Search | less
> >>
> >> If this works, then you can at least use perldoc until you hunt down the
> >> cause of the problem.
> >
> > What makes you think "perldoc -t" would work? My guess is it's a
> > permission problem that doesn't exist for root.
>
> I took it the poster at his word that the only thing he couldn't do was
> view the documentation. I was under the impression that if you try to run
> perldoc as root, then it would always issue an error message about it
> being unsafe to run as root - regardless of what option. The error
> mentioned in the OP was he tried to run perldoc to view documentation and
> got nothing.
I see. However, OP said it works for him(?) as root, but not as an
ordinary user. In such a case, I tend to check permissions first.
Otherwise I believe perldoc is root-safe now and the warning is gone.
(Yup, v3.13 is fine with root)
In any case, someone (Sean Burke, to give credit where credit is due)
has done a tremendous job of cleaning up the code. Perldoc used to be
a horror of a script -- I remember I tried to fix something minor once,
but had to give up because I couldn't make sure in reasonable time
that the fix wouldn't break something else. When I looked at it last
night I found a well-organized program, neatly divided up in modules.
It would be a joy to fix if I knew of anything that needed fixing.
> I agree that it might be a permission problem ... OTOH, if it's working
> for an unprivileged user, it might be the pager setting for root. Trying
> to run perldoc with the -t option might (dis)prove this. Besides, as I
> mentioned, this was a temporary fix ... what does it hurt to try it and
> find it doesn't work. :-)
There's certainly nothing wrong with trying it, I was just curious
what gave you the idea, given the symptoms.
Anno
------------------------------
Date: 11 Nov 2004 11:08:23 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regexp s// too greedy
Message-Id: <cmvh77$lk$1@mamenchi.zrz.TU-Berlin.DE>
bettyann <bettyann@campbell.com> wrote in comp.lang.perl.misc:
> hi all,
>
> can anyone help me limit the greediness of my substitution pattern? i
> have a CSV file and i want to insert a new column of values after the
> 6th column. but the new data to be inserted is dependent upon the
> value of the 6th column.
>
> example original data:
> 2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1
> 1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1
> 5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1
> 8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1
>
> i want to put "0" after the 6th column if the 6th column contains
> "hold.bmp".
> i want to put "-1" after the 6th column if the 6th column contains
> "NaN".
>
> i thought i could do this with two substitutions commands:
>
> s/^((.*?,){5}?(hold.bmp))/$1,0/
> s/^((.*?,){5}?(NaN))/$1,-1/
>
> i cannot limit the matching of "hold.bmp" or "NaN". i want this
> pattern to match *only* if "hold.bmp" or "NaN" immediately follows the
> 5th column.
[code appreciated, but snipped]
I'd use split and splice for that, not a regex (except that split also
uses a regex). Then you can comfortably look at the preceding field
and decide what goes after it. For instance:
while ( <DATA> ) {
my @l = split /,/;
splice @l, 6, 0, $l[ 5] eq 'hold.bmp' ? 0 : -1;
print join ',', @l;
}
Anno
------------------------------
Date: Thu, 11 Nov 2004 14:59:17 +0100
From: Janek Schleicher <bigj@kamelfreund.de>
Subject: Re: regexp s// too greedy
Message-Id: <pan.2004.11.11.13.59.15.710521@kamelfreund.de>
On Wed, 10 Nov 2004 19:38:35 -0800, bettyann wrote:
> can anyone help me limit the greediness of my substitution pattern? i
> have a CSV file and i want to insert a new column of values after the
> 6th column. but the new data to be inserted is dependent upon the
> value of the 6th column.
Well, when talking about handling CSV files, why not using one of the
numerous modules on CPAN (http://search.cpan.org?query=CSV)
E.g. with Text::CSV_XS the following snippet works without to be worried
about parsing csv:
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV_XS;
my $csv = Text::CSV_XS->new();
while (<DATA>) {
chomp;
$csv->parse($_) or die "Couldn't parse '$_' as CSV";
my @col = $csv->fields;
$csv->combine(@col[0..5],($col[5] eq 'hold.bmp' ? 0 : -1),@col[6..$#col]);
print $csv->string,"\n";
}
__DATA__
2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1
1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1
5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1
8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1
Greetings,
Janek
------------------------------
Date: Thu, 11 Nov 2004 17:38:14 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: Tail a File using POE and Tk
Message-Id: <asNkd.40721$QJ3.10418@newssvr21.news.prodigy.com>
Johnny Google wrote:
> In your code you use select on the filehandle - I am a little fuzzy on
> this but I thought that select will block the file.... I need an
> outside app to have the ability to write to the file being read... does
> select keep other apps from writing to the file while it is being read?
select() does not block. There is no way through one app to block
another app from modifying a file (AFAIK).
For faster, and more detailed, explanations of Perl's functions, it's
much easier to read the docs that come with Perl:
perldoc -f select
--Ala
------------------------------
Date: Thu, 11 Nov 2004 14:18:41 -0500
From: sam <ramsaram@jpl-devvax.jpl.nasa.gov>
Subject: Two operations with one last if?
Message-Id: <10p7be4g9o23l5b@news.supernews.com>
Is the following "legal" and "sensible?"
while(<LOGFILE>) {
undef($splinter);
@record = split;
$archivesection = $record[6];
($interestingpart, $junk) = split(/\?/,$archivesection,2);
$userid = $searchpattern{$interestingpart} && $splinter =
$_, last if (defined($searchpattern{$interestingpart}))
if (defined($splinter) &&
(&daily || &weekly || &monthly || &yearly)) {
&add_splinter_to_pile;
}
}
I want the userid from the associative array and the record that
belongs to that userid if I find the piece I'm looking for in that
record. Or is there another/better way to do this?
------------------------------
Date: Thu, 11 Nov 2004 18:32:53 +0000
From: Brian McCauley <nobull@mail.com>
Subject: URI canonicalization (was: how greedy is nongreedy in regexp ?)
Message-Id: <cn0avo$a2q$1@sun3.bham.ac.uk>
Stuart Moore wrote:
> Brian McCauley wrote:
>
>>
>> But since this is a question about canonicalising URLs it would seem
>> more appropriate to use the URI module. However the canonical()
>> method of URI doesn't do this. Is this right or should it be
>> considered a bug in URI?
>
>
> Is www.foo.com/a/b/../c/d always the same as www.foo.com/a/c/d ?
>
> I'd guess on most webservers it is, but surely you can't guarantee it in
> general.
I think you can garantee it on standards-conforming web servers. At
least that's the implication of of the W3C standards for URIs.
> Suppose the dots were instead input to a script?
Then at least one of them must be encoded.
So I think it's fairly clear from the standards that
http://foo/a/b/c/../../d/./e/f
Should canonicalize to
http://foo/a/d/e/f
It also follows that both of...
http://foo/a/b/%2E./c
http://foo/a/b/.%2e/c
..should canonicalise to the same thing and it shouldn't be..
http://foo/a/b/../c
..because that's a non-canonical form of..
http://foo/a/c
It is however unclear to me what the correct canonical form would be. I
think it should probably be
http://foo/a/b/%2E./c
------------------------------
Date: Thu, 11 Nov 2004 16:14:23 +0100
From: "lievemario" <lievemario@hotmail.com>
Subject: what to do with special characters like "é","ë",...
Message-Id: <cmvvhd$a6p$1@snic.vub.ac.be>
hey,
I've wrote a perl script which gets data out of a mysql database and convert
it to xml.
It works with the XML::Handler::YAWriter,
here is the code;
use strict;
use DBI;
use XML::Generator::DBI;
use XML::Handler::YAWriter;
my $dbh = DBI->connect ("DBI:mysql:myDB", "myUID", "myPassword",
{ RaiseError => 1, PrintError => 0});
my $out = XML::Handler::YAWriter->new (AsFile => "test.xml");
my $gen = XML::Generator::DBI->new ( Handler => $out, dbh => $dbh );
$gen->execute ("SELECT *
FROM someTable");
$dbh->disconnect ();
I do not get any errors when executing the script,
but when I try to open the test.xml file, it has an error
in it:
<name>th?/name>
this should be:
<name>thé</name>
Has anyone an idea how I can solve this?
thx!
------------------------------
Date: Thu, 11 Nov 2004 16:13:08 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: what to do with special characters like "é","ë",...
Message-Id: <ocMkd.30$fc.1@trnddc08>
lievemario wrote:
[...]
> I do not get any errors when executing the script,
> but when I try to open the test.xml file, it has an error
> in it:
> <name>th?/name>
> this should be:
> <name>thé</name>
>
> Has anyone an idea how I can solve this?
Just use the proper encoding/character set/code page (terminology varies),
either in your database or in the generated XML file or in the XML header or
in the settings for whatever program you are using to "open" the XML file.
Actually change those "or" to "and". Although you could convert the charset
from and to it is much easier to stick to the same throughout.
jue
------------------------------
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 7393
***************************************