[25974] in Perl-Users-Digest
Perl-Users Digest, Issue: 8193 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 22 21:05:30 2005
Date: Wed, 22 Jun 2005 18: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 Wed, 22 Jun 2005 Volume: 10 Number: 8193
Today's topics:
Re: Email Address Validation <abigail@abigail.nl>
Re: FAQ 6.18 Why does using $&, $`, or $' slow my progr (Anno Siegel)
How can I pick up those big numbers <sun_tong@users.sourceforge.net>
Re: How can I pick up those big numbers <1usa@llenroc.ude.invalid>
Re: How can I pick up those big numbers <sun_tong@users.sourceforge.net>
Re: How can I pick up those big numbers <1usa@llenroc.ude.invalid>
Re: How can I pick up those big numbers <sun_tong@users.sourceforge.net>
Re: How can I pick up those big numbers <1usa@llenroc.ude.invalid>
module to create Zork like game maps? <*@eli.users.panix.com>
Re: module to create Zork like game maps? <tadmc@augustmail.com>
Re: module to create Zork like game maps? <dha@panix.com>
Re: module to create Zork like game maps? <abigail@abigail.nl>
sort on third, then second field <jblno@spamhotmail.com>
Re: sort on third, then second field <1usa@llenroc.ude.invalid>
Re: what's the right way to encode this? <sun_tong@users.sourceforge.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 22 Jun 2005 19:02:23 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Email Address Validation
Message-Id: <slrndbjddv.14f.abigail@alexandra.abigail.nl>
Brian Wakem (no@email.com) wrote on MMMMCCCXIII September MCMXCIII in
<URL:news:3htd83FiqocoU1@individual.net>:
:: Dave Weaver wrote:
::
:: > On Wed, 22 Jun 2005 15:13:13 +0100, Brian Wakem <no@email.com> wrote:
:: >>
:: >> invalid_email_response() unless $FORM{'emailaddress'} =~
:: >> m/^[-a-zA-Z0-9_.]+\@[-a-zA-Z0-9_]+\.[-a-zA-Z0-9_.]+[a-zA-Z]$/;
:: >
:: > That code will reject perfectly valid email addesses, such as
:: > joe+bloggs@example.com
:: > my*name@example.com
:: > and many others.
::
::
:: I know, but for ease of implementation against effectiveness it is a
:: reasonable trade-off IMO. I have a database of 1.4 million email addresses
:: and that regex matches *all* of them.
I've a list of 500 billion email addresses, and /.*/ matches all of them.
Abigail
--
#!/opt/perl/bin/perl -w
$\ = $"; $; = $$; END {$: and print $:} $SIG {TERM} = sub {$ := $_}; kill 15 =>
fork and ($; == getppid and exit or wait) foreach qw /Just another Perl Hacker/
------------------------------
Date: 22 Jun 2005 20:17:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: FAQ 6.18 Why does using $&, $`, or $' slow my program down?
Message-Id: <d9ch0p$bje$1@mamenchi.zrz.TU-Berlin.DE>
brian d foy <comdog@panix.com> wrote in comp.lang.perl.misc:
> In article <d94se2$eld$1@mamenchi.zrz.TU-Berlin.DE>, Anno Siegel
> <anno4000@lublin.zrz.tu-berlin.de> wrote:
>
> > I am appending an amended version of the FAQ (since it is posted with my
> > name attached, I kinda feel responsible :)
>
> thanks - I'll patch it in the next go around. :)
Okay, so I've done my homework. @- and @+ came with 5.6.1. They are not
mentioned in perldelta, but they weren't in perl5.005_04.
Anno
Once Perl sees that you need one of these variables anywhere in the
program, it provides them on each and every pattern match. That means
that on every pattern match the entire string will be copied, part of it
to $`, part to $&, and part to $'. Thus the penalty is most severe with
long strings and patterns that match often. Avoid $&, $', and $` if you
can, but if you can't, once you've used them at all, use them at will
because you've already paid the price. Remember that some algorithms
really appreciate them. As of the 5.005 release, the $& variable is no
longer "expensive" the way the other two are.
Since Perl 5.6.1 the special variables @- and @+ can functionally replace
$`, $& and $'. These arrays contain pointers to the beginning and end
of each match (see perlvar for the full story), so they give you
essentially the same information, but without the risk of excessive
string copying.
------------------------------
Date: Wed, 22 Jun 2005 15:02:50 -0400
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: How can I pick up those big numbers
Message-Id: <1119466971.7a2c29c3a87333897c34ea4df8df5570@teranews>
Hi,
Say I have a string like the following, and I want to pick up those "big
numbers" pointed by ^^^:
abcdµÜefgÒÝ•„£¨qwert
^^^^^^^^^^^^^^
My mind is blunt now... thanks
--
Tong (remove underscore(s) to reply)
*niX Power Tools Project: http://xpt.sourceforge.net/
- All free contribution & collection
------------------------------
Date: Wed, 22 Jun 2005 19:33:13 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How can I pick up those big numbers
Message-Id: <Xns967D9E38DC940asu1cornelledu@127.0.0.1>
* Tong * <sun_tong@users.sourceforge.net> wrote in
news:1119466971.7a2c29c3a87333897c34ea4df8df5570@teranews:
> Say I have a string like the following, and I want to pick up those "big
> numbers" pointed by ^^^:
>
> abcdµÜefgÒÝ•„£¨qwert
> ^^^^^^^^^^^^^^
> My mind is blunt now... thanks
Well, what is your criterion for big?
What exactly do you mean by 'pick up'?
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Wed, 22 Jun 2005 16:52:27 -0400
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: Re: How can I pick up those big numbers
Message-Id: <1119473548.b876b92af10baa24aadf8a8a56fd94db@teranews>
On Wed, 22 Jun 2005 19:33:13 +0000, A. Sinan Unur wrote:
>> Say I have a string like the following, and I want to pick up those "big
>> numbers" pointed by ^^^:
>>
>> abcdµÜefgÒÝ•„£¨qwert
>> ^^^^^^^^^^^^^^
>> My mind is blunt now... thanks
>
> Well, what is your criterion for big?
Criterion is >= 256
> What exactly do you mean by 'pick up'?
Locate the string "•" by Perl so that I can do further tweaking,
e.g., change "•„" to something else.
--
Tong (remove underscore(s) to reply)
*niX Power Tools Project: http://xpt.sourceforge.net/
- All free contribution & collection
------------------------------
Date: Wed, 22 Jun 2005 21:01:53 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How can I pick up those big numbers
Message-Id: <Xns967DAD40945C6asu1cornelledu@127.0.0.1>
* Tong * <sun_tong@users.sourceforge.net> wrote in
news:1119473548.b876b92af10baa24aadf8a8a56fd94db@teranews:
> On Wed, 22 Jun 2005 19:33:13 +0000, A. Sinan Unur wrote:
>
>>> Say I have a string like the following, and I want to pick up those
>>> "big numbers" pointed by ^^^:
>>>
>>> abcdµÜefgÒÝ•„£¨qwert
>>> ^^^^^^^^^^^^^^
>>> My mind is blunt now... thanks
>>
>> Well, what is your criterion for big?
>
> Criterion is >= 256
>
>> What exactly do you mean by 'pick up'?
>
> Locate the string "•" by Perl so that I can do further tweaking,
> e.g., change "•„" to something else.
Poster are generally expected to have attempted a solution *before*
posting. I would recommend reading the posting guidelines for this group
as well as:
perldoc perlop
especially the section on regex operators. Second,
try
perldoc perlre
perldoc perlretut
perldoc perlreref
As for you specific problem, the following might be a solution:
#! /usr/bin/perl
use strict;
use warnings;
my $s = q{abcdµÜefgÒÝ•„£&#
168;qwert};
while($s =~ /&#(\d+);/g) {
if((my $c = 0 + $1) >= 256) {
print "Bad: $c\n";
}
}
__END__
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Wed, 22 Jun 2005 17:37:14 -0400
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: Re: How can I pick up those big numbers
Message-Id: <1119476235.055b5bd162903248a909f6bba92b4672@teranews>
On Wed, 22 Jun 2005 21:01:53 +0000, A. Sinan Unur wrote:
> Poster are generally expected to have attempted a solution *before*
> posting. I would recommend reading the posting guidelines for this group
> as well as:
I don't have a good way for that, so I told myself, "instead of posting my
long-and-ugly code, why not wait for a neat one." :-) Thanks for the
script.
> while($s =~ /&#(\d+);/g) {
Hmm, never thought a match can be used like this before -- in each loop,
$1 get a new match...
Thanks again
--
Tong (remove underscore(s) to reply)
*niX Power Tools Project: http://xpt.sourceforge.net/
- All free contribution & collection
------------------------------
Date: Wed, 22 Jun 2005 23:20:58 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How can I pick up those big numbers
Message-Id: <Xns967DC4D50D5Casu1cornelledu@127.0.0.1>
* Tong * <sun_tong@users.sourceforge.net> wrote in
news:1119476235.055b5bd162903248a909f6bba92b4672@teranews:
> On Wed, 22 Jun 2005 21:01:53 +0000, A. Sinan Unur wrote:
>
>> Poster are generally expected to have attempted a solution *before*
>> posting. I would recommend reading the posting guidelines for this
>> group as well as:
>
> I don't have a good way for that, so I told myself, "instead of
> posting my long-and-ugly code, why not wait for a neat one." :-)
> Thanks for the script.
Well, I had no intention of supporting lazy behavior.
>> while($s =~ /&#(\d+);/g) {
>
> Hmm, never thought a match can be used like this before -- in each
> loop, $1 get a new match...
You would have if you head read the documentation.
> Thanks again
You are welcome. However, I see no indication from you that you will be
reading the appropriate documentation, and attempt to solve the problem
on your own in the future. Unfortunately (for you), there are too may
people who exhibit the same (bad) laziness for me to want to see if you
change your attitude.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Wed, 22 Jun 2005 20:29:05 +0000 (UTC)
From: Eli the Bearded <*@eli.users.panix.com>
Subject: module to create Zork like game maps?
Message-Id: <eli$0506221606@qz.little-neck.ny.us>
[note crosspost and follow-ups]
I've tried searching CPAN, but found only one module related to games
and maps, a line of sight calculator. That's not what I'm looking for.
What I am looking for is something to help either draw maps and/or
calculate the moves to get from room A to room B in a Zork (etc) map.
These are connected boxes with eight common directions (north,
northeast, east, southeast, south, southwest, west, northwest) and an
assortment of rarer directions (up, down, in, out, etc). In a few odd
cases the corridors are not straight, and leaving by west from one room
will enter you by south in another. It is often useful to note room names
and items of note in the rooms.
I'm not sure what interface I'd like best to use, but I have a number
of paper maps I want to transfer. Transfering by automatic parsing of
room names and exit directions (when possible, ie unique names and
regular directions) would be nice.
The only thing I've found so far in perl is "informap" from the IF
archive. It draws maps based on reading in game source code, which is
not an option for me.
Anybody know of perl code to help me?
Elijah
------
surprised more game mapping programs aren't out there
------------------------------
Date: Wed, 22 Jun 2005 16:35:23 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: module to create Zork like game maps?
Message-Id: <slrndbjmcr.vrb.tadmc@magna.augustmail.com>
[ note trimmed follow-ups ]
Eli the Bearded <*@eli.users.panix.com> wrote:
> Anybody know of perl code to help me?
Nope, sorry.
> Elijah
But its nice to see you here again!
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 22 Jun 2005 22:13:05 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: module to create Zork like game maps?
Message-Id: <slrndbjojh.3k.dha@panix2.panix.com>
On 2005-06-22, Tad McClellan <tadmc@augustmail.com> wrote:
>
> [ note trimmed follow-ups ]
>
>
> Eli the Bearded <*@eli.users.panix.com> wrote:
>
>> Elijah
>
> But its nice to see you here again!
Indeed! I was just thinking the same thing.
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
DHA is the "Smorax", he is friends with the Twinkies and speaks for
the Choc-O-Diles. - Mark Rogaski
------------------------------
Date: 23 Jun 2005 00:27:20 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: module to create Zork like game maps?
Message-Id: <slrndbk0f8.14f.abigail@alexandra.abigail.nl>
Eli the Bearded (*@eli.users.panix.com) wrote on MMMMCCCXIII September
MCMXCIII in <URL:news:eli$0506221606@qz.little-neck.ny.us>:
`` [note crosspost and follow-ups]
``
`` I've tried searching CPAN, but found only one module related to games
`` and maps, a line of sight calculator. That's not what I'm looking for.
`` What I am looking for is something to help either draw maps and/or
`` calculate the moves to get from room A to room B in a Zork (etc) map.
`` These are connected boxes with eight common directions (north,
`` northeast, east, southeast, south, southwest, west, northwest) and an
`` assortment of rarer directions (up, down, in, out, etc). In a few odd
`` cases the corridors are not straight, and leaving by west from one room
`` will enter you by south in another. It is often useful to note room names
`` and items of note in the rooms.
Calculating a path from one room to another is a standard graph
algorithm (Eulers algorithm will do fine). In the Graph::* modules
found on CPAN, there's something to help you out.
Abigail
--
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";
------------------------------
Date: Wed, 22 Jun 2005 23:14:47 GMT
From: jbl <jblno@spamhotmail.com>
Subject: sort on third, then second field
Message-Id: <80hjb1do9eejijki2g2krvdnaro1ip7ogf@4ax.com>
I have tried several methods and this at least runs, but does nothing.
I am trying to get this to sort by date (third field) then by
description (second field)
#!/usr/bin/perl
use warnings;
use strict;
$/ = "\n";
my @a;
my @b;
open(IN,'C:\sortByDate.txt')
|| die "Cannot open C:\\sortByDate\.txt: $!";
open(OUT,'>C:\sortByDate.tmp')
|| die "Cannot open to write C:\\sortByDate\.tmp: $!";
while (<IN>) {
my @foo = split(/\t/,$_);
my @sorted_foo = sort { lc($a[2]) cmp lc($b[2]) } @foo;
print OUT "$sorted_foo[0]\t"."$sorted_foo[1]\t"."$sorted_foo[2]";
}
sortByDate.txt
4 string description data line 4 05-04-2005
5 string description data line 5 05-25-2005
2 string description data line 2 05-25-2005
7 string description data line 7 04-28-2005
1 string description data line 1 04-28-2005
6 string description data line 6 04-28-2005
3 string description data line 3 04-29-2005
output sortByDate.tmp
4 string description data line 4 05-04-2005
5 string description data line 5 05-25-2005
2 string description data line 2 05-25-2005
7 string description data line 7 04-28-2005
1 string description data line 1 04-28-2005
6 string description data line 6 04-28-2005
3 string description data line 3 04-29-2005
exactly the same
thanks
jbl
------------------------------
Date: Thu, 23 Jun 2005 00:01:02 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: sort on third, then second field
Message-Id: <Xns967DCB9FDCE41asu1cornelledu@127.0.0.1>
jbl <jblno@spamhotmail.com> wrote in
news:80hjb1do9eejijki2g2krvdnaro1ip7ogf@4ax.com:
> I have tried several methods and this at least runs, but does nothing.
> I am trying to get this to sort by date (third field) then by
> description (second field)
Then, you need to do it in one go. You can see this visually by trying
it out with a spreadsheet like Ooo Calc or Excel.
> #!/usr/bin/perl
> use warnings;
> use strict;
Thank you.
> $/ = "\n";
I do not know why you think this is necessary or appropriate, but if it
were, I would suggest
local $/ = "\n";
> my @a;
> my @b;
You don't use these arrays for any purpose.
> open(IN,'C:\sortByDate.txt')
> || die "Cannot open C:\\sortByDate\.txt: $!";
There is no need to escape a dot in a double quoted string. But, thanks
for checking for errors.
> open(OUT,'>C:\sortByDate.tmp')
> || die "Cannot open to write C:\\sortByDate\.tmp: $!";
I am a little confused by your naming scheme for files. Are you thinking
of making one pass to sort by date, and another to sort by description,
or vice versa. In either case, the second pass will mess up the results
of the first pass.
> while (<IN>) {
> my @foo = split(/\t/,$_);
> my @sorted_foo = sort { lc($a[2]) cmp lc($b[2]) } @foo;
This is a huge problem. You read one line at a time. @foo cannot hold
anything other than or the individual components of *one* line. This
cannot sort the whole data set.
> print OUT "$sorted_foo[0]\t"."$sorted_foo[1]\t"."$sorted_foo[2]";
> }
I am going to show you a rather inefficient but simple way of doing
this. Armed with this, you can search for 'Schwartzian Transform' and
also take a look at Uri Guttman's Sort::Maker module.
#!/usr/bin/perl
use warnings;
use strict;
my @data;
# I iterate line by line rather than slurping because
# I want to stop on encountering an empty line and also
# do some of the processing up front.
while(<DATA>) {
chomp;
last unless length;
if(my @fields = ( /^(\d)\t(.+)\t(\d\d)-(\d\d)-(\d\d\d\d)$/ ) ) {
push @data, \@fields;
}
}
@data = sort comparator2 @data;
for (@data) {
printf "%d\t%s\t%2.2d-%2.2d-%4.4d\n", @$_;
}
# Note that the acrobatics below would not have been
# necessary if dates were in YYYYMMDD format.
sub comparator2 {
my $r;
unless($r = ($a->[4] <=> $b->[4])) {
unless($r = ($a->[2] <=> $b->[2])) {
$r = ($a->[3] <=> $b->[3]);
}
}
return $r ? $r : ($a->[1] cmp $b->[1]);
}
__DATA__
4 string description data line 4 05-04-2005
5 string description data line 5 05-25-2005
2 string description data line 2 05-25-2005
7 string description data line 7 04-28-2005
1 string description data line 1 04-28-2005
6 string description data line 6 04-28-2005
3 string description data line 3 04-29-2005
D:\Home\asu1\UseNet\clpmisc> ttt
1 string description data line 1 04-28-2005
6 string description data line 6 04-28-2005
7 string description data line 7 04-28-2005
3 string description data line 3 04-29-2005
4 string description data line 4 05-04-2005
2 string description data line 2 05-25-2005
5 string description data line 5 05-25-2005
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Wed, 22 Jun 2005 14:37:06 -0400
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: Re: what's the right way to encode this?
Message-Id: <1119465428.ec3b1318ceaee5e0ca785b822acda62d@teranews>
On Tue, 21 Jun 2005 21:11:38 -0400, * Tong * wrote:
> I notice that I make a mistake ...
I now realize it is an entirely different issue -- a bug in tidy, which
has nothing to do with my Perl code.
--
Tong (remove underscore(s) to reply)
*niX Power Tools Project: http://xpt.sourceforge.net/
- All free contribution & collection
------------------------------
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 8193
***************************************