Re: A better way.

2005-08-02 Thread Wiggins d'Anconia
Dan Klose wrote: Hello Everyone. I have the following code: ### CODE BLOCK ### my %hash_of_arrays2; Have you considered a hash of hashes? For me, given the sample below, I would prefer it, but obviously I haven't seen your whole script. for (keys %hash_of_arrays) { my

Re: A better way.

2005-08-02 Thread Jeff 'japhy' Pinyan
On Aug 2, Dan Klose said: my %hash_of_arrays2; for (keys %hash_of_arrays) { my @array_of_data = exists($hash_of_arrays{$_}) [EMAIL PROTECTED] :(); Given that you're iterating over the list of keys in %hash_of_arrays, there's NO reason to be using exists() here. my

Re: A better way.

2005-08-02 Thread Dan Klose
Hi, I have gone for the following code: my %avs_dev = map{ $_ = [mean($hoa{$_}), dev($hoa{$_})] } keys %hoa; for (sort {$avs_dev{$a}[0] = $avs_dev{$b}[0]} keys %avs_dev) { print $_, $avs_dev{$_}[0], $avs_dev{$_}[1]\n; } I have never used MAP before... it looks handy! Works a treat. Thanks

Re: A better way

2003-04-03 Thread Stefan Lidman
Brian Ling wrote: Hi List, I have the following bit of code, that works but doesn't feel like the best way, can anyone think of a better neater answer maybe a one liner? my $target = getTarget(); If ( target eq MAIN ) { return } #do lots of other stuff with value of target well this

Re: A better way

2003-04-03 Thread Rob Richardson
Stefan, Personally, I'd prefer: if (target ne MAIN) { #do lots of other stuff } I think general programming practice discourages multiple return points in subroutines. RobR __ Do you Yahoo!? Yahoo! Tax Center - File online, calculators,

RE: A better way

2003-04-03 Thread Brian Ling
Thanks for that, I had not released you could effectively use the getTarget() return value twice :-) well this works: return if 'MAIN' eq (my $target = getTarget()); /Stefan BBCi at http://www.bbc.co.uk/ This e-mail (and any attachments) is confidential and may contain personal views

Re: A better way

2003-04-03 Thread Rob Dixon
Rob Richardson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Stefan, Personally, I'd prefer: if (target ne MAIN) { #do lots of other stuff } I think general programming practice discourages multiple return points in subroutines. Yes, and it's no more dangerous than

Re: A better way

2003-04-03 Thread Rob Dixon
Brian Ling wrote: Thanks for that, I had not released you could effectively use the getTarget() return value twice :-) well this works: return if 'MAIN' eq (my $target = getTarget()); /Stefan Personally, I prefer: ( my $target = getTarget() ) eq 'MAIN' and return; as I believe

Re: A better way

2003-04-03 Thread Paul Johnson
Rob Dixon said: Rob Richardson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Stefan, Personally, I'd prefer: if (target ne MAIN) { #do lots of other stuff } I think general programming practice discourages multiple return points in subroutines. Yes, and it's no

Re: A better way

2003-04-03 Thread Rob Dixon
Paul Johnson wrote: Rob Dixon said: Rob Richardson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Stefan, Personally, I'd prefer: if (target ne MAIN) { #do lots of other stuff } I think general programming practice discourages multiple return points

Re: A better way

2003-04-03 Thread R. Joseph Newton
Rob Richardson wrote: Stefan, Personally, I'd prefer: if (target ne MAIN) { #do lots of other stuff } I think general programming practice discourages multiple return points in subroutines. RobR I disagree. While one should certainly exercise care when making an early return,

Re: A better way

2003-04-03 Thread R. Joseph Newton
Paul Johnson wrote: To my mind, return if $target eq MAIN; at the top of a sub is a lot more helpful than making me search all the way down to the botttom to see if there is anything after the conditional. And it's probably a lot less likely that the next person to edit that sub will

Re: A better way

2003-04-03 Thread Paul Johnson
R. Joseph Newton said: The only thing it lacked was a meaningful return value. Since the getTarget function provided enough information to decide in favor of an early exit, this information should probably be passed on more explicitly,

Re: A better way

2003-04-03 Thread R. Joseph Newton
Paul Johnson wrote: R. Joseph Newton said: The only thing it lacked was a meaningful return value. Since the getTarget function provided enough information to decide in favor of an early exit, this information should probably be

Re: A better way

2003-04-03 Thread Rob Dixon
R. Joseph Newton wrote: Paul Johnson wrote: To my mind, return if $target eq MAIN; at the top of a sub is a lot more helpful than making me search all the way down to the botttom to see if there is anything after the conditional. And it's probably a lot less likely that the next

Re: A better way

2003-04-03 Thread R. Joseph Newton
Rob Dixon wrote: Unless the $target variable was meant simply to decide on a return, it makes more sense to assign its value--one task, one line, and check it for validity--another task entirely, on a line of its own. So presumably you're against while ( my $line = FH ) {

Re: A better way, a perl way?

2003-01-23 Thread Jeff 'japhy' Pinyan
On Jan 22, david said: @data_ = map { (my $copy = $_) =~ s/^ //; $copy } @data; s/^ // for(@data_ = @data); Sigh. I usually do that. I was a little slow on the idiom-uptake. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734

Re: A better way, a perl way?

2003-01-22 Thread Jeff 'japhy' Pinyan
On Jan 22, Jerry Preston said: I am looking for a better way, a perl way for the following: foreach ( @data ) ) { s/^ //; $data_[ $jp++ ] = $_; } You do realize that you're modifying the elements in @data as well, right? So that, unless $jp starts at some value other than 0,

Re: A better way, a perl way?

2003-01-22 Thread Frank Wiles
.--[ Jerry Preston wrote (2003/01/22 at 11:59:14) ]-- | | I am looking for a better way, a perl way for the following: | | foreach ( @data ) ) { |s/^ //; |$data_[ $jp++ ] = $_; | } | `- I'm

RE: A better way, a perl way?

2003-01-22 Thread Bob Showalter
Frank Wiles wrote: .--[ Jerry Preston wrote (2003/01/22 at 11:59:14) ]-- | | I am looking for a better way, a perl way for the following: | | foreach ( @data ) ) { |s/^ //; |$data_[ $jp++ ] = $_; | } |

Re: A better way, a perl way?

2003-01-22 Thread david
Jeff 'Japhy' Pinyan wrote: If you DON'T want that, you'd have to do: for (@data) { (my $copy = $_) =~ s/^ //; push @data_, $copy; } Or something to that effect. Here's a one-liner: @data_ = map { (my $copy = $_) =~ s/^ //; $copy } @data; a bit shorter:

RE: A better way to handle array index?

2002-10-21 Thread Jenda Krynicky
From: Johnstone, Colin [EMAIL PROTECTED] for example I read my form variables into a hash for processing. I then reference them by the form fieldname. #read STDIN, $PostData, $ENV{'CONTENT_LENGTH'}; #print post data =$PostDatabr; #postdata will look like this #[EMAIL

Re: A better way to handle array index?

2002-10-21 Thread Jenda Krynicky
From: chris [EMAIL PROTECTED] I am looking for a less cryptic way to handle array index. most cryptic $array[0] better use constant NAME = 0; $array[NAME] This all depends on what do you want to do with the data structure. But most probably you do want to use a hash.

RE: A better way to handle array index?

2002-10-20 Thread Timothy Johnson
And if you're really stuck with using arrays, you can always: my @bases = (); my $first = 0; $bases[$first] = 'who'; -Original Message- From: Johnstone, Colin To: 'chris' Cc: '[EMAIL PROTECTED]' Sent: 10/19/02 5:47 PM Subject: RE: A better way to handle array index? That would

RE: A better way to handle array index?

2002-10-19 Thread Johnstone, Colin
That would be a hash. (or an associative array) for example I read my form variables into a hash for processing. I then reference them by the form fieldname. #read STDIN, $PostData, $ENV{'CONTENT_LENGTH'}; #print post data =$PostDatabr; #postdata will look like this #[EMAIL

RE: a better way?

2002-09-26 Thread Nikola Janceski
open(FILE, yourfile) or die $!; chomp(my(@lots) = FILE); close FILE; -Original Message- From: Jerry Preston [mailto:[EMAIL PROTECTED]] Sent: Thursday, September 26, 2002 11:30 AM To: Beginners Perl Subject: a better way? Hi! Is there a better way? A Perl way? $j = 0;

Re: a better way?

2002-09-26 Thread Jeff 'japhy' Pinyan
On Sep 26, Jerry Preston said: Is there a better way? A Perl way? $j = 0; while( file ) { chomp; ( $lots[ $j++ ] ) = $_; That's usually written as push @lots, $_; } Well, you could do: chomp(@lines = FILE); but why do you need the file in an array? -- Jeff japhy

RE: a better way?

2002-09-26 Thread Nikola Janceski
: Thursday, September 26, 2002 11:36 AM To: Jerry Preston Cc: Beginners Perl Subject: Re: a better way? but why do you need the file in an array? The views and opinions expressed in this email

RE: a better way?

2002-09-26 Thread Jerry Preston
: Beginners Perl Subject: Re: a better way? On Sep 26, Jerry Preston said: Is there a better way? A Perl way? $j = 0; while( file ) { chomp; ( $lots[ $j++ ] ) = $_; That's usually written as push @lots, $_; } Well, you could do: chomp(@lines = FILE); but why do you need

RE: a better way?

2002-09-26 Thread Nikola Janceski
Preston [mailto:[EMAIL PROTECTED]] Sent: Thursday, September 26, 2002 11:51 AM To: [EMAIL PROTECTED] Cc: Beginners Perl Subject: RE: a better way? Jeff, I guess it an old 'c' habit. I do this to check each line for the item I am looking for. I there a better way and why? Thanks

RE: a better way?

2002-09-26 Thread Jeff 'japhy' Pinyan
On Sep 26, Jerry Preston said: I guess it an old 'c' habit. I do this to check each line for the item I am looking for. I there a better way and why? my $found = 0;# have we found 'jeff'? while (FILE) { # reads ONE LINE at a time, and stores it in $_ if (/jeff/) { # if the line

Re: A better way to list variable names in report format?

2002-09-12 Thread chris
Thank you. Now I can quit the horizontal scrolling. On Wed, 11 Sep 2002 20:52:59 -0400, [EMAIL PROTECTED] (Bob Showalter) wrote: I know beans about formats, but perldoc perlform contains this statement: The expressions may be spread out to more than one line if enclosed in braces. If so, the

Re: A better way to list variable names in report format?

2002-09-11 Thread chris
Oops. $$ @$myStuff{qw/column1 column2 column3/}; is definitely an improvement but my list is very long. I think I will have to assign new variables just to make the listing in multiple lines. Horizontal scrolling to read off-page code is not nice. On Wed, 11 Sep 2002 16:42:10 -0700,

Re: A better way for seeding an annoymous hash

2002-08-08 Thread Peter Scott
At 11:44 AM 8/8/02 -0700, drieux wrote: On Thursday, August 8, 2002, at 11:04 , Peter Scott wrote: At 10:38 AM 8/8/02 -0700, drieux wrote: I'm not sure the average normal person would feel at home with say: %{$by_os{$os_key}}-{$_}++ for(@$found); Especially since it's only by

RE: Any better way to make 1000000 becomes 1,000,000 ?

2002-07-30 Thread Beau E. Cox
Connie - Try this (not really much better) from Perl Cookbook #2.17: use strict; use warnings; my $num = commify (1_000_000); print $num\n; sub commify { my $text = reverse $_[0]; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; return scalar reverse ($text); } Aloha

Re: Any better way to make 1000000 becomes 1,000,000 ?

2002-07-30 Thread chris
This works for me http://search.cpan.org/doc/WRW/Number-Format-1.44/Format.pm use strict; use warnings; use Number::Format qw(:subs :vars); $THOUSANDS_SEP = '.'; $DECIMAL_POINT = ','; my @number = (123456789,123); foreach my $number (@number) { print format_number($number) . \n; } use

Re: A better way for ugly code?

2001-08-10 Thread Curtis Poe
--- Teresa Raymond [EMAIL PROTECTED] wrote: Curtis, What part of the code that you posted actually does the untainting? Here's one way to grab the data and untaint it in one line: my ( $name ) = ( $q-param('name') =~ /^(\w+)$/ ); Note that the parentheses around *both side* of the

Re: A better way for ugly code?

2001-08-09 Thread Curtis Poe
--- Mark Ross [EMAIL PROTECTED] wrote: Hi all, I'm curious how I can condense this code. I'm pulling my values from a Web submitted form (using CGI), and I need to untaint them. But, each form field has different requirement for what characters it can match (account number should only

Re: A better way for ugly code?

2001-08-09 Thread Teresa Raymond
Curtis, What part of the code that you posted actually does the untainting? --- Mark Ross [EMAIL PROTECTED] wrote: Hi all, I'm curious how I can condense this code. I'm pulling my values from a Web submitted form (using CGI), and I need to untaint them. But, each form field has

Re: A better way?

2001-06-22 Thread Paul
--- Tim Musson [EMAIL PROTECTED] wrote: Hey all, I have this code fragment. if ($Var eq String) { Sub($Var1); } elsif ($Var2 =~ /$STRING/) { Sub($Var1); } Is this a better way? if (($Var eq String) || ($Var2 =~ /$STRING/)) { Sub($Var1); } I like it better.

Re: A better way?

2001-06-22 Thread iansmith
On Fri, 22 Jun 2001, Tim Musson wrote: Is this a better way? if (($Var eq String) || ($Var2 =~ /$STRING/)) { Sub($Var1); } I usually write... if ($Var eq String or $Var2 =~ /$STRING/) { ...as I like the diffrent precidence of the 'or' operator. You can also leave off the if you are