Re: Zip/Postal codes.
On Thu, 2 Jan 2003 16:02:04 +0100, [EMAIL PROTECTED] (Marius Ascheberg) wrote: For all other countries, I've nothing so far. Can anyone help? http://www.uni-koeln.de/~arcd2/3d.htm http://www.columbia.edu/kermit/postal.html , by the Kermit people, may also be of interest. Cheers, Philip
Re: sort numbers
On 01 Jan 2003 21:54:25 -0800, [EMAIL PROTECTED] (Randal L. Schwartz) wrote: Philip == Philip Newton [EMAIL PROTECTED] writes: Philip You're not allowed to compare numbers? That will make it difficult to Philip find out when the list is sorted. use ESP::Psychic qw(infer_sortedness); Ah! Easy, then. use ESP::Psychic qw(infer_sortedness); sub bogosort { do { rotate_sequential (start = rand($#_ - 3)); } while(! infer_sortedness); } Cheers, Philip
Re: sort numbers
On Thu, 2 Jan 2003 12:41:38 -0800 (PST), [EMAIL PROTECTED] (Artist Google) wrote: Well, I am not looking for randomly achieved solutions. and looking for minimum steps to achieve solution. I thought that was obvious. I was being sarcastic. I thought *that* was obvious. Cheers, Philip
Re: sort numbers
On Wed, 1 Jan 2003 13:02:58 -0800 (PST), [EMAIL PROTECTED] (Artist Google) wrote: Hi, I have this puzzle. Given N numbers, N4, you have to sort the numbers. The only operation permitted is you can rotate any sequencial 4 numbers in reverse order. or you can roate the entire list sequencially. You're not allowed to compare numbers? That will make it difficult to find out when the list is sorted. Cheers, Philip
Re: Function parameter passing (was: Re: limit the list)
On Wed, 20 Nov 2002 10:35:11 -0600, [EMAIL PROTECTED] (Steven Lembark) wrote: -- Andrew Molyneux [EMAIL PROTECTED] I'd probably do: my ($max, $sep, $end) = @_; Yes, becuase if you did it this way you'd get $end equal to the integer coult of the number of list arguments passed plus one for the end value. Huh? $end gets assigned $_[2]. I'm not sure where you get an integer coult from. Notice the usage: my $string = commify 90, ', ', 'etc...', @names; Those parameters get flattened into a list @_. @names doesn't know that there's an assignment to a scalar in the subroutine; it gives up its identity and becomes part of the list. And anyway, it's a list context assignment. The first three elements of @_ get assigned to $max, $sep, and $end (respectively); all further elements get ignored. Similar to my ($ss, $mm, $hh) = localtime; or my ($foo, $bar, baz) = (1 .. 10); The other problem is that even if there were only three arguments being passed in you have to check the count before making the assignment and croak on @_ != 3 in order to avoid an extra parameter causing $end to become an integer count. Why? IDGI. Cheers, Philip
Re: Fwd: Re: interesting typo I couldn't see
On 17 Feb 02, at 11:05, Patrik Grip-Jansson wrote: On Sun, 17 Feb 2002, Philip Newton wrote: Well, not really C since you rely on '//' introducing a comment-to-end-of-line. That's a C++-ism which some C compilers support but which isn't part of the C standard. No, you're wrong there. Using '//' as a comment is a part of the C standard. Have a look at a recent version, for example the one at; http://www.cl.cam.ac.uk/~mgk25/volatile/ISO-C-FDIS.1999-04.txt Possible. OK, I'll then say it's not part of the ANSI C standard as that phrase is usually understood (e.g. that which is documented in KR's _The C Programming Language_, 2nd edition). There aren't a whole lot of compilers implementing C99 (or whatever it's called) yet. Cheers, Philip -- Philip Newton [EMAIL PROTECTED]
Re: Explanation of my 189-stroke Perl-is-C;C-is-Perl entry
On Sun, 17 Feb 2002 12:02:43 -0800, [EMAIL PROTECTED] wrote: On Sun, Feb 17, 2002 at 07:35:24AM +0100, Philip Newton wrote: On Sun, 17 Feb 2002 09:42:55 +1100, [EMAIL PROTECTED] (Andrew Savige) wrote: you have a choice of 3 different languages (Perl, C or C++). ^.^ Well, not really C since you rely on '//' introducing a comment-to-end-of-line. That's a C++-ism which some C compilers support but which isn't part of the C standard. oh yes it is. Ok, let me re-phrase: it's not ANSI C, as in KR 2nd ed. Cheers, Philip
Re: Explanation of my 189-stroke Perl-is-C;C-is-Perl entry
On Sun, 17 Feb 2002 11:55:27 +0100, [EMAIL PROTECTED] (Peter Makholm) wrote: Philip Newton [EMAIL PROTECTED] writes: Well, not really C since you rely on '//' introducing a comment-to-end-of-line. I cannot find the C99 standard. But it looks like '//' was introduced as comment-to-end-of-line in ISO 9899-1999 (aka. C99). So only if you see KR as the One True Authority the above is true. Well, existing compilers tend to be slow to implement new standards such as C99 So for my purposes, standard C is ANSI C i.e. KR 2nd ed.. YMMV. Cheers, Philip
RE: Explanation of my 189-stroke Perl-is-C;C-is-Perl entry
On 18 Feb 02, at 10:46, [EMAIL PROTECTED] wrote: Philip Newton wrote: Well, existing compilers tend to be slow to implement new standards such as C99 So for my purposes, standard C is ANSI C i.e. KR 2nd ed.. YMMV. Interestingly, in this particular case, many vendors are very *quick* to implement, often implementing before it happened. :) Translation: The two dominant C compilers, gcc and Microsoft MSVC, both supported // comments in C long before the C99 standard. I suspect this is because they make both C and C++ compilers and it is easier to share a single comment-stripper for both. Possible. I know that Borland Turbo C on the PC supported //-style comments in 1992; however, that was also a combined C/C++ compiler (at least the version I had -- earlier versions did C only and I don't know whether they supported //-style comments). But remember that all the world's not a gcc. I don't know how much luck you'd have an Solaris's or HP-UX's cc. Cheers, Philip -- Philip Newton [EMAIL PROTECTED]
Re: Fwd: Re: interesting typo I couldn't see
On Sat, 16 Feb 2002 11:05:14 -0800, [EMAIL PROTECTED] (Vicki Brown) wrote: It took me a while to find the problem... when I did I was somewhat amused --- Begin Forward --- if (...) { my @item_parts = split(/\n/, $item); printf ORDER (\n%4d %-50s %3.2f %3.2f\n, $quantity, $item_parts[0], $price, $ext); } else { printf ORDER (\n%4d %-50s %3.2f %3.2f\n, } $quantity, $item, $price, $ext); --- End Forward --- I had to look a couple of times, too. Cheers, Philip
Re: Golf and the Perl Review
On Fri, 8 Feb 2002 09:33:01 -0500, [EMAIL PROTECTED] (Bill -Osx- Jones) wrote: Not to be dumb as a stump, but are you saying that - under Win32 - STDERR would not appear in the console window? That, because of possibly internal Win32 issues, it must always be sent to a file? What I think he is saying is that, on Win9x (*not* NT or 2000 under cmd.exe, which is a bit more powerful than Win9x's command.com), * if you do nothing, then STDERR appears on the console. Your Perl script does not capture it even if you (try to) use something like `foo.exe 21`. (Instead, you're likely to end up with a file called '1'.) * if you try to redirect STDERR to a tied handle or to STDOUT before starting an external program (with backticks or system, for example), you're still not going to capture the application's STDERR. (I'm not sure where they end up -- whether on the console as before, or in nirvana.) * if you redirect STDERR to a file (or to another filehandle which ultimately points to a file), then the spawned application's STDERR messages will end up in the file, which can be examined programmatically -- not quite as convenient as having them show up in the result of `command 21` but at least (a) they don't clutter up the console display, and (b) you're able to ascertain whether any output went to STDERR during the execution of the program. Bart may correct me if I'm wrong. Cheers, Philip
Re: substitution question
On Sat, 02 Feb 2002 22:24:05 +0100, [EMAIL PROTECTED] (Bart Lateur) wrote: On Sat, 2 Feb 2002 12:35:13 -0800 , Pradeep Sethi wrote: and I want to use regexp , without using sprinf. !?!?!! WTF is wrong with sprintf()? It's a proper tool for this job. Next you'll want to replace 13.57831 by 13.58 without using sprintf(). This reminded me of something I read on http://perl.plover.com/Questions.html : The flip side of this is a question like ``I want to accomplish X, but I don't want to use Y. What can I use instead?'' Which, again, is sometimes reasonable, and then sometimes X is closing a filehandle and Y is the `close' function. The paragraph before that is also interesting in this context; and see also http://perl.plover.com/Questions3.html . Cheers, Philip
Re: Better ?
On Thu, 24 Jan 2002 14:58:09 -0500, [EMAIL PROTECTED] (Michael G Schwern) wrote: On Thu, Jan 24, 2002 at 11:24:47AM -0500, Bill -OSX- Jones wrote: $c = grep {/[osx]/i} @_; Regardless, the {} there is redundant and actually slows you down a bit (Perl has to enter/leave that block on each element which isn't cheap and its not smart enough to optimize it out. But you can't just take them off since you'd need to put a comma in then: $c = grep /[osx]/i, @_; or perhaps even $c = grep /[osxOSX]/, @_; ISTR someone saying that matching /[fF][oO][oO]/ was better than /foo/i, but that might be apocryphal; I'm not sure which effect, if any, that would have on the relative speeds of /[osx]/i and /[osxOSX]/. Cheers, Philip
Re: Golf challenge: decode CETI message
On Wed, 9 Jan 2002 20:34:30 -0500, [EMAIL PROTECTED] (Keith C. Ivey) wrote: But s'\x0\xff' @' to make it shorter and more visible on my system. y(s))y) ? Cheers, Philip
Re: test a password string for correctness
On Thu, 13 Dec 2001 18:10:26 -0500, [EMAIL PROTECTED] (Ryan Fischer) wrote: This should do it I think: /[a-zA-Z]/==3/[0-9]/==2/^.{5,}$/; Pattern match in scalar context returns true or false, so the maximum number is 1. You'll never get 3 out of a pattern match in scalar context (and == forces scalar context). Cheers, Philip
Re: test a password string for correctness
On Thu, 13 Dec 2001 19:25:02 -0500 (EST), [EMAIL PROTECTED] (Jeff 'Japhy' Pinyan) wrote: I'd probably include capitalized operators in the obscure group Which capitalised operators? NE, LT, and friends? I think they went away in bleadperl... didn't they? Cheers, Philip
Re: test a password string for correctness
On Thu, 13 Dec 2001 10:50:11 -0500, [EMAIL PROTECTED] (Ronald J Kimball) wrote: (y/a-zA-Z// 2) (y/0-9// 1) Each numeric comparison will return either 1 or 0. In my experience, 1 or , rather than 1 or 0. Or is FALSE (PL_NO?) a special value which looks like 0 to operators that care, such as bitwise-and? Cheers, Philip
Re: Santa Hole 4 (mid.pl) Post Mortem
On Fri, 7 Dec 2001 10:58:03 +1100 , [EMAIL PROTECTED] (Andrew Savige) wrote: *** Hole 4 (mid.pl) *** --- Piers Cawley - 25 #!/usr/bin/perl -p0 $_=$1while/.(^.+)^/ms --- Rick Delaney - 25 #!/usr/bin/perl -p0 $_=$1while/.^(.+)^/sm --- Karsten Sperling - 25 #!/usr/bin/perl -p0 $_=$1while/.(^.+^)/sm --- Eugene van der Pijll - 25 #!/usr/bin/perl -p0 $_=$1while/.^(.+)^/ms --- Keith C Ivey - 25 #! /usr/bin/perl -p0 $_=$1while/.(^.+)^/ms Interesting how different people liked that ^'s in different places :) (Though it doesn't really matter since it's zero-length, so putting it inside or outside the capturing parens doesn't affect what gets matched. Might make a small speed difference due to the the effect of leaving the capturing parens and possibly re-entering them on backtracking, I suppose.) Cheers, Philip
Re: The Santa Claus Golf Apocalypse
On Tue, 4 Dec 2001 22:33:45 +0100 (CET), [EMAIL PROTECTED] (Philippe 'Book' Bruhat) wrote: it's straightforward Perl, as documented in Amelia What's Amelia? Cheers, Philip
Re: tri-state flags
On Thu, 06 Dec 2001 13:46:41 +0100, [EMAIL PROTECTED] (Bart Lateur) wrote: Also intersting to note is its behaviour WRT perl booleans. As you know, (or should know ;-)), is that these have a dual nature: a boolean false is 0 in numerical context, and in string context. Well, apparently ~ thinks of it as a number. I suppose it depends on the order in which the appropriate code behind the ~ operator tests -- if it's if(num) {...} elsif(string) {...} you'll obviously get diffferent results than from if(string) {...} elsif(num) {...} for variables which have both the is-num and is-string bit turned on. Cheers, Philip
Re: middle line, redux
On Sun, 2 Dec 2001 13:49:04 + (GMT), [EMAIL PROTECTED] (Jonathan e. paton) wrote: I honestly think I've found the only true solution, which is: perl -p Hm? How does this print only the middle line of a file? Cheers, Philip
Re: isprint Golf Challenge
On Fri, 16 Nov 2001 23:02:57 -0500, in perl.fwp you wrote: foreach my $num (0..255) { my $chr = chr $num; $U2P{$chr} = $chr =~ tr/\x20-\x7F// ? $chr : '\\'.sprintf(%03o,$num); } That should be \x20-\x7E, I think. \x7F is a control character (DEL, \c?). Cheers, Philip
Re: isNumber( ) ??
On Fri, 19 Oct 2001 18:05:54 +0100, [EMAIL PROTECTED] (Piers Cawley) wrote: #!/usr/bin/perl6 sub is_number ($number) { return +$number eq 'NaN' } s/eq/ne/ ? Cheers, Philip