[28392] in Perl-Users-Digest
Perl-Users Digest, Issue: 9756 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 22 18:10:17 2006
Date: Fri, 22 Sep 2006 15:10:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 22 Sep 2006 Volume: 10 Number: 9756
Today's topics:
Re: How identify if more than one option is specified? (reading news)
Re: How identify if more than one option is specified? (Chris Mattern)
Re: How identify if more than one option is specified? (Chris Mattern)
Re: How identify if more than one option is specified? <someone@example.com>
Re: How identify if more than one option is specified? <someone@example.com>
perl sort <honza@burdil.cz>
Re: perl sort <glex_no-spam@qwest-spam-no.invalid>
Re: perl sort usenet@DavidFilmer.com
Re: perl sort <honza@burdil.cz>
Re: Priority flag and MIME::Lite <maitrebart@excite.com>
Re: Russel Quong's "Perl in 20 pages" <uri@stemsystems.com>
Re: String Pattern Matching: regex and Python regex doc <ilias@lazaridis.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 22 Sep 2006 18:05:21 GMT
From: "Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
Subject: Re: How identify if more than one option is specified?
Message-Id: <BBVQg.14948$bM.4949@newsread4.news.pas.earthlink.net>
On 09/22/2006 12:27 PM, Hemant Shah wrote:
> Folks,
>
> Is there a easy way to find out if more than one option is specified.
>
> Example:
>
> use Getopt::Std;
> getopts(abc);
> if ($opt_a || $opt_b || $opt_c) {}
>
> I only want user to specify one of the options (either -a or -b -or -c).
> How do I easily check if they have specified more than one option.
>
> I can write "if" statement as follows:
>
> if (($opt_a && $opt_b && $opt_c) ||
> ($opt_a && $opt_b) ||
> ($opt_b && $opt_c) ||
> ($opt_a && $opt_c))
> {
> # print error message.
> }
>
> This could get ugly if the number of possible options is greater than 3.
>
> Is there an easier way?
>
> Thanks.
>
Put the results in a hash and count the number of keys in the hash like so:
use Getopt::Std;
my %opts;
getopts ('abc', \%opts);
if (keys %opts > 1) {
print "More than one option was given.\n";
}
__HTH__
--
paduille.4058.mumia.w@earthlink.net
------------------------------
Date: Fri, 22 Sep 2006 20:57:52 -0000
From: syscjm@sumire.eng.sun.com (Chris Mattern)
Subject: Re: How identify if more than one option is specified?
Message-Id: <12h8jigfe49lb61@corp.supernews.com>
In article <ef16de$non$1@new7.xnet.com>, Hemant Shah wrote:
>
>Folks,
>
> Is there a easy way to find out if more than one option is specified.
>
> Example:
>
> use Getopt::Std;
> getopts(abc);
> if ($opt_a || $opt_b || $opt_c) {}
>
> I only want user to specify one of the options (either -a or -b -or -c).
> How do I easily check if they have specified more than one option.
>
> I can write "if" statement as follows:
>
> if (($opt_a && $opt_b && $opt_c) ||
> ($opt_a && $opt_b) ||
> ($opt_b && $opt_c) ||
> ($opt_a && $opt_c))
> {
> # print error message.
> }
>
> This could get ugly if the number of possible options is greater than 3.
>
> Is there an easier way?
>
> Thanks.
>
Sure. Just count heads.
my $arg_count=0;
$arg_count++ if $opt_a;
$arg_count++ if $opt_b;
$arg_count++ if $opt_c;
if ($arg_count != 1) {
die "You dummy, pick one and only one!"; }
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Fri, 22 Sep 2006 21:07:04 -0000
From: syscjm@sumire.eng.sun.com (Chris Mattern)
Subject: Re: How identify if more than one option is specified?
Message-Id: <12h8k3oo1ooaub4@corp.supernews.com>
In article <BBVQg.14948$bM.4949@newsread4.news.pas.earthlink.net>,
Mumia W. (reading news) wrote:
>On 09/22/2006 12:27 PM, Hemant Shah wrote:
>> Folks,
>>
>> Is there a easy way to find out if more than one option is specified.
>>
>> Example:
>>
>> use Getopt::Std;
>> getopts(abc);
>> if ($opt_a || $opt_b || $opt_c) {}
>>
>> I only want user to specify one of the options (either -a or -b -or -c).
>> How do I easily check if they have specified more than one option.
>>
>> I can write "if" statement as follows:
>>
>> if (($opt_a && $opt_b && $opt_c) ||
>> ($opt_a && $opt_b) ||
>> ($opt_b && $opt_c) ||
>> ($opt_a && $opt_c))
>> {
>> # print error message.
>> }
>>
>> This could get ugly if the number of possible options is greater than 3.
>>
>> Is there an easier way?
>>
>> Thanks.
>>
>
>Put the results in a hash and count the number of keys in the hash like so:
>
> use Getopt::Std;
> my %opts;
> getopts ('abc', \%opts);
>
> if (keys %opts > 1) {
> print "More than one option was given.\n";
> }
>
>__HTH__
>
Dang, I didn't think that would work. But you're right, the
key isn't defined if the option isn't given. That can have
problems, but works out well for him here. I think the hash
version should usually be used anyways, it's just so much
cleaner.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Fri, 22 Sep 2006 21:20:23 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: How identify if more than one option is specified?
Message-Id: <rsYQg.32631$cz3.21299@edtnps82>
Chris Mattern wrote:
> In article <ef16de$non$1@new7.xnet.com>, Hemant Shah wrote:
>>Folks,
>>
>> Is there a easy way to find out if more than one option is specified.
>>
>> Example:
>>
>> use Getopt::Std;
>> getopts(abc);
>> if ($opt_a || $opt_b || $opt_c) {}
>>
>> I only want user to specify one of the options (either -a or -b -or -c).
>> How do I easily check if they have specified more than one option.
>>
>> I can write "if" statement as follows:
>>
>> if (($opt_a && $opt_b && $opt_c) ||
>> ($opt_a && $opt_b) ||
>> ($opt_b && $opt_c) ||
>> ($opt_a && $opt_c))
>> {
>> # print error message.
>> }
>>
>> This could get ugly if the number of possible options is greater than 3.
>>
>> Is there an easier way?
>
> Sure. Just count heads.
>
> my $arg_count=0;
> $arg_count++ if $opt_a;
> $arg_count++ if $opt_b;
> $arg_count++ if $opt_c;
my $arg_count = grep $_, $opt_a, $opt_b, $opt_c;
> if ($arg_count != 1) {
> die "You dummy, pick one and only one!"; }
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 22 Sep 2006 21:22:33 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: How identify if more than one option is specified?
Message-Id: <tuYQg.32632$cz3.22769@edtnps82>
John W. Krahn wrote:
> Chris Mattern wrote:
>>In article <ef16de$non$1@new7.xnet.com>, Hemant Shah wrote:
>>>Folks,
>>>
>>>Is there a easy way to find out if more than one option is specified.
>>>
>>>Example:
>>>
>>>use Getopt::Std;
>>>getopts(abc);
>>>if ($opt_a || $opt_b || $opt_c) {}
>>>
>>>I only want user to specify one of the options (either -a or -b -or -c).
>>>How do I easily check if they have specified more than one option.
>>>
>>>I can write "if" statement as follows:
>>>
>>>if (($opt_a && $opt_b && $opt_c) ||
>>> ($opt_a && $opt_b) ||
>>> ($opt_b && $opt_c) ||
>>> ($opt_a && $opt_c))
>>>{
>>> # print error message.
>>>}
>>>
>>>This could get ugly if the number of possible options is greater than 3.
>>>
>>>Is there an easier way?
>>Sure. Just count heads.
>>
>>my $arg_count=0;
>>$arg_count++ if $opt_a;
>>$arg_count++ if $opt_b;
>>$arg_count++ if $opt_c;
>
> my $arg_count = grep $_, $opt_a, $opt_b, $opt_c;
Or more correctly:
my $arg_count = grep defined, $opt_a, $opt_b, $opt_c;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 22 Sep 2006 21:22:55 +0200
From: "Jan Burdil" <honza@burdil.cz>
Subject: perl sort
Message-Id: <ef1d6t$2bbb$1@ns.felk.cvut.cz>
Hello,
how can I replace * with some command like cat file, ls -l in line
perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'
Thank you
Jan Burdil
------------------------------
Date: Fri, 22 Sep 2006 14:58:07 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: perl sort
Message-Id: <45143f96$0$10296$815e3792@news.qwest.net>
Jan Burdil wrote:
> Hello,
> how can I replace * with some command like cat file, ls -l in line
>
> perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'
You'd use your editor, or your arrow keys, move the cursor to '*',
remove '*', and insert whatever you like.
Maybe explaining what you want to do and what you tried would get you a
better answer.
------------------------------
Date: 22 Sep 2006 13:06:00 -0700
From: usenet@DavidFilmer.com
Subject: Re: perl sort
Message-Id: <1158955560.505431.278100@i3g2000cwc.googlegroups.com>
Jan Burdil wrote:
> how can I replace * with some command like cat file, ls -l in line
> perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'
perl -e 'print join "\n", sort { -M $b <=> -M $a } `ls -l`,"\n"'
But I find it hard to believe you REALLY want to do that... that's
nutty. There are far better ways to do that (either in Perl or using
plain shell commands).
--
David Filmer (http://DavidFilmer.com)
------------------------------
Date: Fri, 22 Sep 2006 22:24:30 +0200
From: "Jan Burdil" <honza@burdil.cz>
Subject: Re: perl sort
Message-Id: <ef1gqb$2dqu$1@ns.felk.cvut.cz>
when I try
perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'
bb
xx
aa
Mail
mail
yy
unrar
tmp
curl.txt
abc
my files are sorted by date. And I need to sort lines from curl command.
curl ftp://1.1.1.1 give me
-rw-r--r-- 1 honza users 414 Sep 22 12:16 curl.txt
-rwx------ 1 honza users 52 May 31 21:54 bb
drwx------ 2 honza users 512 Aug 22 10:54 mail
And I would like the result to be sorted by date.
I try replace <*> with command curl ftp://1.1.1.1 like this
perl -e 'print join "\n", sort { -M $b <=> -M $a } `curl
ftp://1.1.1.1`,"\n"'
but this doesn't work
Jan Burdil
<usenet@DavidFilmer.com> wrote in message
news:1158955560.505431.278100@i3g2000cwc.googlegroups.com...
> Jan Burdil wrote:
>> how can I replace * with some command like cat file, ls -l in line
>> perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'
>
> perl -e 'print join "\n", sort { -M $b <=> -M $a } `ls -l`,"\n"'
>
> But I find it hard to believe you REALLY want to do that... that's
> nutty. There are far better ways to do that (either in Perl or using
> plain shell commands).
>
> --
> David Filmer (http://DavidFilmer.com)
>
------------------------------
Date: 22 Sep 2006 13:36:17 -0700
From: "Maitre Bart" <maitrebart@excite.com>
Subject: Re: Priority flag and MIME::Lite
Message-Id: <1158957377.656391.67780@e3g2000cwe.googlegroups.com>
Maitre Bart wrote:
> Is there a way to set the priority flag in an email to be sent using
> MIME::Lite ?
> I looked in the MIME::Lite doc but found nothing about priority. I
> searched with Goggle in vain.
I will answer to myself and to those who may be curious too:
$mime->add('X-Priority' => 1)
will do the job!
------------------------------
Date: Fri, 22 Sep 2006 16:26:38 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Russel Quong's "Perl in 20 pages"
Message-Id: <x7bqp7abr5.fsf@mail.sysarch.com>
>>>>> "MD" == Michele Dondi <bik.mido@tiscalinet.it> writes:
MD> On Thu, 21 Sep 2006 14:20:34 -0400, Uri Guttman <uri@stemsystems.com>
MD> wrote:
>> i love reading bad perl web tutes. this is as bad as they get. this
MD> You're either lying or removing past horrors. Do you remember the
MD> earthquake guy's one? And the one by a lady whose name eludes me for
MD> the moment, but which was reported here exactly for that reason: i.e.
MD> being an awfully bad -but supported by some institution's grant!- perl
MD> tutorial?
i recall all of those. but this guy's comments on arrays and lists being
the same since the docs say so is as bad as any of those others. the
absolute certainty of his comments are hysterical. but the only way to
truly judge these tutes is to make up a page of links, reviews and
quotes. a worthy project. maybe i will make it a wiki so we can all join
in.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 22 Sep 2006 22:11:35 +0300
From: Ilias Lazaridis <ilias@lazaridis.com>
To: Xah Lee <xah@xahlee.org>
Subject: Re: String Pattern Matching: regex and Python regex documentation
Message-Id: <45143567.2000903@lazaridis.com>
[followup to c.l.py]
Xah Lee wrote:
> the Python regex documentation is available at:
> http://xahlee.org/perl-python/python_re-write/lib/module-re.html
>
> Note that, i've just made the terms of use clear.
>
> Also, can anyone answer what is the precise terms of license of the
> official python documentation? The official python.org doc site is not
> clear.
I would be interested in this information, too.
> Note also, that the regex syntax used by Perl is the same as Python.
> So, this section
> http://xahlee.org/perl-python/python_re-write/lib/re-syntax.html
> which contains clear explanation of regex syntax, will be of interest
> to Perl programers as well.
...
Your tutorial has helped me to write my first regular expression:
http://dev.lazaridis.com/base/changeset/60
your notes about documentation are interesting, too:
http://xahlee.org/perl-python/re-write_notes.html
I have some notes, too:
http://case.lazaridis.com/wiki/Docu
-
I would like to read more on your website, but the usability is
terrible, mainly due to the missing navigation.
What about an exchange?
I assist you with the navigation. you will just need apache
server-side-include and one file "navigation.html", which will contail
all of the navigation, very simple.
And you make an real life example for a python regular expression use-case:
i want to scan a text for this line:
[[CustomAttributes(this=4,that=34,name='peter')]]
picking "this=4" ...
and add the attributes to an object.
object = addCustomAttributes(text)
(ok, the regex part would be enouth).
.
--
http://lazaridis.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:
#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 9756
***************************************