[31456] in Perl-Users-Digest
Perl-Users Digest, Issue: 2708 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 6 21:09:45 2009
Date: Sun, 6 Dec 2009 18:09: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 Sun, 6 Dec 2009 Volume: 11 Number: 2708
Today's topics:
Re: "negative" regex matching? sln@netherlands.com
Re: "negative" regex matching? sln@netherlands.com
Re: "negative" regex matching? sln@netherlands.com
How to add system user accounts with perl? <nobody@nowhere.com>
Re: How to add system user accounts with perl? <ben@morrow.me.uk>
Re: How to add system user accounts with perl? <sysadmin@example.com>
Re: How to add system user accounts with perl? <ben@morrow.me.uk>
Perl CGI table row heading <spam.meplease@ntlworld.com>
Re: Perl CGI table row heading <sreservoir@gmail.com>
Re: Perl CGI table row heading <spam.meplease@ntlworld.com>
Re: Want to judge some remote hosts online or not quick <mvdwege@mail.com>
Re: Want to judge some remote hosts online or not quick <hongyi.zhao@gmail.com>
Re: Want to judge some remote hosts online or not quick <mvdwege@mail.com>
Re: Want to judge some remote hosts online or not quick <john@castleamber.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 05 Dec 2009 12:45:14 -0800
From: sln@netherlands.com
Subject: Re: "negative" regex matching?
Message-Id: <d4hlh5lnrksh9equdvc1doj8edmh47oibh@4ax.com>
On Fri, 4 Dec 2009 14:50:59 -0800 (PST), "seven.reeds" <seven.reeds@gmail.com> wrote:
>Hi,
>
>I have a regex question. I have arbitrary text and I want to search
>it for a set of terms/substrings. In the simple case of one term
>it is easy to find the match(es) and then mark them up with HTML
>"span" tags. My issue is with more than one term.
>
>Here is an example to illustrate. If I have the string:
>
> Sarah likes Johnny's cooking
>
>and the single term: "john" then I can match and highlight the match
>resulting in:
>
> Sarah likes <span>John</span>ny's cooking
>
>Now what if I have two terms: "Johnny" & "john" -- in that order? I
>can easily let myself end up with (in sequence):
>
> <apply Johnny match>
> Sarah likes <span>Johnny</span>'s cooking
> <apply john match>
> Sarah likes <span><span>John</span>ny</span>'s cooking
>
>Ok, so what I want is to be able to search for and mark each term in
>the string as long as that term is not already in a "span" clause.
>
>I've done some digging in Friedl's RegEx book but I'm not sure if I
>know enough to know what I am looking for?
>
>ideas?
This what you are trying to do?
rxhtml.pl
-sln
----------------
use strict;
use warnings;
## globs ..
my $string = "
<apply Johnny match>
Sarah likes Johnny's cooking
<apply john match>
Sarah likes Johnny's cooking
";
## code ..
# use terms: Johnny,john
if ( getMatch( $string,'span','Johnny|john')) # add mods in term's
{ print "Matched:\n'$string'\n\n" }
else
{ print "No match.\n\n" }
# use terms: King,john .. case insensitive
if ( getMatch( $string,'span','(?i)King|john'))
{ print "Matched:\n'$string'\n\n" }
else
{ print "No match.\n\n" }
exit(0);
## subs ..
sub getMatch {
my ($tag,$terms) = @_[1,2];
$_[0] =~ s {(?<!<$tag>)(.*)($terms)(?!.*</?$tag>)}
{$1<$tag>$2</$tag>}g;
}
__END__
Matched:
'
<apply <span>Johnny</span> match>
Sarah likes <span>Johnny</span>'s cooking
<apply <span>john</span> match>
Sarah likes <span>Johnny</span>'s cooking
'
Matched:
'
<apply <span>Johnny</span> match>
Sarah likes <span>Johnny</span>'s coo<span>king</span>
<apply <span>john</span> match>
Sarah likes <span>Johnny</span>'s coo<span>king</span>
'
------------------------------
Date: Sun, 06 Dec 2009 15:15:18 -0800
From: sln@netherlands.com
Subject: Re: "negative" regex matching?
Message-Id: <ameoh5dfa4i7p2b9vm6br1ad5m7conhd8f@4ax.com>
On Sat, 05 Dec 2009 12:45:14 -0800, sln@netherlands.com wrote:
>On Fri, 4 Dec 2009 14:50:59 -0800 (PST), "seven.reeds" <seven.reeds@gmail.com> wrote:
>
>>ideas?
>
>This what you are trying to do?
>
Yeah but don't do this, it doesen't work.
-sln
------------------------------
Date: Sun, 06 Dec 2009 15:42:25 -0800
From: sln@netherlands.com
Subject: Re: "negative" regex matching?
Message-Id: <doeoh55ugk1fv87brvi1d1qlej8h81kirp@4ax.com>
On Fri, 4 Dec 2009 14:50:59 -0800 (PST), "seven.reeds" <seven.reeds@gmail.com> wrote:
>Hi,
>
>I have a regex question. I have arbitrary text and I want to search
>it for a set of terms/substrings. In the simple case of one term
>it is easy to find the match(es) and then mark them up with HTML
>"span" tags. My issue is with more than one term.
>
[snip]
>
>Ok, so what I want is to be able to search for and mark each term in
>the string as long as that term is not already in a "span" clause.
>
>I've done some digging in Friedl's RegEx book but I'm not sure if I
>know enough to know what I am looking for?
>
>ideas?
I posted an earlier plain look-ahead/behind assertion rx.
But, this won't work because of fixed width look behind.
So this friend, is a bullet proof way to do what you want.
Finally, a use for new 5.10 regex recursion code, which allows
for nested tags.
I've thoroughly tested this code. Taking into account the 'restraints'
of parsing markup (ie: validity), but thats the compromise you are
making for speed.
The regex will go along happily matching tags (in a nested fashion),
or, the terms you specify.
If any terms are inside of the tags (even nested), they are consumed
without any substitution (ie: they are left alone). The only thing
left to match are the terms themselves.
Both match, nested tags or terms, in an alternation (one or the other).
The reason the tags aren't substituted for themselves (ie its capture group)
is because of the new '\K' which excludes the tags.
Read about the new extended expressions
here -> 'perlre' in perldocs.
Also, in addition to tags, tag-attribute form is included as well:
<$tag></$tag> or <$tag attrib></$tag>.
Good luck!
-sln
-------------------
Output:
String =
'
<apply john Johnny match>
Sarah likes Johnny's cooking
<apply john match>
Sarah likes Johnny's cooking
<span id="medium_rectangle" class="_fwph">
Because Johnny does good cooking
</span>
King John
'
Terms =
Johnny|john - replaced 5
'
<apply <span>john</span> <span>Johnny</span> match>
Sarah likes <span>Johnny</span>'s cooking
<apply <span>john</span> match>
Sarah likes <span>Johnny</span>'s cooking
<span id="medium_rectangle" class="_fwph">
Because Johnny does good cooking
</span>
King John
'
(?i)King|john - replaced 4
'
<apply <span>john</span> <span>Johnny</span> match>
Sarah likes <span>Johnny</span>'s coo<span>king</span>
<apply <span>john</span> match>
Sarah likes <span>Johnny</span>'s coo<span>king</span>
<span id="medium_rectangle" class="_fwph">
Because Johnny does good cooking
</span>
<span>King</span> <span>John</span>
'
---------------------------------
use strict;
use warnings;
require 5.010_000;
## globs ..
my ($string, $result) =
qq{
<apply john Johnny match>
Sarah likes Johnny's cooking
<apply john match>
Sarah likes Johnny's cooking
<span id="medium_rectangle" class="_fwph">
Because Johnny does good cooking
</span>
King John
};
## code ..
print "\nString = \n'$string'\n\nTerms =\n";
print "\nJohnny|john - replaced ";
#
$result = getMatch( $string, 'span', 'Johnny|john');
print "$result\n";
print "'$string'\n" if $result;
print "\n(?i)King|john - replaced ";
#
$result = getMatch( $string, 'span', '(?i)King|john'); # case insensitive
print "$result\n";
print "'$string'\n" if $result;
exit(0);
## subs ..
sub getMatch
{
#* USES RX RECURSION '(?#)', new to 5.10
#* Start/End tags must have this specific form:
#* <$tag></$tag> or <$tag attrib></$tag>
#* --------------------------------------
my ($tag,$terms) = @_[1,2];
my $start = "<$tag(?:\\s+|>)"; # allow <tag> or <tag attribute>
my $end = "</$tag>";
my $replaced = 0;
$_[0] =~ s
{ # match ..
( # 1
$start
(?:
(?:(?!$start|$end).)++ # no backtracking
|
(?1) # recurse group 1
)*
$end
)
\K # effecient -- don't include tag data in match
|
( # 2
$terms
)
}
{ # replace ..
$replaced++, "<$tag>".$2."</$tag>" if defined $2
}xsge;
return $replaced;
}
__END__
------------------------------
Date: Sun, 06 Dec 2009 01:21:23 GMT
From: nobody <nobody@nowhere.com>
Subject: How to add system user accounts with perl?
Message-Id: <nGDSm.76268$Td3.35781@en-nntp-01.dc1.easynews.com>
I need to add numerous user accounts on a linux system. I have a list of
user names and passwords like:
jsmith sesam3
rjones abracadb
Of course this is easy enough to create a hash from, but can perl be used
to actually create an account, and set the password as well? So the
entire operation would be equivalent to:
useradd -g somegroup -u someuid -c "jsmith" -s /bin/bash -m rjones
passwd rjones
I've been googling, but couldn't even find a script as a starting point.
-Thanks
------------------------------
Date: Sun, 6 Dec 2009 02:34:31 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to add system user accounts with perl?
Message-Id: <nqhru6-obm1.ln1@osiris.mauzo.dyndns.org>
Quoth nobody <nobody@nowhere.com>:
> I need to add numerous user accounts on a linux system. I have a list of
> user names and passwords like:
>
> jsmith sesam3
> rjones abracadb
>
>
> Of course this is easy enough to create a hash from, but can perl be used
> to actually create an account, and set the password as well? So the
> entire operation would be equivalent to:
>
> useradd -g somegroup -u someuid -c "jsmith" -s /bin/bash -m rjones
>
> passwd rjones
On my system 'pw useradd' accepts a '-h fd' option to read the user's
password from. If yours does the same you can use this to invoke
useradd(8)@ see perldoc perlipc, perldoc -f fork, perldoc -f pipe,
perldoc -f exec, and $^F in perldoc perlvar, or use IPC::Run to wrap the
process for you.
Otherwise, you will need to invoke useradd(8) with system and then use
either IPC::Open2 or Expect to invoke passwd(1). Alternatively, if your
system supports PAM you may be able to use a CPAN module to set the
password that way.
Note that since your script will need to run as root, you should include
-T on the #! line, for security.
Ben
------------------------------
Date: Sun, 06 Dec 2009 16:23:08 -0800
From: Wanna-Be Sys Admin <sysadmin@example.com>
Subject: Re: How to add system user accounts with perl?
Message-Id: <MVXSm.38553$cX4.19122@newsfe10.iad>
nobody wrote:
> I need to add numerous user accounts on a linux system. I have a list
> of user names and passwords like:
>
> jsmith sesam3
> rjones abracadb
>
>
> Of course this is easy enough to create a hash from, but can perl be
> used
> to actually create an account, and set the password as well? So the
> entire operation would be equivalent to:
>
> useradd -g somegroup -u someuid -c "jsmith" -s /bin/bash -m rjones
>
> passwd rjones
>
>
> I've been googling, but couldn't even find a script as a starting
> point.
>
>
> -Thanks
Sure, you can use just about any language to do this. It's all about
parsing the info, checking it's okay, opening files, writing to them
(possibly in the right place, depending on what you're looking to do),
encrypt the password, creating directories, setting permissions and
ownerships, etc. it can be very simple, it just depends on how many
things you need the new (adding) account to do. For the most part,
it's opening the passwd, group, etc. files, adding the info (after
determining the next highest uid/gid that's not taken (probably over
500 as well)), and so on. Or, you can pass the useradd command in
system or exec and let the system's existing tools do the work for you.
--
Not really a wanna-be, but I don't know everything.
------------------------------
Date: Mon, 7 Dec 2009 01:48:40 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to add system user accounts with perl?
Message-Id: <og3uu6-l1v1.ln1@osiris.mauzo.dyndns.org>
Quoth Wanna-Be Sys Admin <sysadmin@example.com>:
> nobody wrote:
>
> > I need to add numerous user accounts on a linux system. I have a list
>
> Sure, you can use just about any language to do this. It's all about
> parsing the info, checking it's okay, opening files, writing to them
> (possibly in the right place, depending on what you're looking to do),
> encrypt the password, creating directories, setting permissions and
> ownerships, etc. it can be very simple, it just depends on how many
> things you need the new (adding) account to do. For the most part,
> it's opening the passwd, group, etc. files, adding the info (after
> determining the next highest uid/gid that's not taken (probably over
> 500 as well)), and so on.
Don't do that. There are more than a few subtleties to adding a new
user, in particular: making sure the passwd file is updated atomically,
being *certain* you've got the format right, regenerating any databases
your system might use, and knowing when you actually need to update some
other file entirely (like /etc/master.passwd on BSD). Getting any of
this wrong is likely to cause serious problems with your system, so just
use the provided tools.
Ben
------------------------------
Date: Sun, 06 Dec 2009 15:15:10 GMT
From: dan <spam.meplease@ntlworld.com>
Subject: Perl CGI table row heading
Message-Id: <2UPSm.30464$6p6.4911@newsfe05.ams2>
I want to create a table with Perl CGI that looks like this:
<table>
<tr>
<th>Row heading</th>
<td>test1</td>
<td>test2</td>
</tr>
</table>
The following creates a table with two rows
table (
Tr ([
th ('row heading'),
td (['test', 'test2'])
])
),
what am I doing wrong?
dan
------------------------------
Date: Sun, 06 Dec 2009 10:37:34 -0500
From: sreservoir <sreservoir@gmail.com>
Subject: Re: Perl CGI table row heading
Message-Id: <hfgj2r$e25$1@aioe.org>
dan wrote:
> I want to create a table with Perl CGI that looks like this:
>
> <table>
> <tr>
> <th>Row heading</th>
> <td>test1</td>
> <td>test2</td>
> </tr>
> </table>
>
> The following creates a table with two rows
>
> table (
> Tr ([
> th ('row heading'),
> td (['test', 'test2'])
> ])
> ),
>
> what am I doing wrong?
perhaps check the output output of the snippet.
its output, indented nicely:
<table>
<tr>
<th>row heading</th>
</tr>
<tr>
<td>test</td>
<td>test2</td>
</tr>
</table>
you want to remove the brackets in the arguments to Tr:
<table>
<tr>
<th>row heading</th>
<td>test</td>
<td>test2</td>
</tr>
</table>
try:
table(
Tr(
th("row heading"),
td [ "test", "test2" ]));
--
"Six by nine. Forty two."
"That's it. That's all there is."
"I always thought something was fundamentally wrong with the universe"
------------------------------
Date: Sun, 06 Dec 2009 15:56:04 GMT
From: dan <spam.meplease@ntlworld.com>
Subject: Re: Perl CGI table row heading
Message-Id: <ouQSm.31516$6p6.4535@newsfe05.ams2>
On Sun, 06 Dec 2009 10:37:34 -0500, sreservoir wrote:
> you want to remove the brackets in the arguments to Tr: <table>
> table(
> Tr(
> th("row heading"),
> td [ "test", "test2" ]));
That works. Thanks.
------------------------------
Date: Sat, 05 Dec 2009 20:21:14 +0100
From: Mart van de Wege <mvdwege@mail.com>
Subject: Re: Want to judge some remote hosts online or not quickly over WAN.
Message-Id: <86zl5xdy6t.fsf@gareth.avalon.lan>
Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> Hi all,
>
> I want to judge some remote hosts online or not quickly over WAN. I've
> learned that ping command will not work in this case if the icmp ack
> is blocked locally by firewall. Is it possiable for me to do this job
> by perl codes?
>
If the remote are supposed to run services, you could use the
appropriate Net::* modules to connect to them and see if the services
are available.
Mart
--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
------------------------------
Date: Sun, 06 Dec 2009 19:04:51 +0800
From: Hongyi Zhao <hongyi.zhao@gmail.com>
Subject: Re: Want to judge some remote hosts online or not quickly over WAN.
Message-Id: <bp3nh5hqf5bins6t428t819favcipc4tfs@4ax.com>
On Sat, 05 Dec 2009 20:21:14 +0100, Mart van de Wege
<mvdwege@mail.com> wrote:
>If the remote are supposed to run services, you could use the
>appropriate Net::* modules to connect to them and see if the services
>are available.
Yes, in my case, I mean the remote host act as a http proxy at
specified ports, such as 80, 3128 and so on.
For example, test hundreds of them, which are stored in a Plain text
file with the foramt of one ip:port per line, e.g.:
...
220.245.140.197:3128
200.19.159.34:3128
200.19.159.35:3128
200.132.0.70:3128
198.163.152.229:3128
198.163.152.230:3128
142.103.2.1:3128
142.103.2.2:3128
128.233.252.11:3128
128.233.252.12:3128
142.150.238.12:3128
142.150.238.13:3128
...
So I want to sove this issue quickly and accurately.
Any hints will be highly appreciated.
Best regards.
--
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
------------------------------
Date: Sun, 06 Dec 2009 19:47:33 +0100
From: Mart van de Wege <mvdwege@mail.com>
Subject: Re: Want to judge some remote hosts online or not quickly over WAN.
Message-Id: <86vdgkdjne.fsf@gareth.avalon.lan>
Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> On Sat, 05 Dec 2009 20:21:14 +0100, Mart van de Wege
> <mvdwege@mail.com> wrote:
>
>>If the remote are supposed to run services, you could use the
>>appropriate Net::* modules to connect to them and see if the services
>>are available.
>
> Yes, in my case, I mean the remote host act as a http proxy at
> specified ports, such as 80, 3128 and so on.
>
> For example, test hundreds of them, which are stored in a Plain text
> file with the foramt of one ip:port per line, e.g.:
>
> ...
> 220.245.140.197:3128
> 200.19.159.34:3128
> 200.19.159.35:3128
<snip>
> So I want to sove this issue quickly and accurately.
> Any hints will be highly appreciated.
>
Erm.
Short of writing your program for you, I cannot give you any more
hints. This is as straightforward as it can get in Perl.
Mart
--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
------------------------------
Date: Sun, 06 Dec 2009 18:22:29 -0600
From: John Bokma <john@castleamber.com>
Subject: Re: Want to judge some remote hosts online or not quickly over WAN.
Message-Id: <87fx7nmy4a.fsf@castleamber.com>
Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> Yes, in my case, I mean the remote host act as a http proxy at
> specified ports, such as 80, 3128 and so on.
>
> For example, test hundreds of them, which are stored in a Plain text
> file with the foramt of one ip:port per line, e.g.:
>
> ...
> 220.245.140.197:3128
[...]
> So I want to sove this issue quickly and accurately.
> Any hints will be highly appreciated.
nmap? I mean, that's what they used in the Matrix :-)
Many systems and network administrators also find it useful for tasks
such as network inventory, managing service upgrade schedules, and
monitoring host or service uptime.
http://nmap.org/
--
John Bokma
Read my blog: http://johnbokma.com/
Hire me (Perl/Python): http://castleamber.com/
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2708
***************************************