Re: limit the list

2002-11-19 Thread A. Pagaltzis
* Selector, Lev Y <[EMAIL PROTECTED]> [2002-11-20 00:55]: > an array of names is converted into a comma-separated list. > if the list gets to long - limit it and add ", etc." at the end. > > $str = join ', ', @names; > if (length($str)>90) { > ($str = substr($str,0,90)) =~ s/,[^,]*$/,

Re: limit the list

2002-11-19 Thread A. Pagaltzis
* A. Pagaltzis <[EMAIL PROTECTED]> [2002-11-20 02:00]: > my ($i, $total); > ($total += $_) < 90 or last, $i++ for map length, @names; > $str = join ',', @names[0 .. $i]; > $str .= ', etc' if $i < $#names; Sorry, that would of course be ($total += leng

Re: limit the list

2002-11-19 Thread A. Pagaltzis
Ok, another attempt, this time with brain engaged and coffee consumed. > $str = join ', ', @names; > if (length($str)>90) { > ($str = substr($str,0,90)) =~ s/,[^,]*$/, etc./; > } my ($i, $total); ($total += length) < 90 ? $i++ : last for @ARGV; $str = join ', ', @ARGV[0 .. $i]; $str .= ', etc

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread A. Pagaltzis
* Andrew Molyneux <[EMAIL PROTECTED]> [2002-11-20 12:47]: > You're not the only one. I'd probably do: > my ($max, $sep, $end) = @_; me too > but I'd love to know if Steven had a specific reason > for doing it the other way. There doesn't seem to be any here. -- Regards, Aristotle

Re: limit the list

2002-11-20 Thread A. Pagaltzis
* Steven Lembark <[EMAIL PROTECTED]> [2002-11-20 12:47]: > map > { > $sum < $cut ? > > ( ($sum += $sln + length) < $cut ? $_ : $end ) > : > () > } Wasted work. Two comparisons per element and you don

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread A. Pagaltzis
* Steven Lembark <[EMAIL PROTECTED]> [2002-11-20 17:35]: > 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. Notice the usage: > > my $string = commify 90, ', ', 'etc...', @names; > > The othe

Re: limit the list

2002-11-20 Thread A. Pagaltzis
* Steven Lembark <[EMAIL PROTECTED]> [2002-11-20 17:35]: > > Wasted work. Two comparisons per element and you don't bail > > once you've filled your available space. > > Two comparisons on a short list, at which point the remainder > of them are a simple comparison to get a () out, which ends > up

Re: limit the list

2002-11-20 Thread A. Pagaltzis
* Josh Goldberg <[EMAIL PROTECTED]> [2002-11-20 19:20]: > map{$i++<$lim?push @n,$_:$i!=$lim?{push @n,'etc.' and goto FOO}:''}@names; Sigh. map in void context and goto where a for would have done. And it doesn't even conform to the specs, you were asked to provide a string with less than 90 charac

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread A. Pagaltzis
* Steven Lembark <[EMAIL PROTECTED]> [2002-11-20 20:51]: > Look up what happens to arrays in a scalar context. > > my ( $a, $b, $c ) = qw( foo bar bletch blort bim bam blort ); > > what do yo get for $c? 'bletch' - and that's not an array there. -- Regards, Aristotle

Re: limit the list

2002-11-20 Thread A. Pagaltzis
* Jonathan E. Paton <[EMAIL PROTECTED]> [2002-11-20 20:51]: > if (@array > $bound) { > $array[$bound-1] = ", etc"; # Set element at boundary > $#array = $bound-1; # Shorten array to boundary > } > > print join ", ", @array; Again, that's the same as: join ', ', @array[0 .. $boun

Re: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread A. Pagaltzis
* Andrew Molyneux <[EMAIL PROTECTED]> [2002-11-20 18:25]: > A. Pagaltzis wrote: > > Enter splice. > > > > my ($max, $sep, $end) = splice @_, 0, 3; > > That has brevity, certainly, but for legibility, I think I > prefer Steven's original (shift,shift,shift)

Re: limit the list

2002-11-20 Thread A. Pagaltzis
* Jonathan E. Paton <[EMAIL PROTECTED]> [2002-11-20 21:15]: > > join ', ', @array[0 .. $bound], @array > $bound ? 'etc' : (); > > No, it's not. In my way the effects on the array are > permanent, although that's probably not useful in this > instance Point taken. @array = @array[0 .. $bound], @

Re: limit the list

2002-11-20 Thread A. Pagaltzis
* Steven Lembark <[EMAIL PROTECTED]> [2002-11-20 21:45]: > > but, the code said: > > > > $str = join ', ', @names; > > if (length($str)>90) { > > ($str = substr($str,0,90)) =~ s/,[^,]*$/, etc./; > > } > > Original doesn't mention if the "etc." should fall w/in > the

Re: limit the list

2002-11-20 Thread A. Pagaltzis
* Jonathan E. Paton <[EMAIL PROTECTED]> [2002-11-20 21:40]: > You mean like the original poster wanted 90 chars, not 90 > elements? Yes, and the first (working) snippet I posted does that, with the least amount of tokens and highest efficiency and I believe also greatest clarity of all solutions p

Re: limit the list

2002-11-20 Thread A. Pagaltzis
* Dave Arnold <[EMAIL PROTECTED]> [2002-11-21 02:45]: > $str = join ', ', @names; > if ( length($str) > 90 ) > { > substr($str,rindex($str,",",90)) = ", etc."; > } Nice, and so obvious too - in retrospect, of course. The only thing I don't like about it is it still joins everything, even if it

Re: limit the list

2002-11-20 Thread A. Pagaltzis
* Jonathan E. Paton <[EMAIL PROTECTED]> [2002-11-20 23:10]: > Solution: It doesn't. I am duly admonished. You're right. -- Regards, Aristotle

Re: Function parameter passing (was: Re: limit the list)

2002-11-25 Thread A. Pagaltzis
* Bart Lateur <[EMAIL PROTECTED]> [2002-11-25 09:10]: > It is because it comes into the realm of undefined > behaviour. What it does is execution-order dependent, in > the least. Ah, but in Perl, this order is defined. The following is guaranteed to work: select((select(FH), $|++)[0]); If the or

Re: my in conditionals

2002-11-27 Thread A. Pagaltzis
* Paul Makepeace <[EMAIL PROTECTED]> [2002-11-27 08:53]: > perl apparently doesn't consider $d exists by the second $d and issues > an error. Can someone explain this? (Esp. in light of all this sequence > point talk.) The entire statement ist compiled at a time; at this time, $d is undeclared. Th

Re: fun with regex

2002-12-11 Thread A. Pagaltzis
* Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> [2002-12-12 07:32]: > While it's cool, and I'D use it, for readability purposes, > might I suggest: > > $sql =~ /(\s*)/ and $sql =~ s/^$1//mg; How about /^(\s*)/ - better safe than sorry. On second thought, /^(\s*|)/ to avoid warnings. -- Regards, Ar

Re: fun with regex

2002-12-12 Thread A. Pagaltzis
* Abigail <[EMAIL PROTECTED]> [2002-12-12 15:28]: > > On second thought, /^(\s*|)/ to avoid warnings. > > What kind of warning? Do you know of a string where > /^(\s*)/ doesn't match? Perhaps a string without a > beginning? Or that has -1 space at the beginning? Yeah, I realized that about 20 mi

Re: Metaprogramming

2002-12-13 Thread A. Pagaltzis
* Simon Cozens <[EMAIL PROTECTED]> [2002-12-13 14:55]: > Oh no! You mean it'll only work in non-pathological cases? > That's no good! Its inability to deparse a closure such that its bound lexicals and their values can be recreated is sometimes a serious hindrance. It works well enough and then so

Re: grep substitute

2002-12-14 Thread A. Pagaltzis
* Scott Wiersdorf <[EMAIL PROTECTED]> [2002-12-14 13:01]: > perl -n0777 > exit !(/pattern/) > > Necessary Improvements: > > - concisely get the pattern from the command-line (e.g., pattern as > $ARGV[0] and the file as $ARGV[1]) such that the syntax is more like > grep (e.g., grep 'pattern' f

Re: Zip/Postal codes.

2003-01-02 Thread A. Pagaltzis
* Abigail <[EMAIL PROTECTED]> [2003-01-02 16:08]: > For all other countries, I've nothing so far. Can anyone > help? For Germany, it's a simple \d{5} - any digit including zero allowed at any position, and all five places must be given. -- Regards, Aristotle

Re: Converting a textfile-like string to an array and back

2003-02-07 Thread A. Pagaltzis
* Andrew Savige <[EMAIL PROTECTED]> [2003-02-07 13:47]: > my @lines = split(/^/, $x, -1); chomp(@lines); # fastest? my @lines = split m[\Q$/], $x, -1; -- Regards, Aristotle

Re: Converting a textfile-like string to an array and back

2003-02-07 Thread A. Pagaltzis
* John Douglas Porter <[EMAIL PROTECTED]> [2003-02-07 14:15]: > @lines = split /\n/, $x, -1; pop @lines; $/ can be different from \n though. And popping the last field is dangerous - you don't know if the file ends with a newline. Also, you now have no chance to reconstruct the exact equivalent

Re: Converting a textfile-like string to an array and back

2003-02-07 Thread A. Pagaltzis
* John Douglas Porter <[EMAIL PROTECTED]> [2003-02-07 14:50]: > Yes, but his example data was text in a here document. Then add a note about the caveat. > split m,$/, $x, -1; In bizarre cases, $/ might contain regex metacharacters. Don't forget the \Q. > > And popping the last field is danger

Re: Converting a textfile-like string to an array and back

2003-02-07 Thread A. Pagaltzis
* Yitzchak Scott-Thoennes <[EMAIL PROTECTED]> [2003-02-07 20:51]: > chomp(my $tmp=$x); my @lines=split /\n/,$tmp,-1 Very nice. -- Regards, Aristotle

Re: Converting a textfile-like string to an array and back

2003-02-09 Thread A. Pagaltzis
* John W. Krahn <[EMAIL PROTECTED]> [2003-02-09 12:27]: > You can also speed up j1 by using map without the braces. > > sub j1 { my @lines = map chomp && $_, split /^/, $x, -1 } Which will promptly fail on a last line without a trailing record separator because chomp would return 0 and cause the

Re: Converting a textfile-like string to an array and back

2003-02-09 Thread A. Pagaltzis
* Andrew Savige <[EMAIL PROTECTED]> [2003-02-10 07:28]: > @lines = ($x=~/^.*/mg) x !!length($x); $_=$x;@lines=(/^.*/mg)x+length; -- Regards, Aristotle

Re: Converting a textfile-like string to an array and back

2003-02-10 Thread A. Pagaltzis
* Andrew Savige <[EMAIL PROTECTED]> [2003-02-10 17:54]: > *whistle* *whistle* *red card* *disqualified* > multiplying by length (x+length) will not give the desired > result here; it must be boolean (0 or 1 only). Doh! Of course. I'm an idiot. *grmbl* -- Regards, Aristotle

Re: Converting a textfile-like string to an array and back

2003-02-10 Thread A. Pagaltzis
* Eugene van der Pijll <[EMAIL PROTECTED]> [2003-02-10 18:35]: > Unfortunately, you had "use strict" in your first post, > and neither of these are use-strict safe. Oh? What makes you say so? -- Regards, Aristotle

Re: When the Schwartzian Transform gets out of control...

2003-02-11 Thread A. Pagaltzis
Sorting 1000 items involves a _lot_ more than 1000 comparisons - which is really all you need. If you insist on your approach you should memoize vercmp() or use the orcish maneuver in your sort() callback. (Memoizing will accelerate it across all of your script, but the orcish maneuvre will accele

Re: When the Schwartzian Transform gets out of control...

2003-02-11 Thread A. Pagaltzis
* A. Pagaltzis <[EMAIL PROTECTED]> [2003-02-12 07:35]: > and -1 == vercmp($2,$3, @{$installed{$_}}); That is, of course, and -1 == vercmp($2,$3, @{$installed{$1}}); -- Regards, Aristotle

Re: Fun with RegExps

2003-02-17 Thread A. Pagaltzis
Alternatively it can be done with negative lookaheads. print "ok" if /^(?![a-z0-9]+$)(?![A-Z0-9]+$)(?![a-zA-Z]+$)[\w-]{6,14}$/; -- Regards, Aristotle

Re: Fun with RegExps

2003-02-17 Thread A. Pagaltzis
Sorry, too quick a copypaste: print "ok" if /^(?![a-z0-9]+$)(?![A-Z0-9]+$)(?![a-zA-Z]+$)[A-Za-z0-9]{6,14}$/; -- Regards, Aristotle

Re: Fun with RegExps

2003-02-18 Thread A. Pagaltzis
* Abigail <[EMAIL PROTECTED]> [2003-02-18 12:30]: > Both "__" and "--" match the given regexp, but > fail the stated requirements. I know; I tested with the right version but forgot to fix my mail before sending, therefor my corrective post five post minutes later. -- Regards, Aristotle

Re: Fun with RegExps

2003-02-18 Thread A. Pagaltzis
* Abigail <[EMAIL PROTECTED]> [2003-02-18 12:30]: > > 5. Optionally, it can cover for accepted non-alphanumeric chars such as > > "_", "-" etc (but not "#"), and a maximum password length of 14 > > characters > > (?=.*[-_]) # Contains a dash or an underscore. The way I read that requir

Re: grep too slow

2003-02-23 Thread A. Pagaltzis
Try this. Untested. $t->start('transforming2'); my $i; for(@list) { $i = $_->{'info'}; push @info, $i; push @{$hash{$i}}, $_; } @found3 = map pop @{$hash{$_}}, amatch('3456', @info); $t->stop; -- Regards, Aristotle

Re: grep too slow

2003-02-24 Thread A. Pagaltzis
Still untested: * A. Pagaltzis <[EMAIL PROTECTED]> [2003-02-23 17:50]: > @found3 = map pop @{$hash{$_}}, amatch('3456', @info); That should rather read @found3 = map shift @{$hash{$_}}, amatch('3456', @info); The point is that the order of identical items in the

Re: my if?

2003-07-01 Thread A. Pagaltzis
* Bernie Cosell <[EMAIL PROTECTED]> [2003-07-01 18:39]: > Perl is filled with multiple ways to do things and the simple > argument that you can do something similar using some other > mechanism is rarely determinative. "...but I hesitate to make ten ways to do it." -- Larry Wall -- Regards, Aris

Re: my if?

2003-07-02 Thread A. Pagaltzis
* Pense, Joachim <[EMAIL PROTECTED]> [2003-07-02 14:15]: > You can write > > if ($some_condition) { >do_this; >do_that; >do_something_else; > } > > and you can write > > do_this if $some_condition; > > You need not write > > if ($some_condition) {do_this} You can also write do {

Re: [OT] t/badfile....FAILED test 3

2003-07-14 Thread A. Pagaltzis
That's no fun. -- Regards, Aristotle

Re: Is this fun?

2003-07-15 Thread A. Pagaltzis
* Jon Bjornstad <[EMAIL PROTECTED]> [2003-07-15 00:00]: > I don't often get to use the '.' operator or the 'x' operator > and I thought this was pretty cool. Pretty standard fare for some people, though I guess the exact idea of fun is different for everyone. :) > There are a few flaws with the a

Re: Is this fun?

2003-07-15 Thread A. Pagaltzis
* Keith C. Ivey <[EMAIL PROTECTED]> [2003-07-15 14:42]: > which will be handled by the regex but may cause a parser to > blow up (though some are more tolerant than others) Did you read what I said? You need a tolerant parser indeed. Did you take any look HTML::Parser at all? > | That leaves inpu

Re: merlyn smeared by Python Johnnies' description of Schwartzian transform

2003-07-16 Thread A. Pagaltzis
* Abigail <[EMAIL PROTECTED]> [2003-07-16 11:33]: > Yes. GRT usually have the form: > > @sort = map { ... } > sort > map { ... } @unsorted; > > with often pack/unpack in the map blocks, while an ST is > usually structured as: > > @sort = map {$_ -> [0]} >

Re: Fun - Each character at most once

2003-07-17 Thread A. Pagaltzis
* [EMAIL PROTECTED] <[EMAIL PROTECTED]> [2003-07-17 21:15]: > > What is the most "interesting" program that is restricted to > > use each ASCII character at most once? > > The definition I chose was to check if a program (from @ARGV) > contains duplicate chars and printing a duplicate char iff it

Re: Fun - Each character at most once

2003-07-25 Thread A. Pagaltzis
* Adam Rice <[EMAIL PROTECTED]> [2003-07-22 16:02]: > I wrote a program to generate these, but has an unfun tendency > to take forever when the solution is non-trivial so I won't > post it. If there was a better technique than brute force to > find the answers that might be fun, but I just can't ge

Re: Phalanx top 100 CPAN modules golf

2003-08-25 Thread A. Pagaltzis
* Andrew Savige <[EMAIL PROTECTED]> [2003-08-24 04:27]: > the Klement Transform? Or should that read Klementian or even > Klementine Transform? :-) Well, it's not called the Guttman-Roslerian Transform (or Guttmanian-Roslerian?) either. "Schwartzian" is really a red herring. -- Regards, Aristot

Re: Semcarlbd letrtes sepur! (Scrambled letters super!)

2003-09-18 Thread A. Pagaltzis
* Etienne Grossmann <[EMAIL PROTECTED]> [2003-09-18 09:29]: > I hared a sutdy has been dnoe on taht scjebut in an Eigslnh > urtiivesny, but I coannt get hold of it. Any ionirmtfoan on > that sceujbt is welomce. http://www.bisso.com/ujg_archives/000224.html > perl -pe 'sub r{join"",map chop,sort

Re: Semcarlbd letrtes sepur! (Scrambled letters super!)

2003-09-18 Thread A. Pagaltzis
* Kripa Sundar <[EMAIL PROTECTED]> [2003-09-18 15:41]: > The following does guarantee re-ordering. How does it reorder "loop"? :-) -- Regards, Aristotle "If you can't laugh at yourself, you don't take life seriously enough."

Re: Semcarlbd letrtes sepur! (Scrambled letters super!)

2003-09-19 Thread A. Pagaltzis
* Xavier Noria <[EMAIL PROTECTED]> [2003-09-19 15:07]: > What about > > -p s!\B\w+\B!join"",sort{.5<=>rand}$&=~/./g!ge > > Would that be considered random enough? http://www.perlmonks.org/index.pl?node_id=199981 -- Regards, Aristotle "If you can't laugh at yourself, you don't take life s

Re: lvalue hash slice

2003-09-30 Thread A. Pagaltzis
* Gaal Yahas <[EMAIL PROTECTED]> [2003-09-30 20:14]: > Sadly, this doesn't work as an lvalue: > @hash{ qw/aaa bbb ccc/ } = ($one, $two, $three); I use that *all* the time. The problem is not with Perl here.. -- Regards, Aristotle "If you can't laugh at yourself, you don't take life serious

Re: lvalue hash slice

2003-09-30 Thread A. Pagaltzis
* Gaal Yahas <[EMAIL PROTECTED]> [2003-09-30 22:01]: > Has this always worked? I coulda sworn I tried it in the past > with no luck... It has always worked since I started Perl (sometime around 5.4). I'd make an educated guess that it has been available at least as long as C<(LIST)[EMAIL PROTECTE

Re: lvalue hash slice

2003-10-03 Thread A. Pagaltzis
* Gaal Yahas <[EMAIL PROTECTED]> [2003-10-03 11:24]: > Two points about this. First, the lvalue ?: is kinda, uh, > Perlish to the extreme. Yeah. It tends to be a powerful obfuscant too. I had to look thrice at your code (then went "oh, duh!"). For more than two or maybe three lvalues to switch bet

Re: Comparing items from multiple files

2003-11-21 Thread A. Pagaltzis
* Peter Scott <[EMAIL PROTECTED]> [2003-11-20 11:52]: > my $regex = shift; > my %data; > while (<>) > { > next unless /$regex/; > $data{$ARGV}{$1}++; > } > > for my $outer (keys %data) > { > my @others = grep $_ ne $outer => keys %data; > for my $inner (keys %{$data{$outer}}) > { > f

Re: lwall snippet

2004-04-10 Thread A. Pagaltzis
* Etienne Grossmann <[EMAIL PROTECTED]> [2004-04-11 03:19]: > On Sat, Apr 10, 2004 at 08:56:26PM -0400, [EMAIL PROTECTED] wrote: > > last|perl -pe '$_ x=/(..:..)...(.*)/&&"'$1'"ge$1&&"'$1'"lt$2' > > That's gonna be tough for Randal to beat... :-) > >-- Larry Wall in <[EMAIL PROTEC

Re: lwall snippet

2004-04-11 Thread A. Pagaltzis
* [EMAIL PROTECTED] <[EMAIL PROTECTED]> [2004-04-11 07:12]: > I see. But I think you meant > >$_ x= /(..:..)...(.*)/ && 'foo' ge $1 && 'foo' lt $2; > > since the shell's $2 is never used, as far as I can tell. Sorry, yes of course. -- Regards, Aristotle "If you can't laugh at yourse

Re: fractional cents

2004-04-19 Thread A. Pagaltzis
* Bernie Cosell <[EMAIL PROTECTED]> [2004-04-19 17:37]: > So: what I want is something to format money correctly, whther > it is fractional or not. there's the fairly awful: > > sprintf ($amt =~ /\.\d\d\d/? "%7.3f": "%7.2f"), $amt Right off the bat I thought of %g, but that doesn't really h

(OT) Is the fwp list unreliable?

2004-04-19 Thread A. Pagaltzis
Hi all, sorry for the offtopic mail, but does anyone else have problems getting mails sent to this list? It is often the case that I will not get a thread's initial mail and quite common that half the thread's later mails won't arrive either. I saw there is an NNTP interface; is that postable? Is

Re: fractional cents

2004-04-19 Thread A. Pagaltzis
* Quantum Mechanic <[EMAIL PROTECTED]> [2004-04-19 23:09]: > --- "A. Pagaltzis" <[EMAIL PROTECTED]> wrote: > > my $amt_str = sprintf "%7.3f", $amt; > > for($amt_str) { chop if /\.\d\d0\z/ } > > Why would you do "for..chop&

Re: fractional cents

2004-04-20 Thread A. Pagaltzis
* Bernie Cosell <[EMAIL PROTECTED]> [2004-04-19 23:32]: > I'll confess that I took the coward's way out: > >$money = sprintf "%7.3f", $amt; >$money =~ s/0$// ; > Doh. My own code was needlessly complex because I was working from the assumption that there may be no fractional part at all,

Re: fractional cents

2004-04-20 Thread A. Pagaltzis
* Bernie Cosell <[EMAIL PROTECTED]> [2004-04-19 17:37]: > So: what I want is something to format money correctly, whther > it is fractional or not. there's the fairly awful: > > sprintf ($amt =~ /\.\d\d\d/? "%7.3f": "%7.2f"), $amt > > Not much better and a ton more dangerous [due to roundin

Re: fractional cents

2004-04-21 Thread A. Pagaltzis
* John Douglas Porter <[EMAIL PROTECTED]> [2004-04-20 08:39]: > It seems to me that the precision desired should depend on > context, and nothing else. And that being the case... > > printf $fractional_cents ? '%7.3f' : '%7.sf', $amt; > > irrespective of the value of $amt. Why is this not rig

Re: Padding a length of string

2004-04-21 Thread A. Pagaltzis
* Uri Guttman <[EMAIL PROTECTED]> [2004-04-20 08:07]: > and no one found one of the faster methods: > > my $padded = substr( $in . $c x $pad_len, 0, $pad_len ) ; I did. Unfortunately, I misread the spec and thought it would be a problem that it also chops an $in longer than $pad_len down to $pad_

Re: fractional cents

2004-04-21 Thread A. Pagaltzis
* Bernie Cosell <[EMAIL PROTECTED]> [2004-04-22 00:02]: > On 21 Apr 2004 at 22:55, A. Pagaltzis wrote: > > If you do this by looking at $amt, then your method must be > > mathematical, because chopping characters in the string > > representation of the unrounded $amt

Re: fractional cents

2004-04-25 Thread A. Pagaltzis
* Keith C. Ivey <[EMAIL PROTECTED]> [2004-04-22 14:48]: > Math won't work, because floats aren't exact. Actually, that is a point I meant to make somewhere in this thread. When you're dealing with money, it's better to use cents (or tenths or hundredths of cents) as a unit, rather than dollars. Y

Re: fractional cents

2004-04-25 Thread A. Pagaltzis
* Smylers <[EMAIL PROTECTED]> [2004-04-22 13:43]: > > ... it can be done with math, and easily too: > > > > sprintf ( ( $amt * 1000 ) % 10 ? "%7.3f" : "%7.2f " ), $amt > > That isn't right: for $amt = 1.2306 it yields 1.23, while the > original yields the correct 1.231. Yep, you're right. >

Re: Reading X lines at a time

2004-05-09 Thread A. Pagaltzis
* Rick Delaney <[EMAIL PROTECTED]> [2004-05-03 15:23]: > while (my @a = map { eof() ? () : scalar <> } 1 .. $n) { > print @a; > print "SEPARATOR\n"; > } while (my @a = grep defined, map scalar <>, 1 .. $n) { print @a; print "SEPARATOR\n"; } --

Re: Y2K Again ??

2004-05-14 Thread A. Pagaltzis
* Brian Morgan <[EMAIL PROTECTED]> [2004-05-14 13:19]: > ($Yr = $FieldA) =~ s/^(\d{2}).*/$1/; > if($Yr > 20){ >$Yr = "19$Yr"; > }else{ >$Yr = "20$Yr"; > } It isn't exactly to your specs (equates to checking $Yr > 19), but could be made to, at the expense of much more complicated patterns.

Re: Y2K Again ??

2004-05-14 Thread A. Pagaltzis
* Rick Klement <[EMAIL PROTECTED]> [2004-05-14 17:26]: > Brian Morgan wrote: > > > > Good evening everybody, > > I have been working on a small database project and have come across the > > need to move some data from table A to table B, the year format in table > > A is \d{2}\D{8} and in table B

Re: Y2K Again ??

2004-05-14 Thread A. Pagaltzis
* A. Pagaltzis <[EMAIL PROTECTED]> [2004-05-14 17:32]: > That will generate a warning à la > > Argument "94foobar" isn't numeric in addition (+) at baz.pl line 42 > > Of course you could always > > $Yr = do { no warnings 'numeric';

Re: Break the 65 chars :-)

2004-04-26 Thread A. Pagaltzis
* Jose Alves De Castro <[EMAIL PROTECTED]> [2004-04-26 18:36]: > #!/usr/bin/perl -l0n > /:/;$_{$'.$&}.=" $`,"}{map{s/,$/ > /;print}%_ Trivial improvement, for a gain of 5 chars: #!/usr/bin/perl -l0p /:/;$_{$'.$&}.=" $`,"}for(%_){s/,$/ /; I've tried other clever things, but they all c

Re: Regular expression for years after a given one

2004-06-01 Thread A. Pagaltzis
* Jose Alves de Castro <[EMAIL PROTECTED]> [2004-06-01 11:59]: > BTW: This was made so it would work with $year consisting of > four digits... any care to make it generic? :-) sub rx_gt { local $_ = shift; return if /\D/; my @alt = ''; for(split //) {

Re: Regular expression for years after a given one

2004-06-01 Thread A. Pagaltzis
* Winter Christian <[EMAIL PROTECTED]> [2004-06-01 16:31]: > Another approach: > > use re 'eval'; > my $re = qr/(\d{4})(??{ $1>$year?'':'x{1000}' })$/; > > Assuming, of course, that $_ never contains a smaller year > number followed by thousand 'x'es. :-) You can remove that limitation by replac

Re: Regular expression for years after a given one

2004-06-01 Thread A. Pagaltzis
* Tobias Wolter <[EMAIL PROTECTED]> [2004-06-01 17:33]: > On 2004-06-01T10:52:55+0100 (Tuesday), Jose Alves de Castro wrote: > > "How can I say that I want every single year after the one I > > have? It's impossible..." > > The > operator works quite well for a four-digit year. Yeah, but that req

Re: Golf challenge: Tangled Tale

2004-06-23 Thread A. Pagaltzis
* Brad Greenlee <[EMAIL PROTECTED]> [2004-06-21 00:37]: > Golf anyone? My opening shot is 288. * Tobias Gödderz <[EMAIL PROTECTED]> [2004-06-23 19:16]: > We (a friend of mine and me) made it with 246 chars. Uh, you're supposed to publish your solutions when golfing. Regards, -- Aristotle "If yo

Re: Golf challenge: Tangled Tale

2004-06-24 Thread A. Pagaltzis
* Tobias Gödderz <[EMAIL PROTECTED]> [2004-06-24 23:42]: > Okay, I'm down to 148 now, and I think, I'm on my limit. I'll > publish mine as soon as no one wants to compete anymore. I am working on a solution, but I don't think I'll manage to finish tonight, and tomorrow I'll be gone from home until

Re: error handling in perl modules

2004-06-25 Thread A. Pagaltzis
* Babichev Dmitry <[EMAIL PROTECTED]> [2004-06-25 09:17]: > Could anybody provide the best practices of implementation the > error handling in perl modules? This is the "fun with Perl" list. Your inquiry is No Fun. You want to go to www.perlmonks.org or some such. Regards, -- Aristotle "If you

Re: Load-Bearing Warnings

2004-08-03 Thread A. Pagaltzis
* Smylers <[EMAIL PROTECTED]> [2004-08-04 00:34]: > [*0] It was cluttering up the error log with benign 'uninitialized' > messages, which were obscuring the output (from some other script) > that I wanted to see. Maybe you can try just disabling those? no warnings 'uninitialized'; Reg

Re: Matching at least $x words out of @words

2005-05-05 Thread A. Pagaltzis
* Josà Castro <[EMAIL PROTECTED]> [2005-05-05 16:30]: > So suppose you want a regular expression to match at least one > of three words: > > /word1|word2|word3/ > > What solution would you use if you wanted at least _two_ of > those three words? $alt = join '|', qw( word1 word2 word3 );

Re: Matching at least $x words out of @words

2005-05-09 Thread A. Pagaltzis
* Sven Neuhaus <[EMAIL PROTECTED]> [2005-05-09 10:35]: > @a = $x =~ /word1|word2|word3/g; > $count = scalar @a; The problem with this and all the grep solutions is that you donât know whether you matched the same alternate multiple times, or matched different alternates. You donât know whether the

Re: Matching at least $x words out of @words

2005-05-09 Thread A. Pagaltzis
* A. Pagaltzis <[EMAIL PROTECTED]> [2005-05-09 12:10]: > The problem with this and all the grep solutions is that you ^^ > donât know whether you matched the same alternate multiple > times, Err, that bit was non-sense, of course. I n

Re: [ANNOUNCE] first release of PerlWar (and request for beta testers)

2005-10-17 Thread A. Pagaltzis
* Yanick Champoux <[EMAIL PROTECTED]> [2005-10-18 03:05]: > Well, I'll be darned. Some people actually volunteered. :-) You might garner some more interest by posting this to rec.games.corewar – they’re always interested in hearing about variations on the game. Regards, -- #Aristotle *AUTOLOAD=*

Re: Converting dell tags to svc codes - itty-bitty golf, anyone?

2006-02-22 Thread A. Pagaltzis
* [EMAIL PROTECTED] <[EMAIL PROTECTED]> [2006-02-22 20:15]: >map {$s+=(/\d/?$_:(ord()-55))*(36**$i++)} reverse(split(//,uc shift)); @v{ 0..9, "A".."Z" } = 0..35; $s = $s * 36 + $v{ uc $_ } for /./g; Even readably spaced, the less clever solution is shorter. >$s =~ s/(...)/$1-/g; print "$s\n";

Re: Naming the @{[]} operator

2006-07-08 Thread A. Pagaltzis
* Philippe "BooK" Bruhat <[EMAIL PROTECTED]> [2006-07-07 17:35]: > I recently thought about the @{[]} operator again (one of the > semi-famous Perl "secret operators"), and called it the > "babycart" operator. That name only works as long as there isn’t anything within. The spaceship operator is a

Re: Naming the @{[]} operator

2006-07-11 Thread A. Pagaltzis
* Smylers <[EMAIL PROTECTED]> [2006-07-11 23:05]: > "babycart" is 3 syllables; "shopping trolley" Plus I could see myself adopting the latter (reluctantly) if it became part of the vernacular, but I’d feel too silly using the former to pick it up. I still like “fat brackets” better though, in va

Re: Naming the @{[]} operator

2006-07-13 Thread A. Pagaltzis
* Bart Lateur <[EMAIL PROTECTED]> [2006-07-13 11:30]: > On Thu, 13 Jul 2006 04:29:38 -0400, Chasecreek Systemhouse wrote: > >What the advantage the above over this: > > > >perl -le 'print time' > > Oh come on, you asked how to use @{[]}. It’s a legitimate question. Another use case: for( qw

Re: Including externally-defined constants

2006-07-20 Thread A. Pagaltzis
* Philippe "BooK" Bruhat <[EMAIL PROTECTED]> [2006-07-20 08:40]: > Le jeudi 20 juillet 2006 à 02:41, A. Pagaltzis écrivait: > >* Philippe "BooK" Bruhat <[EMAIL PROTECTED]> [2006-07-19 22:10]: > >><< '=cut'; > >> &

Re: Super regexp to format numbers

2006-08-28 Thread A. Pagaltzis
* Alexandre Jousset <[EMAIL PROTECTED]> [2006-08-28 18:15]: > For the moment I have a (too) complicated sub spacify and I would > like to simplify it to a regexp. It doesn’t have to be complicated, even without a regexp. scalar reverse join ' ', unpack '(A3)*', reverse $num; Regards, -- #A

Re: Super regexp to format numbers

2006-08-28 Thread A. Pagaltzis
* Alexandre Jousset <[EMAIL PROTECTED]> [2006-08-28 22:55]: > It works only for integers... This list is “fun with Perl.” Splitting a string at the dot char is not very fun, no? I considered that part to be obvious. Regards, -- Aristotle Pagaltzis //

Re: code line of the day

2006-09-07 Thread A. Pagaltzis
* Uri Guttman <[EMAIL PROTECTED]> [2006-09-07 09:30]: > this line of my code grew to its present form which i find amusing. > > @{$self->{templates}}{ keys %{$tmpls} } = > map ref $_ eq 'SCALAR' ? \"${$_}" : \"$_", values %{$tmpls} ; my ( $k, $v ); $self->templates->{

Re: code line of the day

2006-09-08 Thread A. Pagaltzis
* John Douglas Porter <[EMAIL PROTECTED]> [2006-09-08 15:40]: > If we're looking for ways to do it differently, possibly better: > > my %copy = %$tmpls; > $_ = ref $_ ? \"$$_" : \"$_" for values %copy; > @{$self->{templates}}{ keys %copy } = values %copy; That was one of the deleted attempts. Hmm

Re: code line of the day

2006-09-08 Thread A. Pagaltzis
* Chris Dolan <[EMAIL PROTECTED]> [2006-09-08 17:10]: > Why did you use "local"? Shouldn't the following work? > > sub flatten_copy { > my $s = shift; > ref $s eq 'SCALAR' ? "$$s" : "$s"; > } Works the same. I often use `local $_` in tiny functions that mangle just a sing

Re: code line of the day

2006-09-08 Thread A. Pagaltzis
* John Douglas Porter <[EMAIL PROTECTED]> [2006-09-08 17:20]: > I believe it's better to do > > ref $_ ? "$$_" : "$_" > > than > > ref $_ eq 'SCALAR' ? "$$_" : "$_" > > because, in the first case, you get an actual error in the > exceptional case (a ref of the wrong type), whereas in the >

Re: local vs. my (was Re: code line of the day)

2006-09-09 Thread A. Pagaltzis
* Chris Dolan <[EMAIL PROTECTED]> [2006-09-09 03:55]: > >Works the same. I often use `local $_` in tiny functions that > >mangle just a single value. Matter of taste/style. > > Ahh, I see -- cargo cult. ;-) Err, what? I chose that style for myself. I didn’t pick it up from anyone else and certai

Re: local vs. my (was Re: code line of the day)

2006-09-10 Thread A. Pagaltzis
* Philippe "BooK" Bruhat <[EMAIL PROTECTED]> [2006-09-09 22:45]: > Why is why you can write « my $_ » in recent Perls, I think. Nice. I’ll use that when it finds its way into a stable release. :-) Regards, -- Aristotle Pagaltzis //

Re: local vs. my (was Re: code line of the day)

2006-09-10 Thread A. Pagaltzis
Hi Chris, * Chris Dolan <[EMAIL PROTECTED]> [2006-09-09 21:00]: > I didn't mean that to be insulting -- I was just teasing. […] > That was for my curiosity and to convince me, […] I apologize > for my less-than-clear motives. no problem, not your fault. I’m a bit impatient sometimes, which can le

Re: Punctuation Free Quine -- Almost

2006-09-19 Thread A. Pagaltzis
* Dave Mitchell <[EMAIL PROTECTED]> [2006-09-20 02:55]: > I believe the following is a genuine, punctuation-free Quine: > > s zzs vvxv > and s ZVZchr 122Zie > and s ZVZchr 122Zie > and s ZVZchr 122Zie > and s SxSlcfirstSe > and s YZZxZYvvxvYi and print > z > and s ZVZchr 122Zie > and s ZVZchr 122Z

Re: Minimal DNS answer using Net::DNS

2006-11-26 Thread A. Pagaltzis
* Kelly Jones <[EMAIL PROTECTED]> [2006-11-26 08:00]: > I've used xinetd to set up a test nameserver on port 1024. > Here's the Net::DNS Perl I'm using to say (falsely) that > news.yahoo.com resolves to 10.1.2.3 with a TTL of 1 day: Hmm. Your question is not very Fun, so this is the wrong list to

Re: fun with hashes!

2007-11-23 Thread A. Pagaltzis
* Mr. Shawn H. Corey <[EMAIL PROTECTED]> [2007-11-24 00:50]: > my $sub = ( exists $dispatch{ $key } && ref( $dispatch{ $key } ) eq 'CODE' ) > ? $dispatch{ $key } > : $dispatch{ 'default' }; > > Just because you're not paranoid doesn't mean computers don't > hate you :) So why did

  1   2   >