[23107] in Perl-Users-Digest
Perl-Users Digest, Issue: 5328 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 7 09:05:42 2003
Date: Thu, 7 Aug 2003 06:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 7 Aug 2003 Volume: 10 Number: 5328
Today's topics:
Can't use "open my" with pipe (Eric)
Re: CGI.pm and foreach <REMOVEsdnCAPS@comcast.net>
Checking number of instances running <Rene.Scheibe@Stud.TU-Ilmenau.de>
Re: Checking number of instances running <pete@localho.st>
Re: Checking number of instances running <NOSPAM@bigpond.com>
Re: Checking number of instances running <Rene.Scheibe@Stud.TU-Ilmenau.de>
Re: Convert UTF-8 to unicode? <flavell@mail.cern.ch>
Re: CPAN update <jwillmore@cyberia.com>
Re: Get my PID <jurgenex@hotmail.com>
Getting hostnames from remote servers.... <mothra@mothra.com>
Re: Getting hostnames from remote servers.... <g4rry_sh0rt@zw4llet.com>
Re: hash key of %ENV is case insensitive (Win32) <jwillmore@cyberia.com>
Re: hash key of %ENV is case insensitive (Win32) <jurgenex@hotmail.com>
I need GD for Redhat 9 <jrendant@comcast.net>
Re: I need GD for Redhat 9 <spam@thecouch.homeip.net>
Re: I need GD for Redhat 9 <NOSPAM@bigpond.com>
logging <perseus_medusa@hotmail.com>
Re: logging <mothra@mothra.com>
Re: nested HTML parsing <matt@userve.net>
Re: nested HTML parsing <nobull@mail.com>
Re: perl DBI <jrendant@comcast.net>
Re: perl DBI <jwillmore@cyberia.com>
Re: Replace a word if its not in an html tag (ko)
Re: ssh and Perl <g4rry_sh0rt@zw4llet.com>
Re: ssh and Perl <mothra@mothra.com>
Re: ssh and Perl <g4rry_sh0rt@zw4llet.com>
Re: ssh and Perl <vladimir@NoSpamPLZ.net>
Re: What do you think of my first "JAPH"? (Heinrich Mislik)
Re: What do you think of my first "JAPH"? <REMOVEsdnCAPS@comcast.net>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 7 Aug 2003 05:57:24 -0700
From: jain@gmx.net (Eric)
Subject: Can't use "open my" with pipe
Message-Id: <835c2e5d.0308070457.76803137@posting.google.com>
This works:
open SOURCE 'gunzip -c test.rdf.gz|' or die $!;
my $source = \*SOURCE;
This doesn't ("No such file or directory"):
open my $source, '<', 'gunzip -c test.rdf.gz|' or die $!;
Can latter syntax be made to work, if modified?
(Rationale: Fits into one line...)
------------------------------
Date: Thu, 07 Aug 2003 05:10:41 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: CGI.pm and foreach
Message-Id: <Xns93D03EDD68DBDsdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"W K" <hyagillot@tesco.net> wrote in
news:bgt1p4$l3o$1@titan.btinternet.com:
>
> "Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
> news:Xns93CEC916F7CEAsdn.comcast@206.127.4.25...
>
>> Aw, to heck with them if they can't learn The Perl Way. ;-)
>>
>> map() is nice because you can use it in expressions. It can make
>> many things shorter and nicer.
>>
>> Instead of:
>> @lines = <FILE>;
>> foreach (@lines) {
>> chomp;
>> $_ = uc;
>> }
>>
>> you can do:
>> @lines = map {chomp; uc} <FILE>;
>
> Also, we used to have a manager type who used to ask how many lines of
> code we had written today.
Ah, let's hear it for useless code metrics! :-)
Well, in that case, you could write
@lines
=
map
{
chomp;
uc;
}
<FILE>;
Or maybe this would have made the manager happy:
my @rawlines;
my @lines;
while (<FILE>)
{
push @rawlines, $_;
}
my $rl;
foreach $rl (@rawlines)
{
my $line = $rl;
chomp $line;
$line = uc $line;
push @lines, $line;
}
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPzIlpGPeouIeTNHoEQK2mACg3pKvncEFEbvrBkA2KNAn32uym1gAoLUV
trp8cLXNirHqUQu9i9jTE5ly
=PV6h
-----END PGP SIGNATURE-----
------------------------------
Date: Thu, 7 Aug 2003 12:44:09 +0200
From: "Rene Scheibe" <Rene.Scheibe@Stud.TU-Ilmenau.de>
Subject: Checking number of instances running
Message-Id: <bgtaio$s1r5a$1@ID-65612.news.uni-berlin.de>
...what do you think about checking the number
of scripts (with a specific name) running by:
my $processname = 'script.pl';
my @log = split /\n+/, `ps ax`;
my $count = 0;
foreach (@log)
{
chomp;
if (/$processname/)
{
$count++;
}
}
Or is there a better solution?
I need this to check at startup of the script
if the max. number of instances i want to allow
is already reached and then to exit new
instances right after this test.
Thanks...
...Rene
------------------------------
Date: Thu, 07 Aug 2003 12:51:58 +0000
From: pete <pete@localho.st>
Subject: Re: Checking number of instances running
Message-Id: <92rYa.971$zB6.50422@newsfep2-gui.server.ntli.net>
Rene Scheibe wrote:
> ...what do you think about checking the number
> of scripts (with a specific name) running by:
>
> my $processname = 'script.pl';
> my @log = split /\n+/, `ps ax`;
> my $count = 0;
> foreach (@log)
> {
> chomp;
> if (/$processname/)
> {
> $count++;
> }
> }
>
> Or is there a better solution?
> I need this to check at startup of the script
> if the max. number of instances i want to allow
> is already reached and then to exit new
> instances right after this test.
>
> Thanks...
> ...Rene
You could do
my $processname = "script.pl";
$instances = `ps aux|grep $processname`;
exit if $instances;
That might be slightly faster
Pete
------------------------------
Date: Thu, 7 Aug 2003 22:04:45 +1000
From: "Gregory Toomey" <NOSPAM@bigpond.com>
Subject: Re: Checking number of instances running
Message-Id: <bgtf62$s5b3p$1@ID-202028.news.uni-berlin.de>
"Rene Scheibe" <Rene.Scheibe@Stud.TU-Ilmenau.de> wrote in message
news:bgtaio$s1r5a$1@ID-65612.news.uni-berlin.de...
> ...what do you think about checking the number
> of scripts (with a specific name) running by:
>
> my $processname = 'script.pl';
> my @log = split /\n+/, `ps ax`;
> my $count = 0;
> foreach (@log)
> {
> chomp;
> if (/$processname/)
> {
> $count++;
> }
> }
>
> Or is there a better solution?
I have a similar Perl script that may give you a few ideas:
for (split '\n', qx(ps -u $> -o pid,etime,cmd --no-headers)) {
($pid, $tname, $etime,$cmd) = unpack "a5 x a11 x a8 x a200",$_;
$etime =~ /((\d*):)?(\d*):(\d*)$/; #elapsed time
$ehour = $2;
$emin = $3;
$background=/\?/; #foreground or background
# ...etc
}
Here 'ps -u $>' selects all processes for the user.
gtoomey
------------------------------
Date: Thu, 7 Aug 2003 14:06:10 +0200
From: "Rene Scheibe" <Rene.Scheibe@Stud.TU-Ilmenau.de>
Subject: Re: Checking number of instances running
Message-Id: <bgtfc5$s6cm7$1@ID-65612.news.uni-berlin.de>
> my $processname = "script.pl";
> $instances = `ps aux|grep $processname`;
> exit if $instances;
this exits even if no instance of the script
is running because "ps aux|grep script.pl"
itself is shown as process. and using awk
will slow down things i think.
...rene
------------------------------
Date: Thu, 7 Aug 2003 14:09:18 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Convert UTF-8 to unicode?
Message-Id: <Pine.LNX.4.53.0308071326400.3115@lxplus089.cern.ch>
On Thu, Aug 7, Alan J. Flavell inscribed on the eternal scroll:
> On Wed, Aug 6, Nigel Horne inscribed on the eternal scroll:
> > An "od -x" of the file looks like
> > this:
> >
> > 0000000 a4e6 e79c a2b4
>
> I think that's OK; I'm not too good with doing utf-8 in my head.
The only octets in there which could be the first octet of a utf-8
character are the "e6" and "e7", and, since they are both of the form
"1110xxxx", each would be followed by two non-first octets (see the
utf-8 spec if you don't get this). Non-first octets have to be of the
form "10xxxxxx" i.e one of 8x, 9x, ax or bx. The bytes appear to be in
the wrong order for that.
I think this is because od printed little-endian 16-bit units instead
of printing bytes in sequence. Could it be that the actual byte
sequence in question is:
e6 a4 9c , e7 b4 a2
If so, then that could indeed be a legal utf-8 sequence, representing
two CJK-unified characters, namely U+691c and u+7d22.
http://www.unicode.org/cgi-bin/GetUnihanData.pl?codepoint=691C
http://www.unicode.org/cgi-bin/GetUnihanData.pl?codepoint=7d22
I don't read CJK myself, sorry, so this is sheer guesswork, I have no
idea whether it makes sense in the original.
But I come back to the original question. It looks as if in Perl 5.8
you can simply read this in and print it out (having opened the files
with :utf8 if you hope for the data to make any kind of sense in the
program). So, at which point are you experiencing a problem?
------------------------------
Date: Thu, 07 Aug 2003 11:21:14 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: CPAN update
Message-Id: <20030807072027.36c114a3.jwillmore@cyberia.com>
> hi all,
> I only have access to a http proxy, and everytime when I try to get
> an module, it goes to a ftp site, is there a way I can configure it
> to update from a http connection?
If you mean using the CPAN shell, you'll need to change your
configuration to point to the HTTP proxy. Check the CPAN
documentation on how to do this (perldoc CPAN). I believe it's
something along the lines of:
o conf http_proxy <URL of the proxy>
You can also set an environmental variable to point to the proxy.
Consult the documentation for your OS and CPAN on how to do this.
The same applies to the FTP proxy - just point the FTP proxy variable
to the HTTP proxy.
HTH
Jim
------------------------------
Date: Thu, 07 Aug 2003 12:44:02 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Get my PID
Message-Id: <mQrYa.24010$td7.5875@nwrddc01.gnilink.net>
Willem Kossen wrote:
> I need a way to get the process ID the script is running under from
> the script itself and output it to a pidfile in /var/run. Anyone an
> idea how to do this.
"perldoc perlvar" and scroll down to
$PROCESS_ID
$$ The process number of the Perl running this script. [...]
jue
------------------------------
Date: Thu, 07 Aug 2003 12:10:36 GMT
From: Mothra <mothra@mothra.com>
Subject: Getting hostnames from remote servers....
Message-Id: <pan.2003.08.07.12.11.35.979145@mothra.com>
I'll try and put this as concisely as I can (and yes, it's definitely a
Perl issue):
I had some code that goes out and logs onto my Unix servers by IP and
creates a new root password. The IP addess, root password and crypt
string are stored in a hash table that is loaded in at the start of the
code and then written back out to a file (that is then crypted) stored on
my central admin server.
This was then made effective on the servers by stuffing the crypt string
into /etc/shadow thus:
system($ssh, $server, "
cp /etc/shadow /etc/shadow.old
echo $rootstring>/etc/shadow
grep -v '^root:' /etc/shadow.old >>/etc/shadow ");
This worked by the way, but I wanted to also store the hostname of the
machine in the hash table. I reckoned the most surefire way was to get it
while I was SSHing in to each server by running the "hostname" command,
rather than relying on the hosts file on the central admin server (and
these servers are not in DNS). I got this working and then recently I
accidentally trashed my code and the last backup copy didn't have this
modification in it. And I've forgotten how I did it. Bummer.
I can't remember whether I eventually used IO::Pipe, IO::File, the dreaded
backticks or stuck with system(), but I've tried all of these recently and
every time, instead of the value of hostname, all I get is the exit status
of the command (i.e. '0') in my hash table where the hostname should be.
Can anyone help?
------------------------------
Date: Thu, 07 Aug 2003 13:43:53 +0000
From: Garry Short <g4rry_sh0rt@zw4llet.com>
Subject: Re: Getting hostnames from remote servers....
Message-Id: <3f32498f$0$46005$65c69314@mercury.nildram.net>
Mothra wrote:
<SNIP>
> I can't remember whether I eventually used IO::Pipe, IO::File, the dreaded
> backticks or stuck with system(), but I've tried all of these recently and
> every time, instead of the value of hostname, all I get is the exit status
> of the command (i.e. '0') in my hash table where the hostname should be.
>
> Can anyone help?
This works:
perl -e '$h = `hostname`; print "HOST -> $h\n" '
You *may* need to assign the output of the backticks to an array, since
you're running multiple commands (don't know if any of them will return any
codes to the calling script).
However, if you do something like:
@returns = `
command1
command2
...
commandx
hostname
`;
then $returns[-1] should have the hostname you're after.
Regards,
Garry
------------------------------
Date: Thu, 07 Aug 2003 11:39:00 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: hash key of %ENV is case insensitive (Win32)
Message-Id: <20030807074056.2570a45c.jwillmore@cyberia.com>
> Today I found (in Win32) something interesting about %ENV:
>
> $ENV{cAsE_iNsEnSiTiVe} = 'good';
> print $ENV{case_insensitive};
> __END__
> good
>
> The hash key is case insensitive!!!
>
> If we want to do this magic (case insensitive hash key),
> the only approach I can think of is using "tie". But %ENV is not:
>
> print tied %ENV? 'tied': 'not tied';
> __END__
> not tied
If I follow and understand correctly, you found that the %ENV special
variable to be case insensitive on a WIN32 system - correct?
This is my understanding of what happens (someone correct me if I'm
wrong).
This is a reflection of the OS, not Perl. Take the following
examples:
set path=%path%;c:\adir
SET PATH=%PATH%;C:\ADIR
set Path=%Path%;C:\ADIR
All will set the PATH environmental variable on a WIN32 system in DOS.
Since Perl is (un)setting environmental variable(s) in %ENV, whatever
you can do at the command line is the behavior you will see using
%ENV.
In perlvar, it says the following about %ENV:
%ENV
$ENV{expr}
The hash %ENV contains your current environment.
Setting a value in "ENV" changes the environment
for any child processes you subsequently fork()
off.
Since you're going to set the environment (and maybe fork() off a
child), this is going to be done at the OS level. So, whatever you
can do at the OS level is going to happen in Perl.
HTH
Jim
------------------------------
Date: Thu, 07 Aug 2003 12:56:11 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: hash key of %ENV is case insensitive (Win32)
Message-Id: <L%rYa.24032$td7.10201@nwrddc01.gnilink.net>
John Lin wrote:
> Today I found (in Win32) something interesting about %ENV:
>
> $ENV{cAsE_iNsEnSiTiVe} = 'good';
> print $ENV{case_insensitive};
> __END__
> good
>
> The hash key is case insensitive!!!
Right observation, wrong conclusion.
It is not the hash key, it is the names of the CMD environment variables
which are case insensitive.
That is %tmp%, %TMP%, and %Tmp% are all the same for DOS.
Perl does the right thing by mirroring this behaviour in the %ENV hash.
> If we want to do this magic (case insensitive hash key),
> the only approach I can think of is using "tie". But %ENV is not:
Why would you want to have a case sensitive %ENV that cannot be mapped any
more to the case insensitive CMD environment variables?
This is in no way different to filename in DOS/Windows.
Yes, you can have upper case and lower case and mixed case file names. But
nevertheless "Foo", "foo", and "FOO" are the same file.
Are you suggesting that Perl implements some layer that makes those three
files different?
jue
------------------------------
Date: Thu, 7 Aug 2003 06:10:16 -0500
From: "Jim Rendant" <jrendant@comcast.net>
Subject: I need GD for Redhat 9
Message-Id: <7TednarMlYtlr6-iXTWJjw@comcast.com>
I downloaded the GD module from CPAN and tried to compile it on redhat 9 and
it fails. Where can I get a pre-compiled version of this module?
I am also looking to run the GD::barcode module. Is this also pre compiled?
Have a great day!
Jim Rendant
------------------------------
Date: Thu, 07 Aug 2003 07:43:37 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: I need GD for Redhat 9
Message-Id: <OXqYa.2762$wQ5.12161@weber.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Jim Rendant wrote:
> I downloaded the GD module from CPAN and tried to compile it on redhat 9 and
> it fails.
This is a technical newsgroup. What was the error message(s) you received?
>Where can I get a pre-compiled version of this module?
Most image modules don't do the image processing themselves, but rely on external libraries to do it
for them. For example, GD.pm requires libgd.so/libgd.a (the GD library) to exist before it will
compile and function.
Do you have the GD library installed on your system ? Does it's version match the one recommended in
GD.pm's readme ?
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/MjtueS99pGMif6wRAlb5AKCxupX+Jqoc4L658z2djVWp/F+J/gCfdhxb
DIVsgT3qVHMM3ChOxHAJFtk=
=A+nB
-----END PGP SIGNATURE-----
------------------------------
Date: Thu, 7 Aug 2003 21:51:28 +1000
From: "Gregory Toomey" <NOSPAM@bigpond.com>
Subject: Re: I need GD for Redhat 9
Message-Id: <bgted8$rsqt8$1@ID-202028.news.uni-berlin.de>
"Jim Rendant" <jrendant@comcast.net> wrote in message
news:7TednarMlYtlr6-iXTWJjw@comcast.com...
> I downloaded the GD module from CPAN and tried to compile it on redhat 9
and
> it fails. Where can I get a pre-compiled version of this module?
>
> I am also looking to run the GD::barcode module. Is this also pre
compiled?
>
> Have a great day!
> Jim Rendant
I had some trouble as well. There seems to be lots of "addons" in the latest
version.
Version 1.19 (the last version with gif support) installed OK for me on
Redhat 9.
See GD-1.19-* at http://cpan.org/modules/by-module/GD/
gtoomey
------------------------------
Date: Thu, 7 Aug 2003 19:28:58 +0800
From: "j" <perseus_medusa@hotmail.com>
Subject: logging
Message-Id: <3f323670$1@newsgate.hknet.com>
Hi all ,
what's the common module that's used for logging ? i have looked into
log4perl. But seems that not quite mature and doesn't support
multithreading. Anyone has some idea ?
Thanks.
perseus
------------------------------
Date: Thu, 07 Aug 2003 12:21:16 GMT
From: Mothra <mothra@mothra.com>
Subject: Re: logging
Message-Id: <pan.2003.08.07.12.22.15.143780@mothra.com>
On Thu, 07 Aug 2003 19:28:58 +0800, j wrote:
> Hi all ,
>
> what's the common module that's used for logging ? i have looked
> into
> log4perl. But seems that not quite mature and doesn't support
> multithreading. Anyone has some idea ?
>
Normally I stick an error-handling subroutine in my code that appends
warnings and errors to one or more logfiles and then use Logfile::Rotate
to compress and rotate them. I take it you want to do something more than
this - can you be more specific?
------------------------------
Date: Thu, 7 Aug 2003 11:47:16 +0100
From: "Matt Churchyard" <matt@userve.net>
Subject: Re: nested HTML parsing
Message-Id: <3f3225cd$1@news.userve.net>
the only way i can see of achieving this is by processing the tag values
1 character at a time and setting a flag when you hit a nested tag
below is a little subroutine which turns a nested thtml tag into a data
structure
use Data::Dumper;
$tag = <<"EOF";
<thtml type="if" condition="<thtml type="cgiparam" name="xxx"
nextparam="<thtml type="internal" parm1="aaa" parm2="bb">">" name="4th">
EOF
$tag = &process_tag($tag);
print Dumper($tag);
sub process_tag
{
my $tag = shift;
my (%details, $tname, $char, $depth, $args);
my ($place, $name, $value, $inquotes);
# check for a tag
return $tag unless $tag =~ /^<thtml.+>/s;
# get rid of <>, newlines
$tag =~ s/\r|\n/ /g;
$tag =~ s/^<|>$//g;
# split tag name and attributes and append space to args
($tname, $args) = split(/\s+/,$tag,2);
$args .= " ";
# add tagname to details hash
$details{'tagname'} = $tname;
# set flags
$depth = $place = $inquotes = 0;
# loop through characters in string
for(0..length($args)-1)
{
# get next character
$char = substr($args, $_, 1);
# update our position if we meet a value
if( $char eq '=' && !$place && !$depth )
{
$place = 1;
}
# value is quoted
elsif( $place == 1 && !$depth && $char =~ /["']/ )
{
$inquotes = $inquotes ? 0 : 1;
}
# if we're inside a value, have no depth, are not in quotes
# and meet a space, we should be at the end
elsif( $place == 1 && !$depth && !$inquotes && $char =~ /\s/ )
{
# save attribute and reset values
$details{$name} = &process_tag($value);
$name = $value = "";
$place = 0;
}
# if we're inside a value or we're in an attribute name
elsif( $place || (!$place && $char !~ /\s/) )
{
# update depth if we meet a nested tag
$depth++ if $place && $char eq '<';
$depth-- if $place && $char eq '>';
# append character to correct variable
if( $place ){ $value .= $char; }
else { $name .= $char; }
}
}
# return tag details
return \%details;
}
"Vassilis Tavoultsidis" <ixanthi@ixanthi.remove.gr> wrote in message
news:bgsr2q$19d$1@nic.grnet.gr...
> Hello,
>
> I am using HTML::Parser to parse an html file with my own tags [my own
> templating system actually]. The problem is that I want to be able to do
the
> following
>
> <thtml type="if" condition="<thtml type='cgiparam' name='xxx'
> nextparam='<thtml type="internal" parm1="aaa" parm2="bb">'>" name="4th">
>
> As you can see the condition has in it an other tag with signle quotes
which
> in the nextparam has an other tag with double quotes and I would like to
> have that as much as I want. If I write
>
> <thtml type="if" condition="<thtml type='cgiparam' name='xxx'
> nextparam='<thtml type=internal parm1=aaa parm2=bb>'>" name="4th">
>
> where the internal - internal tag has no quotes i managed to parse it. The
> problem should be that it will recognize the first double quote of the
inner
> most tag as the ending quote of the condition parameter.
>
> Any idea how I can overcome this ?
>
> Thank you
>
>
>
------------------------------
Date: 07 Aug 2003 12:16:44 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: nested HTML parsing
Message-Id: <u9n0elzpib.fsf@wcl-l.bham.ac.uk>
"Vassilis Tavoultsidis" <ixanthi@ixanthi.remove.gr> writes:
> I am using HTML::Parser to parse an html file with my own tags [my own
> templating system actually]. The problem is that I want to be able to do the
> following
>
> <thtml type="if" condition="<thtml type='cgiparam' name='xxx'
> nextparam='<thtml type="internal" parm1="aaa" parm2="bb">'>" name="4th">
That is not valid HTML.
> The problem should be that it will recognize the first double quote
> of the inner most tag as the ending quote of the condition
> parameter.
That is correct, that is what any HTML parser should do.
> Any idea how I can overcome this ?
Fix the mistakes in the HTML source
<thtml type="if" condition="<thtml type='cgiparam' name='xxx'
nextparam='<thtml type="internal" parm1="aaa"
parm2="bb">'>" name="4th">
This, of course, has nothing to do with Perl.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 7 Aug 2003 05:57:13 -0500
From: "Jim Rendant" <jrendant@comcast.net>
Subject: Re: perl DBI
Message-Id: <piOdne2L9opwsq-iXTWJgA@comcast.com>
Try running mysql as some one other than root.
Check your permissions on the /var/lib/mysql directory. It drove me nuts for
a while but this may be the problem. This directory should be owned by mysql
with the group mysql.
"sangeetha" <sangeetha_b@india.com> wrote in message
news:4fde56d3.0308050243.72336b6c@posting.google.com...
> Hi Experts,
>
> I'm new to PERL DBI programming i've writen following perl DBI
> program, It seems it is nt able to connect to MySQL.
>
> >>>>>>>>>>>>>> Program <<<<<<<<<<<<<<<<<<<
>
> #!perl
>
> use warnings;
> use strict;
>
> use DBI;
>
> my $dbh;
>
> $dbh = DBI->connect('dbi:mysql:test','root','pepsi');
>
> unless ($dbh) {
> print "Error opening database: $DBI::errstr\n";
> exit ;
> }
>
> my $connected = $dbh->ping;
>
> if ($connected and not int($connected)) {
> print "ping not implemented by '", $dbh->{driver}->{Name},"'.\n";
> } else {
> print "Connection is live\n";
> }
>
> $dbh->disconnect();
>
> <<<<<<<<<<<<< End Program >>>>>>>>>>>>>>>>>>>>
>
> Output Error message:
>
> DBI connect('test','root',...) failed: Can't connect to local MySQL
> server through socket '/tmp/mysql.sock' (2) at db.pl line 10
> Error opening database: Can't connect to local MySQL server through
> socket '/tmp/mysql.sock' (2)
>
> <<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>
>
> Please note i'm able to check my (test) table directly login into
> "mysql" by "mysql -u root -p" ... checked "mysqld" is running in
> localhost.. MySQL version is "mysql Ver 11.18 Distrib 3.23.56, for
> redhat-linux-gnu (i386)".
>
> Tried:
> Modified the "/etc/my.cnf" file to point the "socket" file to
> "/var/lib/mysql//mysql.sock". for the header of "[client] and
> [mysqld]" even now it's not working....
>
> Please point where it goes wrong.
>
> Thanks,
> Sangeetha.
------------------------------
Date: Thu, 07 Aug 2003 11:11:44 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: perl DBI
Message-Id: <20030807071341.082d6699.jwillmore@cyberia.com>
> $dbh = DBI->connect('dbi:mysql:test','root','pepsi');
You could try:
$dbh =
DBI->connect('dbi:mysql:database=test;host=localhost','root','pepsi');
and see if that works for you (this is a syntax from the DBD::mysql
documentation).
You could also add the following after the connect line:
DBI->(4, "tracefile.txt");
This will create a verbose trace file for your review. It will
describe the "conversation" between your script and the database.
This will help to diagnose where the failure is (ie MySQL
mis-configuration, MySQL not running, etc.).
> <<<<<<<<<<<<< End Program >>>>>>>>>>>>>>>>>>>>
>
> Output Error message:
>
> DBI connect('test','root',...) failed: Can't connect to local MySQL
> server through socket '/tmp/mysql.sock' (2) at db.pl line 10
> Error opening database: Can't connect to local MySQL server through
> socket '/tmp/mysql.sock' (2)
>
Check to see if your MySQL database server is configured to allow
connections from sources other than the mysql client. It is my
understanding that you need to allow connections to MySQL from
something other than the socket it opens - you need to allow
connections to port 3306 (or some variation). You also need to check
the MySQL log file to see if the database is being contacted and
what's it's doing when it is contacted.
I'd check MySQL first, because the error you're getting is more likely
created because of something with the way MySQL is set up versus the
way you wrote the script. The trace file and checking of the logs
will verify or invalidate what I've said.
HTH
Jim
P.S. - ALWAYS remove passwords from posts (I now know your root
password for MySQL is 'pepsi'). I HOPE that you included the password
as an example and it's NOT really the password. Use something like
'foo' or 'bar' - we'll all know that should be an example versus a
real password. And you should NEVER set up 'root' with accounts to
such things as a database unless you have a very valid reason to do
so. root has enough power as is - no sense in giving the root account
any more power without a good reason to do so - use another account
for
superuser or admin fuctions in MySQL.
------------------------------
Date: 7 Aug 2003 05:56:54 -0700
From: kuujinbo@hotmail.com (ko)
Subject: Re: Replace a word if its not in an html tag
Message-Id: <92d64088.0308070456.42f83401@posting.google.com>
tim.cavins@sitel.com (Tim) wrote in message news:<dc9a9e04.0308061228.3b6cf4b7@posting.google.com>...
> What would the regular expression be to replace the word "body" in an
> html document as long as it's not in between < and > so it doesn't
> replace the actual body tag or anything else with body?
>
> Thanks in advance for any help.
>
> -Tim
As others in the thread have suggested, parsing HTML with a regular
expression is not reliable. If you do a lot of HTML parsing,
HTML::TreeBuilder (http://search.cpan.org/author/SBURKE/HTML-Tree-3.17/lib/HTML/TreeBuilder.pm)
is a good start. If you're using Windows, the latest ActiveState
builds include the module with the default install. You need a basic
understanding of Perl objects, but with a little effort, its not too
bad - I'm definitely not an expert in Perl or programming in general.
Here's a quick fix:
#!/usr/bin/perl -w
use strict;
use HTML::TreeBuilder;
my $html = HTML::TreeBuilder->new();
$html->parse_file('test.html');
$html->objectify_text();
my @text_nodes = $html->look_down('_tag','~text',
sub { $_[0]->attr('text') =~ /\bbody\b/i }
);
foreach (@text_nodes) {
(my $new_text = $_->attr('text')) =~ s#\bbody\b##ig;
$_->attr('text',$new_text);
}
$html->deobjectify_text();
print $html->as_HTML();
$html->delete();
Basically, the look_down() method pulls out all text segments, and the
attr() method in the foreach loop does the replacement. As already
noted, depending your *exact* needs, the regular expression used to
identify/replace the string may need to be modified.
HTH
ko
------------------------------
Date: Thu, 07 Aug 2003 10:00:25 +0000
From: Garry Short <g4rry_sh0rt@zw4llet.com>
Subject: Re: ssh and Perl
Message-Id: <3f32307f$0$46012$65c69314@mercury.nildram.net>
Gunter Schelfhout wrote:
> I'm trying to execute a small Perl-script via ssh like this:
> ssh <target_pc> perl -e ' print "hello\n" '
>
> But this doesn't seem to work.
>
> Someone who has an idea?
Okay, the most obvious one:
1. What makes you think this belongs in a Perl newsgroup?
Others to think about before you ask on a more relevant newsgroup:
2. Is the SSH connections actually working?
3. Is Perl installed on the remote machine?
HTH,
Garry
------------------------------
Date: Thu, 07 Aug 2003 11:40:20 GMT
From: Mothra <mothra@mothra.com>
Subject: Re: ssh and Perl
Message-Id: <pan.2003.08.07.11.41.20.227404@mothra.com>
On Thu, 07 Aug 2003 10:00:25 +0000, Garry Short wrote:
> Gunter Schelfhout wrote:
>
>> I'm trying to execute a small Perl-script via ssh like this:
>> ssh <target_pc> perl -e ' print "hello\n" '
>>
>> But this doesn't seem to work.
>>
>> Someone who has an idea?
>
> Okay, the most obvious one:
> 1. What makes you think this belongs in a Perl newsgroup?
>
> Others to think about before you ask on a more relevant newsgroup:
> 2. Is the SSH connections actually working?
> 3. Is Perl installed on the remote machine?
>
Come on, that's a bit harsh. He was trying to run some simple Perl code
- that's obviously why he thought it was suitable for a Perl newsgroup.
You've got to start somewhere.
Someone on comp.security.ssh might just as likely have knocked him back to this
group anyway, telling him it's not an SSH issue.
Or maybe he simply believed the hype about Perl coders all being
friendly & helpful? ;-)
------------------------------
Date: Thu, 07 Aug 2003 13:27:51 +0000
From: Garry Short <g4rry_sh0rt@zw4llet.com>
Subject: Re: ssh and Perl
Message-Id: <3f3246e0$0$46002$65c69314@mercury.nildram.net>
Mothra wrote:
> On Thu, 07 Aug 2003 10:00:25 +0000, Garry Short wrote:
>
>> Gunter Schelfhout wrote:
>>
>>> I'm trying to execute a small Perl-script via ssh like this:
>>> ssh <target_pc> perl -e ' print "hello\n" '
>>>
>>> But this doesn't seem to work.
>>>
>>> Someone who has an idea?
>>
>> Okay, the most obvious one:
>> 1. What makes you think this belongs in a Perl newsgroup?
>>
>> Others to think about before you ask on a more relevant newsgroup:
>> 2. Is the SSH connections actually working?
>> 3. Is Perl installed on the remote machine?
>>
> Come on, that's a bit harsh. He was trying to run some simple Perl code
> - that's obviously why he thought it was suitable for a Perl newsgroup.
> You've got to start somewhere.
>
> Someone on comp.security.ssh might just as likely have knocked him back to
> this group anyway, telling him it's not an SSH issue.
>
> Or maybe he simply believed the hype about Perl coders all being
> friendly & helpful? ;-)
Sorry, it wasn't meant to come across as harsh. It was just extremely
obviously not a perl problem (checking it from a command line, if you're
not sure, takes all of 20 secs). The other two questions were intended to
make sure that he definitely was in a position to at least *try* and do
what he wanted.
However, saying that it's okay to post here, just because there's some perl
code included, is possibly a little too ... "relaxed". That would make it
okay to ask why:
perl -e ' system("ps uax | sort -k2") '
doesn't sort the output by %CPU. Okay, it's a perl script, but what does the
problem have to do with perl?
Regards,
Garry
(the answer, btw, is that sort numbers the columns from 1, not 0, so you'd
want "sort -k3" [on my Linux box, anyway])
------------------------------
Date: Thu, 07 Aug 2003 12:42:55 GMT
From: lostriver <vladimir@NoSpamPLZ.net>
Subject: Re: ssh and Perl
Message-Id: <jPrYa.257$6b2.23346@wagner.videotron.net>
On Thu, 07 Aug 2003 08:33:21 GMT, Gunter Schelfhout wrote:
> I'm trying to execute a small Perl-script via ssh like this:
> ssh <target_pc> perl -e ' print "hello\n" '
>
> But this doesn't seem to work.
>
> Someone who has an idea?
Well, you have got enough explanations why you should not ask questions
like this here....
Here is how you can do it:
ssh <target_pc> 'perl -e " print \"hello\n\"" '
Or better yet make it 'a perl question' - install and use Net::SSH::Perl
module (pure perl implementation of SSH protocol).
--
.signature: No such file or directory
------------------------------
Date: 07 Aug 2003 10:20:24 GMT
From: Heinrich.Mislik@univie.ac.at (Heinrich Mislik)
Subject: Re: What do you think of my first "JAPH"?
Message-Id: <3f3227e8$0$19360$3b214f66@usenet.univie.ac.at>
In article <vj3nlntb633uf8@corp.supernews.com>, spamblock@junkmail.com says...
>Please take a look at, and offer comments on my first "JAPH."
>
>What a good learning experience it is to think through something like this,
>and then try to figure out how to do it in a more compact, and possibly more
>obfuscated way. Kind of fun.
>
>Here it is. It runs fine under 5.6.1 and 5.8.0. YMMV.
>
>perl -e 'my %rt; @rt{qw/.- -... -.-. -.. . ..-. --. .... .. .--- -.-
>.-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. .-.-.- |
>!/}=("A".."Z","."," ","\n"); for(split /\s+/,".--- ..- ... - | .- -. --- -
>.... . .-. | .--. . .-. .-.. | .... .- -.-. -.- . .-. .-.-.- !"){print
>$rt{$_};}'
What about:
perl -we'for(split" ",".--- ..- ... - | .- -. --- - .... . .-. |
.--. . .-. .-.. | .... .- -.-. -.- . .-. .-.- ..--"){tr/-.|/10/d;
print". ETIANMSURWDKGOHVF\nL.PJBXC"=~/.{${\oct("0b1$_")}}(.)/s}'
The morse decoder is incomplete and deliberatly defines codes for . and \n
but works ok for JAPH.
Have fun.
--
Heinrich Mislik
Zentraler Informatikdienst der Universitaet Wien
A-1010 Wien, Universitaetsstrasse 7
Tel.: (+43 1) 4277-14056, Fax: (+43 1) 4277-9140
------------------------------
Date: Thu, 07 Aug 2003 05:25:14 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: What do you think of my first "JAPH"?
Message-Id: <Xns93D041547A3B0sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"David Oswald" <spamblock@junkmail.com> wrote in
news:vj40j625s5hfeb@corp.supernews.com:
> Here's the slightly modified JAPH:
>
> perl -e '@rt{qw/.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. --
> -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. .-.-.- |
> !/}=("A".."Z","."," ","\n");for(split /\s+/,".--- ..- ... - | .- -.
> --- - .... . .-. | .--. . .-. .-.. | .... .- -.-. -.- . .-. .-.-.-
> !"){print $rt{$_};}'
Your ("A".."Z","."," ","\n") can be simplified / further obfuscated.
First, barewords don't need quotes in perl if you're not using strict. So
"A".."Z" can be written simply as A..Z.
Second, when obfuscating, $" is better than " ", and $/ is better than
"\n". :-)
Third, you can trip some people up by using an alphabetic character as a
quoting character.
So you might write that expression as:
( A .. Z, q X.X, $", $/ )
See my signature for additional examples of this.
- --
Eric
$ _ = reverse sort $ / . r , qw p ekca lre uJ ts
reh p, map $ _ . $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPzIpCWPeouIeTNHoEQJylwCghTfWQruPREJyDO/8cSNiXPd9dXkAoJd8
JLeooareOBrI4JIjvXd0eC7Q
=OL1f
-----END PGP SIGNATURE-----
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5328
***************************************