[19367] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1562 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 18 21:05:31 2001

Date: Sat, 18 Aug 2001 18:05:06 -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: <998183106-v10-i1562@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 18 Aug 2001     Volume: 10 Number: 1562

Today's topics:
    Re: Copy file in Perl <godzilla@stomp.stomp.tokyo>
        Extracting attachments from e-mail <mail4donpro@home.com>
    Re: Extracting attachments from e-mail <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Extracting attachments from e-mail <mail4donpro@home.com>
    Re: Extracting attachments from e-mail <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Extracting attachments from e-mail <bcaligari@fireforged.com>
    Re: Extracting attachments from e-mail <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Extracting attachments from e-mail <mail4donpro@home.com>
        FAQ: How can I hope to use regular expressions without  <faq@denver.pm.org>
        manipulating constant lists with map() (Tassilo v. Parseval)
    Re: manipulating constant lists with map() (John J. Trammell)
    Re: manipulating constant lists with map() <Tassilo.Parseval@post.rwth-aachen.de>
    Re: manipulating constant lists with map() <bcaligari@fireforged.com>
    Re: manipulating constant lists with map() <bcaligari@fireforged.com>
    Re: manipulating constant lists with map() <Tassilo.Parseval@post.rwth-aachen.de>
    Re: NT4  fullname to username (John)
    Re: select doesn't detect pipe close <uri@sysarch.com>
    Re: This is not a question ... call me slow if you like <neil@franklin.ch.remove>
    Re: This is not a question ... call me slow if you like (Martien Verbruggen)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 18 Aug 2001 15:32:22 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Copy file in Perl
Message-Id: <3B7EECF6.35FC3F8F@stomp.stomp.tokyo>

Philip Taylor wrote:

> Godzilla! wrote:


(snippage not noted by Taylor - context deliberately changed by Taylor)


> >Should your system not support Perl generated system
> >calls, you may use a classic Perl 4 style method which
> >is significantly faster and more efficient than this
> >typical Copy & Paste Baby Perl 5 Cargo Cult method above:

(snipped standard code)

> In DOS, you ought to run binmode on both the files in case they're
> binary files, unless you're certain that they're not going to be.

Irrelevant. The originating author does not specify any
details about files. Additionally he displays a skill level
which is not indicative of understanding this difference 
between a pure ASCII file and a binary file. It is highly
illogical to add confusion to his lack of Perl skills; he
is in no position to even write code like this. You will
note I commented just such; he needs to learn Perl.

 
> On a 3-byte file, I get similar results to yours (i.e. open/print
> quicker than File::Copy). But on a 1 megabyte file (20,000 lines of 48
> "a"s followed by "\r\n") I get:

(snipped)
 
> (the `copy ...` method tries to access my floppy drive every time it
> runs the command, so I cannot include it in the test)

Your system is incorrectly configured or you wrote bad code.

 
> Testing with different sized files shows that the open/print method is
> faster only for files less than about 1,500 bytes in size.
> Any HTML files with useful content will be far larger than that, making
> File::Copy the best option.

Clearly your Perl skills are such you are unaware the File Copy
module employs a system write methodology providing an advantage
for large files. My method of direct access to a system copy
command is significantly quicker and significantly more efficient
than the File Copy module.

My test results show a transition point significantly different
than what you claim.

Use of the File Copy module is distinctly not the best option.
My previous article includes direct system access for a copy.
This is the best option, evidenced by my benchmark testing.

It is a display of dubious intelligence and a display of a
lack of acceptable Perl skills to taunt module usage as the
only option, rather than offer a number of options, as I do.
However, I am not a Perl 5 Cargo Cultist. I am a programmer.



Godzilla!


------------------------------

Date: Sat, 18 Aug 2001 22:54:45 GMT
From: "Don" <mail4donpro@home.com>
Subject: Extracting attachments from e-mail
Message-Id: <VmCf7.45933$281.7727978@news4.rdc1.on.home.com>

Hi,

I am using NET::POP3 to read and extract e-mail from a POP3 server.  I works great.  However, now I wish to also extract attachment
files if they exists and save them in a specified folder on the web server.  Is this possible in PERL?

Thanks,
Don




------------------------------

Date: Sun, 19 Aug 2001 01:00:07 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Extracting attachments from e-mail
Message-Id: <3B7EF377.4010502@post.rwth-aachen.de>

Don wrote:

> Hi,
> 
> I am using NET::POP3 to read and extract e-mail from a POP3 server.  I works great.  However, now I wish to also extract attachment
> files if they exists and save them in a specified folder on the web server.  Is this possible in PERL?

Yes. For that I'd (currently) use Mail::MboxParser that has explicit 
methods to deal with binary attachements and works around some 
misbehaviours of MIME::Entity that one would usually have to use for 
that. There is actually an example script included in the distribution 
that does exactly that and that can most easily be modified to fit your 
needs.


Tassilo

PS: comp.lang.perl does not exist.
-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



------------------------------

Date: Sat, 18 Aug 2001 23:18:55 GMT
From: "Don" <mail4donpro@home.com>
Subject: Re: Extracting attachments from e-mail
Message-Id: <zJCf7.46174$281.7756990@news4.rdc1.on.home.com>

Thanks for your response.  However, I cannot seem to find this module on CPAN web site module list.  Would you know where it is
located?

Thanks,
Don

"Tassilo von Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote in message news:3B7EF377.4010502@post.rwth-aachen.de...
> Don wrote:
>
> > Hi,
> >
> > I am using NET::POP3 to read and extract e-mail from a POP3 server.  I works great.  However, now I wish to also extract
attachment
> > files if they exists and save them in a specified folder on the web server.  Is this possible in PERL?
>
> Yes. For that I'd (currently) use Mail::MboxParser that has explicit
> methods to deal with binary attachements and works around some
> misbehaviours of MIME::Entity that one would usually have to use for
> that. There is actually an example script included in the distribution
> that does exactly that and that can most easily be modified to fit your
> needs.
>
>
> Tassilo
>
> PS: comp.lang.perl does not exist.
> --
> $a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
> [1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
> (chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
> ),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
> 10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
> ord(chr($h->{$_}))))};
>




------------------------------

Date: Sun, 19 Aug 2001 01:25:03 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Extracting attachments from e-mail
Message-Id: <3B7EF94F.1060301@post.rwth-aachen.de>

Don wrote:

> Thanks for your response.  However, I cannot seem to find this module on CPAN web site module list.  Would you know where it is
> located?

Is is here: http://search.cpan.org/search?dist=Mail-MboxParser

Tassilo--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



------------------------------

Date: Sun, 19 Aug 2001 01:23:40 -0000
From: "Brendon Caligari" <bcaligari@fireforged.com>
Subject: Re: Extracting attachments from e-mail
Message-Id: <9lmt2l01gc5@enews2.newsguy.com>


"Don" <mail4donpro@home.com> wrote in message
news:VmCf7.45933$281.7727978@news4.rdc1.on.home.com...
> Hi,
>
> I am using NET::POP3 to read and extract e-mail from a POP3 server.  I
works great.  However, now I wish to also extract attachment
> files if they exists and save them in a specified folder on the web
server.  Is this possible in PERL?
>
> Thanks,
> Don
>

I presume that the emails you download are in MIME format.  There are
modules on cpan (eg, MIME::Base64, and others) which help you parse
messages, encode and decode attachments, etc.

B




------------------------------

Date: Sun, 19 Aug 2001 01:52:02 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Extracting attachments from e-mail
Message-Id: <3B7EFFA2.2070304@post.rwth-aachen.de>

Brendon Caligari wrote:

> "Don" <mail4donpro@home.com> wrote in message
> news:VmCf7.45933$281.7727978@news4.rdc1.on.home.com...
> 
>>Hi,
>>
>>I am using NET::POP3 to read and extract e-mail from a POP3 server.  I
>>
> works great.  However, now I wish to also extract attachment
> 
>>files if they exists and save them in a specified folder on the web
>>
> server.  Is this possible in PERL?
> 
>>Thanks,
>>Don
>>
>>
> 
> I presume that the emails you download are in MIME format.  There are
> modules on cpan (eg, MIME::Base64, and others) which help you parse
> messages, encode and decode attachments, etc.

But that's hard to achieve. This MIME-module does fancy things if the 
mail is not exactly formated in the way that the module expects it. 
Eventually it boils down to eval()ing practically any call to the 
provided methods or it'll bail out. MIME::Tools is quite fickle.


Tassilo

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



------------------------------

Date: Sun, 19 Aug 2001 00:01:39 GMT
From: "Don" <mail4donpro@home.com>
Subject: Re: Extracting attachments from e-mail
Message-Id: <DlDf7.46422$281.7810751@news4.rdc1.on.home.com>

Thanks!!!

"Tassilo von Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote in message news:3B7EF94F.1060301@post.rwth-aachen.de...
> Don wrote:
>
> > Thanks for your response.  However, I cannot seem to find this module on CPAN web site module list.  Would you know where it is
> > located?
>
> Is is here: http://search.cpan.org/search?dist=Mail-MboxParser
>
> Tassilo--
> $a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
> [1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
> (chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
> ),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
> 10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
> ord(chr($h->{$_}))))};
>




------------------------------

Date: Sun, 19 Aug 2001 00:17:02 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How can I hope to use regular expressions without creating illegible and unmaintainable code?
Message-Id: <2ADf7.240$V3.171380224@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  How can I hope to use regular expressions without creating illegible and unmaintainable code?

    Three techniques can make regular expressions maintainable and
    understandable.

    Comments Outside the Regex
        Describe what you're doing and how you're doing it, using normal
        Perl comments.

            # turn the line into the first word, a colon, and the
            # number of characters on the rest of the line
            s/^(\w+)(.*)/ lc($1) . ":" . length($2) /meg;

    Comments Inside the Regex
        The "/x" modifier causes whitespace to be ignored in a regex pattern
        (except in a character class), and also allows you to use normal
        comments there, too. As you can imagine, whitespace and comments
        help a lot.

        "/x" lets you turn this:

            s{<(?:[^>'"]*|".*?"|'.*?')+>}{}gs;

        into this:

            s{ <                    # opening angle bracket
                (?:                 # Non-backreffing grouping paren
                     [^>'"] *       # 0 or more things that are neither > nor ' nor "
                        |           #    or else
                     ".*?"          # a section between double quotes (stingy match)
                        |           #    or else
                     '.*?'          # a section between single quotes (stingy match)
                ) +                 #   all occurring one or more times
               >                    # closing angle bracket
            }{}gsx;                 # replace with nothing, i.e. delete

        It's still not quite so clear as prose, but it is very useful for
        describing the meaning of each part of the pattern.

    Different Delimiters
        While we normally think of patterns as being delimited with "/"
        characters, they can be delimited by almost any character. the
        perlre manpage describes this. For example, the "s///" above uses
        braces as delimiters. Selecting another delimiter can avoid quoting
        the delimiter within the pattern:

            s/\/usr\/local/\/usr\/share/g;      # bad delimiter choice
            s#/usr/local#/usr/share#g;          # better

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           06.01
-- 
    This space intentionally left blank


------------------------------

Date: 18 Aug 2001 22:41:33 GMT
From: Tassilo.Parseval@post.rwth-aachen.de (Tassilo v. Parseval)
Subject: manipulating constant lists with map()
Message-Id: <9lmqut$eb2$1@nets3.rz.RWTH-Aachen.DE>

Hi,

I had been toying around a little with the map-function and encountered
some behaviour that I don't fully understand. Here are some examples:

1)
ethan@ethan:~$ perl
@f = map { s/\n$// } `find . -name "*.pdf"`;
print @f, "\n";
^D
1111111111111111111111111111111111111111111111111111111111111111111

2)
ethan@ethan:~$ perl
@f = map { $_ =~ s/\n$// } `find . -name "*.pdf"`;
print @f, "\n";
^D
1111111111111111111111111111111111111111111111111111111111111111111

3)
ethan@ethan:~$ perl
@f = map { $_++ } qw(1 2 3);
print @f;
^D
Modification of a read-only value attempted at - line 1.

I have basically two questions about the three above examples:

Why does 3) result in an error while 2) works? I understand that
`file...` is also a read-only value.

Secondly, why does 1) not return me a list (@f) in which each element is
one line returned by "find" without the trailing newline? I tried
several things to manipulate a slurped list returned by backticks on the
fly. Obviously this is not possible.

I'd be very grateful for someone throwing light on this,
Tassilo
-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



------------------------------

Date: 18 Aug 2001 23:06:10 GMT
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: manipulating constant lists with map()
Message-Id: <slrn9nucd4.9mr.trammell@haqq.hypersloth.net>

On 18 Aug 2001 22:41:33 GMT, Tassilo v. Parseval wrote:
[snip]

Hope these examples shed some light...

[ haqq ~ ] perl
@f = map { s/\n$//; $_ } `find . -name "*.pdf"`;
print @f, "\n";
 ./Lit/notes.pdf
[ haqq ~ ] perl
@f = map { $_ + 1 } qw[ 1 2 3 ]; 
print @f, "\n";
234
[ haqq ~ ] 

-- 
Torg: Quick, blow up that shiny thing!
Kiki: Ooooh!


------------------------------

Date: Sun, 19 Aug 2001 01:14:12 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: manipulating constant lists with map()
Message-Id: <3B7EF6C4.80604@post.rwth-aachen.de>

John J. Trammell wrote:
> On 18 Aug 2001 22:41:33 GMT, Tassilo v. Parseval wrote:
> [snip]
> 
> Hope these examples shed some light...

Hmmh, partly. As for the first, that's at least a way to do it.
But this still does not explain this thing with manipulating a read-only 
value. This map { $++ } was just meant to be an example.
It was sort of a theoretical question.

Tassilo--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



------------------------------

Date: Sun, 19 Aug 2001 01:17:20 -0000
From: "Brendon Caligari" <bcaligari@fireforged.com>
Subject: Re: manipulating constant lists with map()
Message-Id: <9lmsmo01f7l@enews2.newsguy.com>


"Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote in
message news:9lmqut$eb2$1@nets3.rz.RWTH-Aachen.DE...
> Hi,
>
> I had been toying around a little with the map-function and encountered
> some behaviour that I don't fully understand. Here are some examples:
>
> 1)
> ethan@ethan:~$ perl
> @f = map { s/\n$// } `find . -name "*.pdf"`;
> print @f, "\n";
> ^D


The value of the block is the value of the last expression evaluated, in
your case, '1', being
the number of successful substitutions.

try this

my @a = qw/zero one two three/;
my @b = map { s/e/E/g } @a;
print @b, "\n";

You might want something more on the lines of
 @f = map { s/\n$//; $_ } `find . -name "*.pdf"`;

B.






------------------------------

Date: Sun, 19 Aug 2001 01:21:14 -0000
From: "Brendon Caligari" <bcaligari@fireforged.com>
Subject: Re: manipulating constant lists with map()
Message-Id: <9lmsu201ftk@enews2.newsguy.com>


"Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote in
message news:9lmqut$eb2$1@nets3.rz.RWTH-Aachen.DE...
> 3)
> ethan@ethan:~$ perl
> @f = map { $_++ } qw(1 2 3);
> print @f;
> ^D
> Modification of a read-only value attempted at - line 1.

$_ in map is an alias to the list value, in your case the list is not made
up
of variables, and hence can't be modified

B.




------------------------------

Date: Sun, 19 Aug 2001 01:39:45 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: manipulating constant lists with map()
Message-Id: <3B7EFCC1.9010503@post.rwth-aachen.de>

Brendon Caligari wrote:

> "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote in
> message news:9lmqut$eb2$1@nets3.rz.RWTH-Aachen.DE...
> 
>>3)
>>ethan@ethan:~$ perl
>>@f = map { $_++ } qw(1 2 3);
>>print @f;
>>^D
>>Modification of a read-only value attempted at - line 1.
>>
> 
> $_ in map is an alias to the list value, in your case the list is not made
> up
> of variables, and hence can't be modified


Yes, that's understood. But this still does not explain why it obviously 
can be modified if the list is generated by a backticks command. My 
problem is that I don't see a difference in qw(1 2 3) and for example 
`ls`. Both seem pretty read-only to me yet it only failed with qw(1 2 3).

Tassilo


-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



------------------------------

Date: 18 Aug 2001 17:58:20 -0700
From: jouell@zdnetmail.com (John)
Subject: Re: NT4  fullname to username
Message-Id: <7e8915d2.0108181658.5af48a8f@posting.google.com>

jouell@zdnetmail.com (John) wrote in message news:<7e8915d2.0108140956.14224863@posting.google.com>...
> Hello,
> 
>   I searched the newsgroups, perl modules I know of, but cannot find
> something that will return an NT4 username from a full name.
> Apparently, you can do this in C++, etc. though I'd to do it in perl,
> or maybe a resource kit util?
>   I know could run "net user /domain $username" and match the username
> to fullname, parsing the results through whole SAM basically, and set
> up a hash or something but that seems cumbersome, and if it's easier
> or done before, great.
> 
> Basically, I am to do function("full name") and have it return the
> username.
> Anyone? 
> 
> Thanks in advance,
> -john



Well, I can either do it the long way like I mentioned, or also use
the hyena software http://www.adkins-resource.com/, and export the
list to a CSV, remove what I don't want and have "full name";username
to what I want with.


-john


------------------------------

Date: Sat, 18 Aug 2001 22:15:43 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: select doesn't detect pipe close
Message-Id: <x7n14xhv5b.fsf@home.sysarch.com>

>>>>> "BG" == Benjamin Goldberg <goldbb2@earthlink.net> writes:

  BG> Ok: here's my rewritten code:
  BG> sub new {
  BG> 	my $proto = shift;
  BG> 	my $class = ref($proto) || $proto;
  BG> 	pipe my( $p2cr, $p2cw ) or die "pipe failed: $!";
  BG> 	pipe my( $c2pr, $c2pw ) or die "pipe failed: $!";
  BG> 	defined( my $pid = fork ) or die "fork failed: $!";
  BG> 	select((
  BG> 		select($p2cw), $|=1,
  BG> 		select($c2pw), $|=1,
  BG> 	)[0]);

better to use sysread and syswrite with pipes. there is usually no need
or want for buffering, so even setting $| slows it down as it will still
buffer i/o for you even if it autoflushes.

  BG> 	print STDERR "Forked: $$\n";
  BG> 	if( $pid ) {
  BG> # these two lines weren't here, so those two filehandles would
  BG> # have been closed implicitly with the return().

  BG> 		local $!;

why that?

  BG> 		close $_ for ($p2cr, $c2pw);

not sure if i like this or not. i understand it clearly enough but i
think it is too much of a trick to be clear to all potential readers. i
would stick with 2 simple closes.

		close $p2cr ;
		close $c2pw ;


  BG> 		return bless { pid => $pid,
  BG> 			reader => $c2pr, writer => $p2cw,
  BG> 			state => "unconnected", }, $class;
  BG> 	} else {

if the last statement in a block is return, next, last, etc. there is no
need for the else. just remove the else{} and it will work the same and
be much easier to read. also you preserve the supply of precious 'else's
and braces.

but this style has other positive effects beyond pixel/byte
conservation. it actually reduces the number of lines of code by 2 or so
lines (depending on the cuddling else style) and removes a level of
indent. and the old metric of about 1 bug per 100 lines of code is
fairly accurate.  the lower line count you get from perl's flexible
logic flow syntax is a major reason for using it (besides better
readibility).

  BG> Here's the daemon code (it hasn't changed any):
  BG> sub daemon {
  BG> 	my ($reader, $writer) = @_;
  BG> 	my ($dbi, $sth);
  BG> 	MAIN: while( 1 ) {
  BG> 		vec(my($rflags)="", fileno $reader, 1) = 1;
  BG> 		my $eflags = $rflags;
  BG> 		print STDERR "$$: entering select...\n";
  BG> 		select($rflags, undef, $eflags, undef)
  BG> 			or die "select: $!";
  BG> 		print STDERR "$$: select returned.\n";
  BG> 		if( !vec($rflags, fileno $reader, 1) ) {
  BG> 			print STDERR "$$: EOF seen, exiting\n";
  BG> 			exit;
  BG> 		}
  BG> The rest is ommited.  Anyway, select() here never returns, ever.

use IO::Select, Event.pm, POE or Stem for this stuff. why reinvent this
wheel one more time?

  BG> I'm not a programmer but I play one on TV...

you are giving me a headache. do you have any tiny little pills?

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs  --------------------------  http://jobs.perl.org


------------------------------

Date: 19 Aug 2001 00:28:50 +0200
From: Neil Franklin <neil@franklin.ch.remove>
Subject: Re: This is not a question ... call me slow if you like...
Message-Id: <6uvgjlroil.fsf@chonsp.franklin.ch>

posting this from alt.ascii-art...

Ilmari Karonen <iltzu@sci.invalid> writes:

> #!/usr/bin/perl
> y/~/\n/,s/\d+/$"x$&/eg,print for qw#~19/`.4/`.~18f3\\2,f2\\~6Gee1Brain,2|
> 4\\/-`\\2\\6The1same1thing1we1do~3what1do1you4i.2_\\';.,X1j6every1night,1
> Pinky.~5want1to1do4`:_\\1(2\\1\\',-.3Try1to1take1over~10tonight?3.'"`\\1a
> \\eY'1)3the1world!2_,.~21`._"\\`-'1`-/12.-;'2|~23/;-`._.-';\\.8,',"4|~21.
> '/3"'3|1`\\.-'""-/1/6j~19,/1/9i,-"8(2,/2/~16.-'1.f9.'12`"/2/~15/1,,/ffj\\
> 6/10.-"`.'-.'~14/1/_\\`--//)5\\1,--._1.-'_,-';1/~13f2".-"-._;'6`._1_.,-i;
> 1/_;1/~13`.,'3|;1\\10\\`\\_,/-'2\\'~14.'4l1\\1`.8/"\\1_1\\`2j~14f6:1`-'8`
> ._;."/`-'~14|6`.15,Z2\\~14l7j13.'/1-1\\`.~13.j.2.3<12(.'4.\\1\\f`.1|\\,'~
> 12,'1`.2\\1/1\\11`|6\\,'||-:j~10.'2.'\\3Y.2\\___......__\\1._3/`.||~2__..
> _,-"1.-"'"")2/'1,'1_10\\1|2/"-.`j""``---.._~4.'_.-'"5/1.("-'-"":\\8._)|_(
> __.1"'~3;.'9/-'---"".--"'7/,_,^-._1.)~3`:=.__.,itz1`---._.;'11""6""~##;-)

neil@chonsp 0:23:18 ~> cat > 1.pl
#!/usr/bin/perl
y/~/\n/,s/\d+/$"x$&/eg,print for qw#~19/`.4/`.~18f3\\2,f2\\~6Gee1Brain,2|
4\\/-`\\2\\6The1same1thing1we1do~3what1do1you4i.2_\\';.,X1j6every1night,1
Pinky.~5want1to1do4`:_\\1(2\\1\\',-.3Try1to1take1over~10tonight?3.'"`\\1a
\\eY'1)3the1world!2_,.~21`._"\\`-'1`-/12.-;'2|~23/;-`._.-';\\.8,',"4|~21.
'/3"'3|1`\\.-'""-/1/6j~19,/1/9i,-"8(2,/2/~16.-'1.f9.'12`"/2/~15/1,,/ffj\\
6/10.-"`.'-.'~14/1/_\\`--//)5\\1,--._1.-'_,-';1/~13f2".-"-._;'6`._1_.,-i;
1/_;1/~13`.,'3|;1\\10\\`\\_,/-'2\\'~14.'4l1\\1`.8/"\\1_1\\`2j~14f6:1`-'8`
_;."/`-'~14|6`.15,Z2\\~14l7j13.'/1-1\\`.~13.j.2.3<12(.'4.\\1\\f`.1|\\,'~
12,'1`.2\\1/1\\11`|6\\,'||-:j~10.'2.'\\3Y.2\\___......__\\1._3/`.||~2__..
_,-"1.-"'"")2/'1,'1_10\\1|2/"-.`j""``---.._~4.'_.-'"5/1.("-'-"":\\8._)|_(
__.1"'~3;.'9/-'---"".--"'7/,_,^-._1.)~3`:=.__.,itz1`---._.;'11""6""~##;-)
neil@chonsp 0:23:29 ~> perl 1.pl | wc
     27     150    1281
neil@chonsp 0:24:39 ~> wc 1.pl
     12      14     830 1.pl
neil@chonsp 0:24:43 ~>

So we get ASCII Art compression from 27 to 12 lines.

Just bad luck for those who do not have an perl interpreter to
decompress it.

And yes, nice Pinky and the Brain picture.


--
Neil Franklin, neil@franklin.ch.remove http://neil.franklin.ch/
Hacker, Unix Guru, El Eng HTL/BSc, Sysadmin, Archer, Roleplayer
- Intellectual Property is Intellectual Robbery


------------------------------

Date: Sun, 19 Aug 2001 10:46:17 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: This is not a question ... call me slow if you like...
Message-Id: <slrn9nu32o.3ga.mgjv@martien.heliotrope.home>

[Crosspost removed, since this probably only is interesting for
clp.misc again]

On 18 Aug 2001 20:45:35 GMT,
	Ilmari Karonen <iltzu@sci.invalid> wrote:
> 
> y/n/\n/,s/\d+/$"x$&/eg,print for qw'n4|9|21|3|n1\2||2|(_-<2_|4_`1|3\3_1\2_|3\3
> -_)2_|n\__/\_,_|___/\__|2\__,_|_|1_|\___/\__|_|1_|\___|_|nn4_1\9|3|14|n4__/1-_
> )2_|1|5\3_`1|2_|1!1/2-_)2_|n3_|1\___|_|2_|2_|1_|\__,_|\__|_i_\\\___|_|1)n45/n'
> 
> Hey, it even fits in three lines.

Under Perl 5.00503, yes. Under 5.6.0 it doesn't work.

Modification of a read-only value attempted at - line 1.

Still, very clever.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | This matter is best disposed of from
Commercial Dynamics Pty. Ltd.   | a great height, over water.
NSW, Australia                  | 


------------------------------

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 1562
***************************************


home help back first fref pref prev next nref lref last post