Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: regular expression math equations

by kwaping (Priest)
on Nov 20, 2006 at 14:55 UTC ( [id://585066]=note: print w/replies, xml ) Need Help??


in reply to regular expression math equations

my $text = "(a + 13) * (b - 10 ) / c"; # select all individual alpha characters my @vars = ($text =~ /[a-zA-Z]/g); # get uniques out of the array my %hash; map { $hash{$_}++ } @vars; my @unique_vars = keys %hash;
Of course, this solution is based on the assumption that your variables are always going to be a single a-z character (based on your example). Also, a small side-benefit of this code is that the values of %hash will tell you how many times a particular variable was found in the equation.

---
It's all fine and dandy until someone has to look at the code.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://585066]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found