From wells at cedarnet.org Sat Mar 13 11:43:28 2004 From: wells at cedarnet.org (Stephen D. Wells) Date: Mon Aug 2 21:27:33 2004 Subject: [Cedarvalley] Perl Impossibility? Message-ID: <1079199808.17910.53.camel@localhost.localdomain> Have a problem that has been drudged up from the last century.... http://groups.google.com/groups?q=readline+socket+group:comp.lang.perl.modules&hl=en&lr=&ie=UTF-8&oe=UTF-8&group=comp.lang.perl.modules&c2coff=1&safe=off&selm=3706E49B.5AD0C8A%40cedarnet.org&rnum=3 Unfortunately the code as posted doesn't exactly compile under 'use strict' you need to add: my $server_port = 6666; above the my $password line. Copy the code to a file and run it... in another window try: telnet 0 6666 and enter a password... The noecho feature doesn't seem to kick in -- the client can still see the password. I can't believe that this is impossible to write in perl... Anyone have a suggestion? TIA, STEVE -- Stephen D. Wells From thompson at cns.uni.edu Tue Mar 16 09:36:44 2004 From: thompson at cns.uni.edu (Aaron Thompson) Date: Mon Aug 2 21:27:33 2004 Subject: [Cedarvalley] Perl Impossibility? In-Reply-To: <1079199808.17910.53.camel@localhost.localdomain> References: <1079199808.17910.53.camel@localhost.localdomain> Message-ID: <20040316153644.GL7288@faculty.cns.uni.edu> Steve, I don't know if this will help - its a little UNIX-centric. Its from a password updating script I wrote a while back. ---- print "enter your CNS Password: "; system("stty -echo"); chomp($passwd = <>); system("stty echo"); print "\nVerifying user ... \n"; ref($pamh = new Authen::PAM($pamsvc, $uname, \&MyConvFunc)) || die "Error code $pamh during PAM init!"; $res = $pamh->pam_set_item(PAM_TTY(), $tty_name); $res = $pamh->pam_authenticate; while(!($res == PAM_SUCCESS()) ){ if($tryCount < $MAXTRY){ print " failed.\n"; print "enter your CNS Password: "; system("stty -echo"); chomp($passwd = <>); system("stty echo"); print "\nVerifying user ... \n"; $res = $pamh->pam_authenticate; $tryCount++; } ---- Hope this helps. @ On Sat, Mar 13, 2004 at 11:43:28AM -0600, Stephen D. Wells wrote: > Have a problem that has been drudged up from the last century.... > > http://groups.google.com/groups?q=readline+socket+group:comp.lang.perl.modules&hl=en&lr=&ie=UTF-8&oe=UTF-8&group=comp.lang.perl.modules&c2coff=1&safe=off&selm=3706E49B.5AD0C8A%40cedarnet.org&rnum=3 > Unfortunately the code as posted doesn't exactly compile under 'use > strict' you need to add: > > my $server_port = 6666; > > above the my $password line. > > Copy the code to a file and run it... in another window try: > > telnet 0 6666 > > and enter a password... > > The noecho feature doesn't seem to kick in -- the client can still see > the password. I can't believe that this is impossible to write in > perl... Anyone have a suggestion? > > TIA, > STEVE > -- > Stephen D. Wells > > _______________________________________________ > Cedarvalley mailing list > Cedarvalley@mail.pm.org > http://mail.pm.org/mailman/listinfo/cedarvalley -- Aaron Thompson Unix Systems Administrator, College of Natural Science http://www.cns.uni.edu/~thompson/ University of Northern Iowa "If there's anything more important than my ego around, I want it caught and shot now." -Douglas Adams From wells at cedarnet.org Wed Mar 31 12:24:53 2004 From: wells at cedarnet.org (Stephen D. Wells) Date: Mon Aug 2 21:27:33 2004 Subject: [Cedarvalley] upload problem In-Reply-To: <20040203024421.GA11241@faculty.cns.uni.edu> References: <20031211165413.GW28940@faculty.cns.uni.edu> <20031211195206.GB28940@faculty.cns.uni.edu> <1071681026.21855.83.camel@localhost.localdomain> <20031217171535.GA10878@faculty.cns.uni.edu> <1071698938.21859.382.camel@localhost.localdomain> <20031219154229.GF10878@faculty.cns.uni.edu> <1071859860.7644.6.camel@localhost.localdomain> <20040203024421.GA11241@faculty.cns.uni.edu> Message-ID: <1080757493.5933.84.camel@localhost.localdomain> You probably have already seen this but I just stumbled across it, liked it and thought I'd pass it along... * A one-liner for checking to see if a value exists in a list: if ({ map { $_ => 1 } qw(apple orange lemon) }->{apple}) { # do stuff } Here's what's happening: We are creating an anonymous hash of the values in the list: { apple => 1, orange => 1, lemon => 1 } Then checking to see if that hash exists { apple => 1, orange => 1, lemon => 1 }->{apple} # should return 1 This replaces code that you see all the time like this: my $found = 0; { for (qw(apple orange lemon)) { next unless $_ eq "apple"; $found++; last; } } if ($found) { # do stuff } * more complex example I've been using the Class::DBI module for some extranet reporting software I created and have a table structure like so: user user_access access ---- ----------- ------ id id id name user_id name pass access_id see Class::DBI for how to build your Classes in one line I can check to see if this user is in the 'admin' group and allow my administration functions to override the user functions using the following: if ({ map { $_->access_id->name => 1 } (EX::DBI::User->accesses)}->{'admin'}) { require "EX/Admin.pm"; push (@ISA, 'EX::Admin'); } I was kinda' impressed with the fact there it's such a compact piece of code. Thoughts? STEVE From tim at timschoenfelder.com Wed Mar 31 13:11:54 2004 From: tim at timschoenfelder.com (Tim Schoenfelder) Date: Mon Aug 2 21:27:33 2004 Subject: [Cedarvalley] upload problem In-Reply-To: <1080757493.5933.84.camel@localhost.localdomain> References: <20031211165413.GW28940@faculty.cns.uni.edu> <20031211195206.GB28940@faculty.cns.uni.edu> <1071681026.21855.83.camel@localhost.localdomain> <20031217171535.GA10878@faculty.cns.uni.edu> <1071698938.21859.382.camel@localhost.localdomain> <20031219154229.GF10878@faculty.cns.uni.edu> <1071859860.7644.6.camel@localhost.localdomain> <20040203024421.GA11241@faculty.cns.uni.edu> <1080757493.5933.84.camel@localhost.localdomain> Message-ID: <406B17FA.6040201@timschoenfelder.com> Stephen D. Wells wrote: >You probably have already seen this but I just stumbled across it, liked >it and thought I'd pass it along... > >* A one-liner for checking to see if a value exists in a list: >if ({ map { $_ => 1 } qw(apple orange lemon) }->{apple}) { > # do stuff >} > >Here's what's happening: > >We are creating an anonymous hash of the values in the list: > { apple => 1, orange => 1, lemon => 1 } > >Then checking to see if that hash exists > { apple => 1, orange => 1, lemon => 1 }->{apple} # should return 1 > >This replaces code that you see all the time like this: >my $found = 0; >{ > for (qw(apple orange lemon)) { > next unless $_ eq "apple"; > $found++; > last; > } >} >if ($found) { > # do stuff >} > >* more complex example > >I've been using the Class::DBI module for some extranet reporting >software I created and have a table structure like so: > >user user_access access >---- ----------- ------ >id id id >name user_id name >pass access_id > >see Class::DBI for how to build your Classes > >in one line I can check to see if this user is in the 'admin' group and >allow my administration functions to override the user functions using >the following: > >if ({ map { $_->access_id->name => 1 } > (EX::DBI::User->accesses)}->{'admin'}) { > require "EX/Admin.pm"; > push (@ISA, 'EX::Admin'); >} > >I was kinda' impressed with the fact there it's such a compact piece of >code. > >Thoughts? > > Nice! Really Nice! -- Tim Schoenfelder http://timschoenfelder.com From thompson at cns.uni.edu Wed Mar 31 13:21:30 2004 From: thompson at cns.uni.edu (Aaron Thompson) Date: Mon Aug 2 21:27:33 2004 Subject: [Cedarvalley] upload problem In-Reply-To: <1080757493.5933.84.camel@localhost.localdomain> References: <20031211165413.GW28940@faculty.cns.uni.edu> <20031211195206.GB28940@faculty.cns.uni.edu> <1071681026.21855.83.camel@localhost.localdomain> <20031217171535.GA10878@faculty.cns.uni.edu> <1071698938.21859.382.camel@localhost.localdomain> <20031219154229.GF10878@faculty.cns.uni.edu> <1071859860.7644.6.camel@localhost.localdomain> <20040203024421.GA11241@faculty.cns.uni.edu> <1080757493.5933.84.camel@localhost.localdomain> Message-ID: <20040331192130.GH17979@faculty.cns.uni.edu> Nice, I ran into to places this would have been useful with lists in the last week - instead I ended up using a hash: my %groups; for my $group (split(" ",`id -nG $self->{_user_name}`)){$groups{$group}++;} ... if($groups{'valid_group'}){ #I'm a group memeber }#fi Your line could have been used instead: my @groups = split(" ",`id -nG $self->{_user_name}`); ... if({ map { $_ => 1 } @groups }->{'valid_group'}){ #I'm a group member } @ On Wed, Mar 31, 2004 at 12:24:53PM -0600, Stephen D. Wells wrote: > You probably have already seen this but I just stumbled across it, liked > it and thought I'd pass it along... > > * A one-liner for checking to see if a value exists in a list: > if ({ map { $_ => 1 } qw(apple orange lemon) }->{apple}) { > # do stuff > } > > Here's what's happening: > > We are creating an anonymous hash of the values in the list: > { apple => 1, orange => 1, lemon => 1 } > > Then checking to see if that hash exists > { apple => 1, orange => 1, lemon => 1 }->{apple} # should return 1 > > This replaces code that you see all the time like this: > my $found = 0; > { > for (qw(apple orange lemon)) { > next unless $_ eq "apple"; > $found++; > last; > } > } > if ($found) { > # do stuff > } > > * more complex example > > I've been using the Class::DBI module for some extranet reporting > software I created and have a table structure like so: > > user user_access access > ---- ----------- ------ > id id id > name user_id name > pass access_id > > see Class::DBI for how to build your Classes > > in one line I can check to see if this user is in the 'admin' group and > allow my administration functions to override the user functions using > the following: > > if ({ map { $_->access_id->name => 1 } > (EX::DBI::User->accesses)}->{'admin'}) { > require "EX/Admin.pm"; > push (@ISA, 'EX::Admin'); > } > > I was kinda' impressed with the fact there it's such a compact piece of > code. > > Thoughts? > STEVE > > _______________________________________________ > Cedarvalley mailing list > Cedarvalley@mail.pm.org > http://mail.pm.org/mailman/listinfo/cedarvalley -- Aaron Thompson Unix Systems Administrator, College of Natural Science http://www.cns.uni.edu/~thompson/ University of Northern Iowa "If there's anything more important than my ego around, I want it caught and shot now." -Douglas Adams From wells at cedarnet.org Wed Mar 31 14:18:53 2004 From: wells at cedarnet.org (Stephen D. Wells) Date: Mon Aug 2 21:27:33 2004 Subject: [Cedarvalley] upload problem In-Reply-To: <20040331192130.GH17979@faculty.cns.uni.edu> References: <20031211165413.GW28940@faculty.cns.uni.edu> <20031211195206.GB28940@faculty.cns.uni.edu> <1071681026.21855.83.camel@localhost.localdomain> <20031217171535.GA10878@faculty.cns.uni.edu> <1071698938.21859.382.camel@localhost.localdomain> <20031219154229.GF10878@faculty.cns.uni.edu> <1071859860.7644.6.camel@localhost.localdomain> <20040203024421.GA11241@faculty.cns.uni.edu> <1080757493.5933.84.camel@localhost.localdomain> <20040331192130.GH17979@faculty.cns.uni.edu> Message-ID: <1080764333.5934.139.camel@localhost.localdomain> Or even... if({ map { $_ => 1 } split(" ",`id -nG $self->{_user_name}`) }->{valid_group}) { # I'm valid } :) STEVE On Wed, 2004-03-31 at 13:21, Aaron Thompson wrote: > Nice, I ran into to places this would have been useful with lists > in the last week - instead I ended up using a hash: > > my %groups; > for my $group (split(" ",`id -nG $self->{_user_name}`)){$groups{$group}++;} > ... > > if($groups{'valid_group'}){ > #I'm a group memeber > }#fi > > Your line could have been used instead: > > my @groups = split(" ",`id -nG $self->{_user_name}`); > ... > if({ map { $_ => 1 } @groups }->{'valid_group'}){ > #I'm a group member > } > > @ > > On Wed, Mar 31, 2004 at 12:24:53PM -0600, Stephen D. Wells wrote: > > You probably have already seen this but I just stumbled across it, liked > > it and thought I'd pass it along... > > > > * A one-liner for checking to see if a value exists in a list: > > if ({ map { $_ => 1 } qw(apple orange lemon) }->{apple}) { > > # do stuff > > } > > > > Here's what's happening: > > > > We are creating an anonymous hash of the values in the list: > > { apple => 1, orange => 1, lemon => 1 } > > > > Then checking to see if that hash exists > > { apple => 1, orange => 1, lemon => 1 }->{apple} # should return 1 > > > > This replaces code that you see all the time like this: > > my $found = 0; > > { > > for (qw(apple orange lemon)) { > > next unless $_ eq "apple"; > > $found++; > > last; > > } > > } > > if ($found) { > > # do stuff > > } > > > > * more complex example > > > > I've been using the Class::DBI module for some extranet reporting > > software I created and have a table structure like so: > > > > user user_access access > > ---- ----------- ------ > > id id id > > name user_id name > > pass access_id > > > > see Class::DBI for how to build your Classes > > > > in one line I can check to see if this user is in the 'admin' group and > > allow my administration functions to override the user functions using > > the following: > > > > if ({ map { $_->access_id->name => 1 } > > (EX::DBI::User->accesses)}->{'admin'}) { > > require "EX/Admin.pm"; > > push (@ISA, 'EX::Admin'); > > } > > > > I was kinda' impressed with the fact there it's such a compact piece of > > code. > > > > Thoughts? > > STEVE > > > > _______________________________________________ > > Cedarvalley mailing list > > Cedarvalley@mail.pm.org > > http://mail.pm.org/mailman/listinfo/cedarvalley -- Stephen D. Wells