[26123] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8316 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 12 00:05:28 2005

Date: Thu, 11 Aug 2005 21: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)

Perl-Users Digest           Thu, 11 Aug 2005     Volume: 10 Number: 8316

Today's topics:
    Re: Manually parsing quoted characters <kuujinbo@hotmail.com>
    Re: Review of "Pro Perl Debugging" <notvalid@email.com>
    Re: sort <jurgenex@hotmail.com>
    Re: sort <eric-amick@comcast.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 12 Aug 2005 07:58:37 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: Manually parsing quoted characters
Message-Id: <ddgl6l$avq$1@pin3.tky.plala.or.jp>

Gary E. Ansok wrote:
> In article <42fb3422$0$18200$db0fefd9@news.zen.co.uk>,
> Dave Weaver  <zen13097@zen.co.uk> wrote:
> 
>>Arne Ruhnau <krevlar.newsgroups@tragetaschen.dyndns.org> wrote:
>>
>>> is there some simpler/more elegant solution to the following problem:
>>> given a string 'a\|b|c', transform it into the list ('a|b', 'c')
>>
>>Here's my attempt, splitting using a negative lookbehind assertion,
>>i.e. only splitting on a | if it's not preceded by a \
>>
>>#!/usr/bin/perl
>>use strict;
>>use warnings;
>>use Data::Dumper;
>>
>>my @list = map { s/\\\|/|/g; $_ } split /(?<!\\)\|/, 'a\|b|c';
>>print Dumper \@list;
>>
>>__END__
>>
>>$VAR1 = [
>>	    'a|b',
>>	    'c'
>>	];
> 
> 
> That runs into the question of how the string 'a\\|b|c' should be
> treated -- should it result in [ 'a\', 'b', 'c' ] ?  If so, then
> a little more work needs to be put into the code.

One possible way:

use strict;
use warnings;
use Text::ParseWords;

chomp(my @data = <DATA>);
foreach my $line (@data) {
   print join(' :: ', grep { $_ } parse_line('\|', 0, $line) ) . "\n";
}
__DATA__
a\|b|c
|a\|b|c
|a\\|b|c


HTH - keith


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

Date: Fri, 12 Aug 2005 01:00:07 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: Review of "Pro Perl Debugging"
Message-Id: <rwSKe.733$SR5.523@newssvr22.news.prodigy.net>

Tony Lawrence wrote:
> Review of "Pro Perl Debugging" at 
> http://aplawrence.com/Books/pro-perl-debugging.html

I would hardly call that a "review". It's a total of 4 (rather small) 
paragraphs, with only 1 sentence that might remotely be referred to as a 
review.

I may be wrong, but the only reason IMO this was posted so that the OP 
can have his/her referrer ID in the link to where you can buy the book 
from Amazon.com.

*plonk*

--Ala


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

Date: Thu, 11 Aug 2005 22:47:38 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: sort
Message-Id: <eAQKe.11568$0d.4108@trnddc02>

Pietro wrote:
> Hallo, I made a little script that sort the lines of a file:
>
> #! /usr/bin/perl
> sub numerically {$a <=> $b;}
> @array = <>;
> @array = sort numerically (@array);
> print (@array);
>
> Maybe the code is not so good, but why if I give thi input file:
>
> 1.3.5.6
> 1.1.2.4
[...]
> 111.222.555.666
> 1.1.2.3
> 1.3.4.5
>
> The result is this:
>
> 1.1.2.4
> 1.1.2.3
> 1.2.5.6
[...]
> 111.222.444.555
> 111.222.333.444
> 111.222.555.666
> 111.223.333.444
>
> As I see perl sots only the first two field delimited by a ".",

Well, no. Perl is sorting _numerically_, just as you asked it to do.
And the numerical value of e.g. the string 1.3.4.5 happens to be 1.3.

> the
> others are inserted as a fifo, first line encountered first line
> wrote in output,

Yep, that's a great feature. It is called a 'stable sort'. If two items have 
the same sort value, e.g. 111.222.444.555 and 111.222.333.444 which both 
have the value of 111.222, then since version 5.8 perl ensures that their 
relative position is not changed. Comes in very handy if you have to sort by 
multiple keys, e.g. first by first name, then by last name.

> why doesn't perl compare all the line?

But perl does compare all the line. Or rather the numerical value of the 
line just as you told it to do.

jue 




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

Date: Thu, 11 Aug 2005 21:52:53 -0400
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: sort
Message-Id: <dnvnf1p72rri8utl7ar3v62b0dnm61ahg2@4ax.com>

On Thu, 11 Aug 2005 21:38:20 GMT, Pietro <nobody@nowhere.no> wrote:

>Hallo, I made a little script that sort the lines of a file:
>
>#! /usr/bin/perl
>
>sub numerically {$a <=> $b;}
>
>@array = <>;
>
>@array = sort numerically (@array);
>
>print (@array);
>
>Maybe the code is not so good, but why if I give thi input file:
>
>1.3.5.6
>1.1.2.4
>111.222.444.555
>1.2.5.6
>11.22.44.55
>1.2.3.4
>11.23.66.77
>11.22.33.44
>111.222.333.444
>11.22.44.55
>111.223.333.444
>11.22.33.44
>1.2.3.4
>11.22.22.22
>11.22.55.66
>1.2.4.5
>111.222.555.666
>1.1.2.3
>1.3.4.5
>
>The result is this:
>
>1.1.2.4
>1.1.2.3
>1.2.5.6
>1.2.3.4
>1.2.3.4
>1.2.4.5
>1.3.5.6
>1.3.4.5
>11.22.44.55
>11.22.33.44
>11.22.44.55
>11.22.33.44
>11.22.22.22
>11.22.55.66
>11.23.66.77
>111.222.444.555
>111.222.333.444
>111.222.555.666
>111.223.333.444
>
>As I see perl sots only the first two field delimited by a ".", the others
>are inserted as a fifo, first line encountered first line wrote in output,
>why doesn't perl compare all the line?

Because you told it to compare numbers, and numbers have at most one
decimal point. If your goal is to compare the delimited fields, use a
function like this:

sub compare {
  my @value1 = split /\./, $a;
  my @value2 = split /\./, $b;
  ($value1[0] <=> $value2[0]) ||
  ($value1[1] <=> $value2[1]) ||
  ($value1[2] <=> $value2[2]) ||
  ($value1[3] <=> $value2[3]);
}

-- 
Eric Amick
Columbia, MD


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

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


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