Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

Search a variable and put in a array.... Help !!!!!

Dear everyone ,

I have a variable=

$file = qq!print "Content-type: text/html\n\n";if ($ENV{'QUERY_STRING'} =~ /^album=(\S+);image=(\d+);whatsnew$/) {$dir = $1;$si = $2;$no = $2;!;


Now what i want is the code which scans the whole $file for variables (eg. $no , $dir). It should ignore Numbers (eg $1,$2) and then add their name to a array.

It should not repeat the same variable twice
 in the array.

Thus the array should read something like this -

@array = ("no","si","dir","and so on");

Please help ASAP...

Anant
0
anant99
Asked:
anant99
1 Solution
 
JaymolCommented:
listening...
0
 
anant99Author Commented:
I think some one can modify this :-

while ($file) {
if (/\$(\w+)/) {
push(@array,$1);
}

i dont know how to get it working...

Please help !!!

Anant
0
 
amandeepCommented:
anant99,

Try it this way :

while ($file=~/\$(\w+)/g) {
  my $v=$1;
  push(@array,$v) unless($v=~/^\d+$/);
}

Hope this helps

Aman
:-)
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
anant99Author Commented:
also can u filter out captial variables like $ENV
0
 
ozoCommented:
$file = q!print "Content-type: text/html\n\n";if($ENV{'QUERY_STRING'} =~ /^album=(\S+);image=(\d+);whatsnew$/)
{$dir = $1;$si = $2;$no = $2;!;
@array = reverse $file=~/\$([a-z]+)\b/g
0
 
ahoffmannCommented:
do you mean just to extract the variable names from the string in $ENV{'QUERY_STRING'}  ?
0
 
anant99Author Commented:
Thanks !!! This is just what I wanted...
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now