CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Substitution on Multiple Variables

 



sithscout80
New User

Sep 25, 2006, 1:39 PM

Post #1 of 4 (289 views)
Substitution on Multiple Variables Can't Post

Within a program I'm writing I have a subroutine sort an array of hashes based on a few criterion.

Currently I have this.

Code
$a->{"Capacity"} =~ s/GB//; 
$a->{"Price"} =~ s/\$//;
$b->{"Capacity"} =~ s/GB//;
$b->{"Price"} =~ s/\$//;


As I add more things parts of the hash to parse (before I sort it), the lines of code will increase quickly.
I was wondering if there is a way to do a substitution on 2 variables in the same line. Something like this.


Code
($a, $b)->{"Capacity"} =~ s/GB//; 
($a, $b)->{"Price"} =~ s/\$//;



KevinR
Veteran


Sep 25, 2006, 3:06 PM

Post #2 of 4 (288 views)
Re: [sithscout80] Substitution on Multiple Variables [In reply to] Can't Post

You should probably be doing all the substitution/parsing before you start the sort.
-------------------------------------------------


sithscout80
New User

Sep 25, 2006, 3:22 PM

Post #3 of 4 (287 views)
Re: [KevinR] Substitution on Multiple Variables [In reply to] Can't Post

Now that you bring it up, I should move the parsing outside of the subroutine.

I still am just wondering if there is a way to do a substituion on multiple variables at the same time.


davorg
Thaumaturge / Moderator

Sep 26, 2006, 1:38 AM

Post #4 of 4 (284 views)
Re: [sithscout80] Substitution on Multiple Variables [In reply to] Can't Post

The best approach is probably something like this:


Code
for ($a, $b) { 
$_->{Capacity} =~ s/GB//;
$_->{Price} =~ s/\$//;
}


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives