[18094] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 254 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 9 06:10:31 2001

Date: Fri, 9 Feb 2001 03:10:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <981717013-v10-i254@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 9 Feb 2001     Volume: 10 Number: 254

Today's topics:
    Re: sort of about sort (Mark Jason Dominus)
    Re: sort of about sort <ccx138@coventry.ac.uk>
        sorting an array (J.C.Posey)
    Re: Specifying the length of regular expression <iboreham@my-deja.com>
        split a path and keep the slashes? tebrusca@my-deja.com
    Re: split a path and keep the slashes? <jonni@ifm.liu.se>
    Re: split a path and keep the slashes? <krahnj@acm.org>
    Re: split a path and keep the slashes? <wuerz@yahoo.com>
    Re: splitting a string on the / character (Mark Jason Dominus)
    Re: splitting a string on the / character (Csaba Raduly)
    Re: This is driving me nuts and I need a guru (Randal L. Schwartz)
    Re: This is driving me nuts and I need a guru (David H. Adler)
    Re: Using regex to match numbers (not digits)? <uri@sysarch.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 09 Feb 2001 05:24:44 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: sort of about sort
Message-Id: <3a837f1c.6f74$389@news.op.net>
Keywords: Paulsen, dodecahedra, gavel, giantess

In article <3A8343B1.A800D6D6@coventry.ac.uk>,
JMT  <ccx138@coventry.ac.uk> wrote:
>Just for interest why wasn't sort implemented so you could use it like
>the UNIX sort.
>e.g. sort -n @array; to sort numerically. even sort -nr to reverse a
>numeric sort.

The current method is more flexible and useful.

>It would seem to make sense because most of the time you either want to
>sort in alpha order or numeric.

No.  Perhaps most of the time *you* want an alpha or numeric sort;
that doesn't mean that that is what other people want.

>Without wanting to change the language is this something that could be
>perl 6 ?

It could, but it won't, because it multiplies entities unnecessarily.
There is already a perfectly good way to do a numeric reversed sort
(as you know, having already read the manual entry for 'sort') and
your suggestion only adds another way to do exactly the same thing.

If you really want that, it is easy to add:

        sub jmt_sort ($@) {
          my $arg = shift;     
          my $numeric  = ($arg =~ /n/);
          my $reversed = ($arg =~ /r/);
          return $numeric ? ($reversed ? sort {$b<=>$a}   @_ 
                                       : sort {$a<=>$b}   @_ )
                          : ($reversed ? sort {$b cmp$ a} @_ 
                                       : sort             @_ );
        }

Then you can use:

        jmt_sort -nr, @array;

and nobody else needs to be bothered by it.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Fri, 09 Feb 2001 09:02:03 +0000
From: JMT <ccx138@coventry.ac.uk>
Subject: Re: sort of about sort
Message-Id: <3A83B20A.34805389@coventry.ac.uk>



Mark Jason Dominus wrote:

> In article <3A8343B1.A800D6D6@coventry.ac.uk>,
> JMT  <ccx138@coventry.ac.uk> wrote:
> >Just for interest why wasn't sort implemented so you could use it like
> >the UNIX sort.
> >e.g. sort -n @array; to sort numerically. even sort -nr to reverse a
> >numeric sort.
>
> The current method is more flexible and useful.
>

[SNIP]

>
> It could, but it won't, because it multiplies entities unnecessarily.
> There is already a perfectly good way to do a numeric reversed sort
> (as you know, having already read the manual entry for 'sort') and
> your suggestion only adds another way to do exactly the same thing.
>

So what does TMTOWTDI stand for again. ;)
I was just thinking that it could (have) be(en) implemented so if you want to
sort by another way you could define your own or by default it does alpha or with
a switch it does numeric.

I was only asking because perl started on UNIX and I'm sure Larry often used sort
-nr.  I have no problem with doing it the way it is now I was just curious as to
why it was set up the way it was.

John.



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

Date: 09 Feb 2001 11:01:54 +0000
From: jcp@myrtle.ukc.ac.uk (J.C.Posey)
Subject: sorting an array
Message-Id: <jkou264jf19.fsf@myrtle.ukc.ac.uk>

I'm a novice Perl programmer, and may be missing something simple.

I converted an awk script using a2p, and want to add a little functionality.

I would like to sort my output, then print.  Currently,

---code fragment---

foreach $item (keys %daily_total) {
    print $item, $daily_total{$item};
}

---end----

Which simply prints to standard out, and then I sort in my shell.  I would
like to sort prior to output.

I know that if it was an array I could simply sort @daily_total, but this
is in error here. Or is it?

Thanks for the help.

-- 
Jake C. Posey                    | +44 (0)1227 827692
Junior Technical Support Officer | http://www.mau.ac.uk/
MAU/TAU                          | http://www.tau.ac.uk/
University of Kent at Canterbury | http://www.jisc.ac.uk/


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

Date: Fri, 09 Feb 2001 10:36:01 GMT
From: Ian Boreham <iboreham@my-deja.com>
Subject: Re: Specifying the length of regular expression
Message-Id: <960h6i$jeo$1@nnrp1.deja.com>

In article <3a835728.6a41$378@news.op.net>,
  mjd@plover.com (Mark Jason Dominus) wrote:
> In article <95v3pv$fhp$1@nnrp1.deja.com>,  <bonjaa@my-deja.com> wrote:
> >How can I write a regular expression for the following:
>
> That is what we call the Wrong Question.

In this case, probably, but not necessarily.

There are occasions on which you can only specify a regular expression,
to be used by code over which you have no control, but you want to do
things like invert the match, specify the length etc. In some cases even
in your own code, you might want to loop over a large collection of
regexes, and you can't really cater for these sorts of special cases
without grossifying your code.

But I know what you mean.

If you really need to do it with a single regex, try:

  ^(?=[ABC]{10,})A+B*C+$

or some variation to taste.


#! /usr/bin/perl -w
use strict;

my @tests = qw(ABC AC AAAAAABCCCCC ACCCCCCCCCCC BAC kkAABCCFFF
AAAAAAAAAA AB ABBBBBBBBC ABBBBBBBC);
foreach (@tests)
{
    print /^(?=[ABC]{10,})A+B*C+$/? "$_ matched\n": "$_ failed\n";
}


This gives the following output:

ABC failed
AC failed
AAAAAABCCCCC matched
ACCCCCCCCCCC matched
BAC failed
kkAABCCFFF failed
AAAAAAAAAA failed
AB failed
ABBBBBBBBC matched
ABBBBBBBC failed


Regards,


Ian


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 09 Feb 2001 05:34:16 GMT
From: tebrusca@my-deja.com
Subject: split a path and keep the slashes?
Message-Id: <95vvgo$628$1@nnrp1.deja.com>

Given a path: "//A/B/" or "/A/B" or "/A//B//" etc
Return a list: "/A", "/B"

That is, ignore multiple slashes and give items with leading slash

Here's what I came up with:

my $string = "/A/B///";
my @list =  map {"/$_"}( map {/^(.+)/}(split( /\//, $string )));

Am I breaking the "Dont modify $_" rule with my first ( actually
second) map?

Any comments or better ideas ... golfers?

Note: The number of items may vary so /()()/ wont work for me.


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 9 Feb 2001 08:57:15 +0100
From: "Jonas Nilsson" <jonni@ifm.liu.se>
Subject: Re: split a path and keep the slashes?
Message-Id: <9607rg$ht6$1@newsy.ifm.liu.se>

How about:

$path="/A//B//";
$_=$path;
while (s%^/*?((/|)[^/]+)%%) {push @list,$1};

(Will work for relative paths also A//B// will give ("A","/B"))
/jN
--
 _____________________     _____________________
|   Jonas Nilsson     |   |                     |
|Linkoping University |   |      Telephone      |
|       IFM           |   |      ---------      |
| Dept. of Chemistry  |   | work: +46-13-285690 |
|  581 83 Linkoping   |   | fax:  +46-13-281399 |
|      Sweden         |   | home: +46-13-130294 |
|_____________________|   |_____________________|
<tebrusca@my-deja.com> wrote in message news:95vvgo$628$1@nnrp1.deja.com...
> Given a path: "//A/B/" or "/A/B" or "/A//B//" etc
> Return a list: "/A", "/B"
>
> That is, ignore multiple slashes and give items with leading slash
>
> Here's what I came up with:
>
> my $string = "/A/B///";
> my @list =  map {"/$_"}( map {/^(.+)/}(split( /\//, $string )));
>
> Am I breaking the "Dont modify $_" rule with my first ( actually
> second) map?
>
> Any comments or better ideas ... golfers?
>
> Note: The number of items may vary so /()()/ wont work for me.
>
>
> Sent via Deja.com
> http://www.deja.com/




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

Date: Fri, 09 Feb 2001 07:44:58 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: split a path and keep the slashes?
Message-Id: <3A83A10D.5A191569@acm.org>

tebrusca@my-deja.com wrote:
> 
> Given a path: "//A/B/" or "/A/B" or "/A//B//" etc
> Return a list: "/A", "/B"
> 
> That is, ignore multiple slashes and give items with leading slash
> 
> Here's what I came up with:
> 
> my $string = "/A/B///";
> my @list =  map {"/$_"}( map {/^(.+)/}(split( /\//, $string )));
> 
> Am I breaking the "Dont modify $_" rule with my first ( actually
> second) map?

No.

> Any comments or better ideas ... golfers?

my @list = grep { length and $_ = "/$_" } split m-/-, $string;


John


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

Date: Fri, 09 Feb 2001 09:07:53 +0100
From: Mona Wuerz <wuerz@yahoo.com>
Subject: Re: split a path and keep the slashes?
Message-Id: <090220010907538209%wuerz@yahoo.com>

In article <95vvgo$628$1@nnrp1.deja.com>, tebrusca@my-deja.com wrote:

> Given a path: "//A/B/" or "/A/B" or "/A//B//" etc
> Return a list: "/A", "/B"
> 
> That is, ignore multiple slashes and give items with leading slash
> 
> Any comments or better ideas ... golfers?

No golf, but why not simply:

my $string = "/A/B///C/D////";

 $string =~ s#/+#/#g;                  # collapse multiple /
 my @list = split /(?=\/)/, $string;   # split on / but don't throw away

print join ',', @list;

output:

/A,/B,/C,/D,/

You may want to trim trailing slashes depending on what you need this
for.

(but I agree, golf would be nicer)

-mona


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

Date: Fri, 09 Feb 2001 05:13:28 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: splitting a string on the / character
Message-Id: <3a837c77.6f2d$27f@news.op.net>
Keywords: TX, ascend, convect, tessellate


In article <slrn986puq.giv.damian@puma.qimr.edu.au>,
Damian James <damian@qimr.edu.au> wrote:
>>When you tell someone that the answer lies
>>somewhere in a highly technical 8000-word document ("But I won't tell
>>you where, nyaaah!) you're just being a jerk.
>>
>
>I really hope I haven't done this here. 

I didn't meen to single you out or to suggest that you in particular
had done any of these things.  I was using the indefinite 'you'
here---I think our newsgroup has a problem with this in general and
that a lot of people are guilty of this.

>I can see I've made a fool of myself here again, 

Well, if it's any consolation, I don't think you made a fool of
yourself.  I just happened to respond to your article because it was
the one I was reading when the spirit moved me to reply, not because I
thought it was egregiously foolish.  And I almost threw away the reply
because I would afraid that you and others would think I was trying to
chastise you in particular, which I wasn't; my remarks were meant
generally.

I should probably have said all this in the original article; I'm
sorry that I didn't do that.



-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Fri, 9 Feb 2001 10:41:22 +0000 (UTC)
From: real.email@signature.this.is.invalid (Csaba Raduly)
Subject: Re: splitting a string on the / character
Message-Id: <Xns904362085quuxi@194.203.134.135>

And so it came to pass that jstanley@mmm.com on 08 Feb 2001 wrote
<95uj37$2a5$1@magnum.mmm.com>: 

>If you know the answer to a question, answer it.  If you don't, or
>have a smart ass comment on why the person should have known the
>answer, don't answer it.  Think of it  this way.
>If you are lost in a foreign town, would you appreciate it if when
>you asked for directions, someone said "Look it up on the map".
>

If the map was available on every street corner, I would definitely 
appreciate it (especially if they pointed out box B4)

-- 
Csaba Raduly, Software Developer (OS/2), Sophos Anti-Virus
mailto:csaba.raduly@sophos.com      http://www.sophos.com/
US Support +1 888 SOPHOS 9      UK Support +44 1235 559933
You are in a maze of twisted little minds, all different.


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

Date: 08 Feb 2001 22:40:15 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: This is driving me nuts and I need a guru
Message-Id: <m1wvb0fjg0.fsf@halfdome.holdit.com>

>>>>> "David" == David H Adler <dha@panix6.panix.com> writes:

David> As much as I respect Tad, I need to disagree slightly.

Oh, now you've done it, you ignorant twit!  You dissed a friend of
mine!  Someone I partied with on a boat for an *entire* 10 days in the
Caribbean! (www.geekcruises.com)

David> Being new to Usenet doesn't get you flamed.  Not bothering to find out
David> how one is expected to act on Usenet (and taking that to heart) gets
David> you flamed.

Yeah, you and the horse you rode in on!  Bollocks!  Your guitars do
*not* go to 11!

And *don't* post to comp.lang.perl ever.   Again.

:-)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 9 Feb 2001 06:48:23 GMT
From: dha@panix6.panix.com (David H. Adler)
Subject: Re: This is driving me nuts and I need a guru
Message-Id: <slrn9874ln.i9r.dha@panix6.panix.com>

On 08 Feb 2001 22:40:15 -0800, Randal L. Schwartz <merlyn@stonehenge.com> wrote:

>And *don't* post to comp.lang.perl ever.   Again.

Grah!  I must be tired.  I should certainly know better to trust other
posters headers... :-/

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
I expect my version of ESP::Psychic will be ready sometime last week.
More likely, yesterday (you know how schedules tend to slip).
	- Eric The Read in comp.lang.perl.misc


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

Date: Fri, 09 Feb 2001 06:27:01 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Using regex to match numbers (not digits)?
Message-Id: <x7ae7wnzgp.fsf@home.sysarch.com>

>>>>> "n" == nukes666  <nukes666@my-deja.com> writes:

  n> I apologize if this question is elementary, which I suspect it is.
  n> However, I am struggling with it and have searched the web and also
  n> checked the regex section of Learning Perl.

get the book mastering regular expressions. read it multiple times.

  n> I need to search a file which has, let's say, 2000 numbers in it
  n> between 1 & 2000, each on it's own line. I want to only print numbers
  n> 700 through 900 and 1200 through 1500.

  n> while (<FILE>) {
  n>       print if /[700-900][1200-1500]/;
  n>       }

  n> Apparently, though, this returns any lines based on digit matches, and
  n> not numbers. Could someone suggest the appropriate regex to return
  n> ranges of numbers?

why must you do it with a pure regex? in fact it would be hard to do
with just a regex as you really want a math range.

	print if /(\d+)/ && (  700 <= $1 && $1 <=  900 ||
                              1200 <= $1 && $1 <= 1500 ) ;

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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