[25683] in Perl-Users-Digest
Perl-Users Digest, Issue: 7924 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 29 18:05:28 2005
Date: Tue, 29 Mar 2005 15:05:11 -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 Tue, 29 Mar 2005 Volume: 10 Number: 7924
Today's topics:
How to access Windows IIS User Info with Perl <page.nix@gmail.com>
Re: How to access Windows IIS User Info with Perl <tzz@lifelogs.com>
Performance question <MaxFreedom@sws5.ornl.gov>
Re: Performance question <mritty@gmail.com>
Re: Performance question xhoster@gmail.com
Re: Performance question xhoster@gmail.com
Re: perl update - what about the modules? <spamtrap@dot-app.org>
Re: perl5.8.6 won't install on FreeBSD5.3 ravenslay3r@gmail.com
problem with old version of (Active) Perl k9boy@hotmail.com
using Perl to insert footer into PDF files? codingalex@yahoo.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 29 Mar 2005 11:56:46 -0800
From: "BigNin" <page.nix@gmail.com>
Subject: How to access Windows IIS User Info with Perl
Message-Id: <1112126206.694493.292610@z14g2000cwz.googlegroups.com>
I have a Perl script which runs on a Unix server with Apache as the
http server. With the use of an .htaccess file, only users that login
with basic authentication are able to run the script. This script is
only available on the intranet so it's internal company use only. The
perl script compares the authenticated username with a text file which
contains groups to which certain employees belong and serves different
HTML depending on the user's group memberships.
In our IT department's infinite wisdom, they have moved us to a Windows
2003 server running IIS. I've made the modifications to my script so
that it runs, but the IIS server is configured for Windows
Authentication. The IT department states that this allows users to
login into the network when they first turn on their PC and then the
users don't have to enter any additional usernames or passwords to
authenticate with IIS and my script. My group text file has now been
converted to Windows security groups.
I have searched HotScripts.com, ActiveState.com, and Google and I can
not find any example of how to get perl to read Windows security groups
and tell me which ones the user belongs to. I'm guessing that someone
somewhere has done this before.
My administrators gave me some ASP code that supposedly can do what I
want, but that doesn't really help me do it in perl. For reference, I
have included it below:
Public Function Groups(ByVal SearchResult As
System.DirectoryServices.SearchResult) As String
Dim i As Integer
Dim tmp As String
Dim groupSid As Object
Dim sid() As Byte
Try
Dim de As DirectoryEntry = SearchResult.GetDirectoryEntry
'pull username and password from web.config file.
de.Username =
Configuration.ConfigurationSettings.AppSettings("User")
de.Password =
Configuration.ConfigurationSettings.AppSettings("Pass")
de.RefreshCache(New String() {"tokenGroups"})
'this line is sometimes necessary to get tokenGroups in the
property cache...
'loop through each sid in the tokenGroups
For Each groupSid In de.Properties("tokenGroups")
'just another way of doing a ctype.
sid = DirectCast(groupSid, Byte())
'set up the groupentry for query
'ConvertToOctetString is the important part here. This is
where the real work is.
Dim groupEntry As New
DirectoryEntry(String.Format("LDAP://", ConvertToOctetString(sid)))
Dim propcoll As PropertyCollection = groupEntry.Properties
Dim key As String
Dim values As Object
'loop through all of the properties for this record
For Each key In propcoll.PropertyNames
'loop through all the values associated with our key
For Each values In propcoll(key)
If LCase(key) = "distinguishedname" Then
Dim temp As String = values.ToString
If Not InStr(temp, "ImportedExchange") Then
Dim atemp() As String = temp.Split(",")
tmp &= Replace(atemp(0).ToString, "CN=", ",")
If Left(tmp, 1) = "," Then
tmp = Mid(tmp, 2)
End If
End If
End If
Next
Next
Next
Catch ex As Exception
'process exception
End Try
Return tmp
End Property
'overload for lazy programming
Public Overloads Shared Function ConvertToOctetString(ByVal values As
Byte()) As String
Return ConvertToOctetString(values, False, False)
End Function
'overload for lazy programming
Public Overloads Shared Function ConvertToOctetString(ByVal values As
Byte(), _
ByVal isAddBackslash As Boolean) As String
Return ConvertToOctetString(values, isAddBackslash, False)
End Function
'This is where the work really comes in. This method allows us to
convert the sid
'into a usable string that LDAP can use to search for the groups this
user belongs to.
Public Overloads Shared Function ConvertToOctetString(ByVal values As
Byte(), _
ByVal isAddBackslash As Boolean, ByVal isUpperCase As Boolean) As
String
Dim iterator As Integer
Dim builder As System.Text.StringBuilder
Dim slash As String
If isAddBackslash Then
slash = "\"
Else
slash = String.Empty
End If
Dim formatCode As String
If isUpperCase Then
formatCode = "X2"
Else
formatCode = "x2"
End If
builder = New System.Text.StringBuilder(values.Length * 2)
For iterator = 0 To values.Length - 1
builder.Append(slash)
builder.Append(values(iterator).ToString(formatCode))
Next
Return builder.ToString()
End Function
Thanks in advance to any suggestions.
------------------------------
Date: Tue, 29 Mar 2005 16:55:59 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to access Windows IIS User Info with Perl
Message-Id: <4nu0muxgk0.fsf@lifelogs.com>
On 29 Mar 2005, page.nix@gmail.com wrote:
> I have a Perl script which runs on a Unix server with Apache as the
> http server. With the use of an .htaccess file, only users that login
> with basic authentication are able to run the script. This script is
> only available on the intranet so it's internal company use only. The
> perl script compares the authenticated username with a text file which
> contains groups to which certain employees belong and serves different
> HTML depending on the user's group memberships.
>
> In our IT department's infinite wisdom, they have moved us to a Windows
> 2003 server running IIS. I've made the modifications to my script so
> that it runs, but the IIS server is configured for Windows
> Authentication. The IT department states that this allows users to
> login into the network when they first turn on their PC and then the
> users don't have to enter any additional usernames or passwords to
> authenticate with IIS and my script. My group text file has now been
> converted to Windows security groups.
...
> My administrators gave me some ASP code that supposedly can do what I
> want, but that doesn't really help me do it in perl.
It looks like you are using ActiveDirectory, which has a LDAP
interface. You could use Net::LDAP to do the equivalent of the ASP
code (lookups only). A LDAP browser such as gq for Linux can help you
inspect the specific structure of the user records. I don't know if
you can get all the information you need through LDAP, but I hope so :)
Ted
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
------------------------------
Date: Tue, 29 Mar 2005 13:25:59 -0500
From: Dave Sill <MaxFreedom@sws5.ornl.gov>
Subject: Performance question
Message-Id: <wx0acom1f7s.fsf@sws5.ornl.gov>
One of my users made the following observation. I'm only an
occasional, lightweight Perl user, so I can't explain what he's
seeing. Can anyone shed some light on it? H/W is a pretty large/fast
Dell server running RHEL 3.
----
I manufactured a 401x401 [ linearly =160801 element] array [@judy]
each element having string values like
01000000001110000000000000000001
I needed to make a comma delimited ascii file of this data.
I decided a single IO write of a string would be the fastest, so i
made a string
$str="";
foreach $i(0..$#judy-1)
{
$str=$str."$judy[$i],"
}
$str=$str."$judy[$#judy]"; open(OUT,">$output_file");print OUT
$str;close(OUT);
`gzip -f $output_file`;
this took 16 minutes.
i tried it the slow way,
open(OUT,">$output_file");
foreach $i(0..$#judy-1)
{
print OUT "$judy[$i],";
}
print OUT "$judy[$#judy]"; close(OUT);
`gzip -f $output_file`;
with 160K IOs, this took about 3 seconds.
the gz files were different, but diff said uncompressed they were the
same.
----
Thanks.
--
Dave Sill Oak Ridge National Lab, Workstation Support
Author, The qmail Handbook <http://web.infoave.net/~dsill>
<http://lifewithqmail.org/>: Almost everything you always wanted to know.
------------------------------
Date: Tue, 29 Mar 2005 18:35:47 GMT
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Performance question
Message-Id: <7eh2e.39625$FB6.20736@trndny09>
Dave Sill wrote:
> One of my users made the following observation. I'm only an
> occasional, lightweight Perl user, so I can't explain what he's
> seeing. Can anyone shed some light on it? H/W is a pretty large/fast
> Dell server running RHEL 3.
>
> ----
> I manufactured a 401x401 [ linearly =160801 element] array [@judy]
> each element having string values like
>
> 01000000001110000000000000000001
>
> I needed to make a comma delimited ascii file of this data.
>
> I decided a single IO write of a string would be the fastest, so i
> made a string
> $str="";
> foreach $i(0..$#judy-1)
> {
> $str=$str."$judy[$i],"
> }
> $str=$str."$judy[$#judy]"; open(OUT,">$output_file");print OUT
> $str;close(OUT);
> `gzip -f $output_file`;
>
> this took 16 minutes.
>
> i tried it the slow way,
>
> open(OUT,">$output_file");
> foreach $i(0..$#judy-1)
> {
> print OUT "$judy[$i],";
> }
> print OUT "$judy[$#judy]"; close(OUT);
> `gzip -f $output_file`;
>
> with 160K IOs, this took about 3 seconds.
>
> the gz files were different, but diff said uncompressed they were the
> same.
Your user has an odd definition of "faster" and "slower". I don't know
what would make the user think that storing the entire 160,801 element
array in memory TWICE would be faster than just printing what's needed
when it's needed.
In the first algorithm, the user is storing one large string, and each
time through the loop, appending to that string. Towards the end, this
means storing over (160,000 x 32) bytes in a single scalar, and asking
perl to append to the end of that string. Then finally you ask perl to
make one absurdly large I/O access.
In the second algorithm, you're simply printing 32 bytes repeatedly.
Neither of those ways are especially good perl code, of course. The
first would be better written:
my $str = join (',', @judy);
open my $out, '>', $output_file or die "Can't open output: $!";
print $out $str;
close $out;
The second would be better written
open my $out, '>', $output_file or die "Can't open output: $!";
{
local $, = ',';
print $out @judy;
}
close $out;
I would suggest your user use the Benchmark module to determine which of
these is actually faster.
Paul Lalli
------------------------------
Date: 29 Mar 2005 19:28:56 GMT
From: xhoster@gmail.com
Subject: Re: Performance question
Message-Id: <20050329142856.304$6h@newsreader.com>
Dave Sill <MaxFreedom@sws5.ornl.gov> wrote:
> One of my users made the following observation. I'm only an
> occasional, lightweight Perl user, so I can't explain what he's
> seeing. Can anyone shed some light on it? H/W is a pretty large/fast
> Dell server running RHEL 3.
>
> ----
> I manufactured a 401x401 [ linearly =160801 element] array [@judy]
> each element having string values like
>
> 01000000001110000000000000000001
>
> I needed to make a comma delimited ascii file of this data.
>
> I decided a single IO write of a string would be the fastest, so i
> made a string
> $str="";
> foreach $i(0..$#judy-1)
> {
> $str=$str."$judy[$i],"
This has to copy the contents of $str (which towards the end is quite
huge) each time through the loop. Maybe even twice. Using:
$str.="judy[$i],";
is tremendously faster, because it just tacks something onto the end of the
string when possible, rather than copying the entire string each time. (I
would have thought perl would have optimized the first into the second, but
apparently it doesn't. Maybe such optimization would cause overloading to
break.)
> }
> $str=$str."$judy[$#judy]";
Of course, I do have to wonder why you just don't use
$str = join ",", @judy;
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 29 Mar 2005 19:42:45 GMT
From: xhoster@gmail.com
Subject: Re: Performance question
Message-Id: <20050329144245.517$cC@newsreader.com>
Paul Lalli <mritty@gmail.com> wrote:
>
> In the first algorithm, the user is storing one large string, and each
> time through the loop, appending to that string. Towards the end, this
> means storing over (160,000 x 32) bytes in a single scalar, and asking
> perl to append to the end of that string.
If he were doing that, it wouldn't be so bad. Perl is pretty good at
handling that. But he isn't asking Perl to append to the end of that
string, but rather to copy that string and then append to the end of that
copy.
> Then finally you ask perl to
> make one absurdly large I/O access.
There is nothing absurd about the size of the I/O.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 29 Mar 2005 14:08:25 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: perl update - what about the modules?
Message-Id: <AtSdnSxX68U2OtTfRVn-sQ@adelphia.com>
Karl Aminov wrote:
> alythh@netscape.net wrote in message
> news:<1112094326.260378.28700@l41g2000cwc.googlegroups.com>...
>> I am running a faithful RedHat7.3 box - so my Perl version is v5.6.1.
>> I was thinking about updating to the current Perl version
>> (5.8.something, right?)
> A rude, but working solution is to include the old library path in
> your perl script:
>
> #! /usr/bin/perl
> use lib '/usr/lib/perl5/site_perl/5.6.1';
That can only be considered "working" with some major caveats. He's asking
about a major version upgrade from 5.6 to 5.8, so XS modules that have been
compiled for the old version will *not* work with the newer one. For XS
modules, the trick you're talking about only works for minor upgrades, like
from 5.8.1 to 5.8.6.
It's less of an issue with pure Perl modules.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 29 Mar 2005 12:19:38 -0800
From: ravenslay3r@gmail.com
Subject: Re: perl5.8.6 won't install on FreeBSD5.3
Message-Id: <1112127578.651344.268810@f14g2000cwb.googlegroups.com>
ok, i dont' understand how or why but the instructions on freshports
did work the last time i tried them... sigh
nope, didn't read /usr/ports/UPDATING
but i will. thanks.
------------------------------
Date: 29 Mar 2005 14:56:56 -0800
From: k9boy@hotmail.com
Subject: problem with old version of (Active) Perl
Message-Id: <1112137016.521350.95120@g14g2000cwa.googlegroups.com>
I wrote the code on my local machine, which runs ActivePerl 5.8. The
machine that will use this code runs ActivePerl 5.6. Part of the code
opens up a large file (>85MB), substitute string values line by line,
then writes it to another file. Surprisingly, this part of the code
quits after reading about 10MB when running on version ActivePerl 5.6.
This alone causes the problem:
$origfile = "C:\\dir\\file.a";
$newfile = "C:\\dir\\file.b";
open INF, $origfile or die $!;
open OUTF, ">$newfile" or die $!;
while(<INF>) {
print OUTF $_;
}
close INF;
close OUTF;
I can't get Perl upgraded without quite some difficultly, so does
anyone know what might be causing this problem?
Thanks in advance.
------------------------------
Date: 29 Mar 2005 14:41:22 -0800
From: codingalex@yahoo.com
Subject: using Perl to insert footer into PDF files?
Message-Id: <1112136082.166127.110350@z14g2000cwz.googlegroups.com>
I'm a little new at PDF manipulation in Perl and I'm not completely
convinced that what I want to do is even possible. Basically what i
want to do is take a multi-page PDF file and insert a footer onto the
bottom of every page along with sequential page numbers. I've been
tinkering with the PDF::API2 module, which looks promising but which
appears to be a little slim on documentation. Can someone point me in
the right direction on this?
Thanks a lot,
Alex
------------------------------
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 7924
***************************************