[27074] in Perl-Users-Digest
Perl-Users Digest, Issue: 8970 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 18 18:06:03 2006
Date: Sat, 18 Feb 2006 15:05:06 -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 Sat, 18 Feb 2006 Volume: 10 Number: 8970
Today's topics:
Re: Merging sparse arrays robic0
Re: perl menubased user interface (Jamie)
Re: Puzzled over rgexp <abigail@abigail.nl>
Re: Puzzled over rgexp robic0
Re: Puzzled over rgexp robic0
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 18 Feb 2006 14:51:51 -0800
From: robic0
Subject: Re: Merging sparse arrays
Message-Id: <519fv1lu41me9isao61m4pem573muj376q@4ax.com>
On 16 Feb 2006 07:24:37 GMT, Abigail <abigail@abigail.nl> wrote:
>Samwyse (samwyse@gmail.com) wrote on MMMMDLII September MCMXCIII in
><URL:news:0ZQIf.48417$dW3.26427@newssvr21.news.prodigy.com>:
>^^ Abigail wrote:
>^^ > Samwyse (samwyse@gmail.com) wrote on MMMMDLI September MCMXCIII in
>^^ > <URL:news:oxFIf.30309$F_3.6888@newssvr29.news.prodigy.net>:
>^^ > ** I have two arrays of equal length that contain null values. I want one
>^^ > ** array with fewer nulls.
>^^ >
>^^ > I'd avoid push, and do something like:
>^^ >
>^^ > my @t = map {defined $f [$_] ? $f [$_] : $g [$_]} 0 .. $#f;
>^^ >
>^^ > Or if you have the defined-or operator:
>^^ >
>^^ > my @t = map {$f [$_] // $g [$_]} 0 .. $#f;
>^^ >
>^^ > Note that I didn't use '$f [$_] || $g [$_]', as that will assign the
>^^ > value of @g if the corresponding value of @f is 0, or the empty string
>^^ > (both values are defined, but false).
>^^
>^^ In this case, the data is coming from a CSV file, so undefined values
>^^ are represented by empty strings, and zeros aren't a concern. In fact,
>^^ I was a bit surprised to find out that Text::ParseWords returns undef's
>^^ for empty fields; it caused a bit of trouble when I later used join(',',
>^^ ...) to write the merged arrays back to a file.
>^^
>^^ I was under the impression that defined-or was a Perl 6 feature. I
>^^ guess I need to check if my current interpreter supports it.
>
>
>Defined-or will be in 5.10, is currently in 5.9.3, and there's a patch
>available for 5.8.x.
>
>
>
I would like to understand your post but I can't. Can you explain your
'^^ >' syntax so I can try to percieve what it is that has been quoted.
Also, could you explain your bizzaro sig regex's as the change so that
someone might not think you have a fuckin "screw loose" ????
Thanks big gurl...
(the line just above will evolve just like your sig regex if you don't respond)
>Abigail
------------------------------
Date: Sat, 18 Feb 2006 13:10:51 GMT
From: nospam@geniegate.com (Jamie)
Subject: Re: perl menubased user interface
Message-Id: <Lc1140264563158640x91d7c8@localhost>
In <MF4Df.52493$tK4.376@tornado.ohiordc.rr.com>,
"Dave" <dmehler26@woh.rr.com> mentions:
>Hello,
> I've got a project that i would appreciate some feedback on. I want to
>design a perlbased user interface that i can drop in as a shell for one or
>more users. My primary purpose is to allow trusted users to manage various
>aspects of a unix machine, utilizing the sudo command to perform only
>certain tasks.
Sounds to me like the classic case for a type of dispatch table. You can
actually use a perl package OR a hash for this, (or both) In a "perl package"
model, the package itself becomes like a database of functions.
Here is a general LAYOUT done in perl to do this, it's NOT perl code, rather
just a layout of an idea very much like some stuff I do. (though I never
intend to take mine web based, I kind of go out of my way for a 1/2 decent
terminal interface because I like terminals.)
package My::Commands;
use strict;
#................ Stuff ..............
# $cmd->run('ls');
sub run {
my($self,$cmd,@args) = @_;
# test to see if we have $cmd before trying to run it.
if(my $meth = $self->map_method($cmd) ) {
$disp = $self->meth(@args);
#
# $disp is likely an object that has some kind of "display" method,
# since you say you'll be going to a web based environment later,
# you MAY need to keep terminal IO at a minimum. (have fun with sudo...)
#
}
}
sub map_method {
my($self,$cmd) = (shift,shift);
my $meth = 'cmd_' . $cmd; # Here we convert a command (for example, "ls") to
if($self->can($meth)){ # a sub named 'cmd_ls' and return it if we have it.
return($meth);
}
return();
}
#
# as for the commands...
#
# Write yourself a little script to BUILD THESE if you have a number of them
# and they're all shell commands. (keep in mind, if you need input from the user
# and have any hope of going web-based later on, you'll need to be "param() compatible
# with input checking and all that stuff.
#
sub cmd_ls {
my($self) = shift;
return( $self->shell_wrapper('ls','-l') );
}
sub shell_wrapper {
.. Do whatever you want to wrap a shell command. Could be a
.. simple system() call or you could have special setup/teardown
.. routines..
return($MY_CUSTOM_DISPLAY_OBJECT_GOES_HERE);
}
As far as the menu, there are a wide variety of CPAN modules out there, but,
my favorite is to just design my own using Term::Cap and Term::ReadKey
Build up a base class, something with the scrollbar and other goodies, then,
inherit from it in various modules. You can rip mine if you want:
http://www.geniegate.com/other/lucy/
Do note that the whole package is very buggy. (and will likely remain some-what
buggy, it's a purely for-fun package)
The thing you'll want is the "Scroll" stuff. You can rip that out and re-apply
it to your project if you like, or, just build your own and use it for ideas.
(I play a lot of tricks on Term::Cap to get symbolic color names, you may or
may not want to do that)
By doing it this way, you don't NEED to have your list of commands in any
particular shape or form. Just inherit and implement these two methods:
list_size
getListValue
I'd avoid elaborate keymapping if you can, but do make sure and wrap your calls
to readkey in a centralized place, just in case you end up doing that in the
future. (You'll likely want to "map" up/down pgup/pgdn and friends, though,
implementing these as commands for your menu system)
>user logs in, and the mainmenu comes up, i'm thinking it's numerical, 1 do
>this 2 do that etc. and depending on the choice there may be submenus or it
>could just execute a command. If this works i might also want to transfer
>this in to a web environment, where the user wouldn't have to log in would
>just pull up a web page. If anyone has anything like this or an idea how to
>proceed i would welcome suggestions.
sudo won't work in web-land, so, I'd suggest turning on taint checking from
the very start. You'll need to implement your own sudo. (this was the leading
reason for the shell_wrapper() method above, rather then just using system(),
if the time comes, you'll be glad all calls to system() are done in one place)
Obviously, if you're putting this on the web... you'll need to enforce security,
your users may not be the same users who end up hacking in. Security on this
level will be important.
Jamie
--
http://www.geniegate.com Custom web programming
guhzo_42@lnubb.pbz (rot13) User Management Solutions
------------------------------
Date: 18 Feb 2006 15:38:48 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Puzzled over rgexp
Message-Id: <slrndvefs7.891.abigail@alexandra.abigail.nl>
IanW (whoever@whereever.com) wrote on MMMMDLIII September MCMXCIII in
<URL:news:dt4ouv$je7$1@blackmamba.itd.rl.ac.uk>:
:)
:) "Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
:) news:45m70eF7d051U1@individual.net...
:) > IanW wrote:
:) >> Can anyone tell me why the following doesn't return "Not standards
:) >> compliant"?
:) >>
:) >> my $em = ',someone@somewhere.com'; # note the comma in fornt of the email
:) >> address
:) >> if ($em =~
:) >> /^(?!\.)[!\#\$%&'*+-\/=?^_`{|}~.a-zA-Z0-9]+(?<!\.)\@(?!\.)[a-zA-Z0-9-.]+$/)
:) > --------------------^^^^
:) >
:) > Those characters are interpreted as a range ( \053-\057 ), which happens
:) > to include comma ( \054 ). Put the '-' at the beginning or end of the
:) > character class.
:)
:) I see, thanks
:)
:) >> {
:) >> print "Standards compliant";
:) >> }
:) >> else {
:) >> print "Not standards compliant";
:) >> }
:) >
:) > Btw, which standard are you referring to?
:)
:) RFC2822, according to wikipedia
"perl misc"@abigail.nl
is a valid email address according to RFC2822 (and if you mail to it, you
should get an autorespond), but it won't match your regexp.
Abigail
--
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'
------------------------------
Date: Sat, 18 Feb 2006 14:11:35 -0800
From: robic0
Subject: Re: Puzzled over rgexp
Message-Id: <3q6fv1db4be9mqoefv4g7ea4uasnr7f8lq@4ax.com>
On Fri, 17 Feb 2006 14:05:10 -0000, "IanW" <whoever@whereever.com> wrote:
>Can anyone tell me why the following doesn't return "Not standards
>compliant"?
>
>my $em = ',someone@somewhere.com'; # note the comma in fornt of the email
>address
>if ($em =~
>/^(?!\.)[!\#\$%&'*+-\/=?^_`{|}~.a-zA-Z0-9]+(?<!\.)\@(?!\.)[a-zA-Z0-9-.]+$/)
>{
> print "Standards compliant";
>}
>else {
> print "Not standards compliant";
>}
>
>If you put a '.' or ':' or ';' etc in front of the address it comes back
>with not compliant but when it's a comma it comes back as compliant. Is this
>a bug or is the fault in my code?
>
>Thanks
>Ian
>
Came late, just read a sample,
If anyone hasn't already answered with the definative solution, say so
and I will.
------------------------------
Date: Sat, 18 Feb 2006 14:41:38 -0800
From: robic0
Subject: Re: Puzzled over rgexp
Message-Id: <aj8fv1lj0hb10robtqt0jmlumgnq51g3es@4ax.com>
On 18 Feb 2006 15:38:48 GMT, Abigail <abigail@abigail.nl> wrote:
>IanW (whoever@whereever.com) wrote on MMMMDLIII September MCMXCIII in
><URL:news:dt4ouv$je7$1@blackmamba.itd.rl.ac.uk>:
>:)
>:) "Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
>:) news:45m70eF7d051U1@individual.net...
>:) > IanW wrote:
>:) >> Can anyone tell me why the following doesn't return "Not standards
>:) >> compliant"?
>:) >>
>:) >> my $em = ',someone@somewhere.com'; # note the comma in fornt of the email
>:) >> address
>:) >> if ($em =~
>:) >> /^(?!\.)[!\#\$%&'*+-\/=?^_`{|}~.a-zA-Z0-9]+(?<!\.)\@(?!\.)[a-zA-Z0-9-.]+$/)
>:) > --------------------^^^^
>:) >
>:) > Those characters are interpreted as a range ( \053-\057 ), which happens
>:) > to include comma ( \054 ). Put the '-' at the beginning or end of the
>:) > character class.
>:)
>:) I see, thanks
>:)
>:) >> {
>:) >> print "Standards compliant";
>:) >> }
>:) >> else {
>:) >> print "Not standards compliant";
>:) >> }
>:) >
>:) > Btw, which standard are you referring to?
>:)
>:) RFC2822, according to wikipedia
>
>
> "perl misc"@abigail.nl
>
>is a valid email address according to RFC2822 (and if you mail to it, you
>should get an autorespond), but it won't match your regexp.
>
>
>Abigail
Hey big gurl, what in the fuck in this in your sig? :
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'
------------------------------
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 8970
***************************************