?
Solved

qw command

Posted on 2001-09-18
5
Medium Priority
?
1,446 Views
Last Modified: 2012-06-21
I am using the following command:

print OUT dumphash([\%$supcat, \%$supcatdesc], [qw(super_cat super_cat_desc)]);

Now I want the following:
I want to use a foreach loop.

Something like this:

foreach (@test) {
print OUT dumphash([\%$supcat, \%$supcatdesc], [qw(super_cat_$_ super_cat_desc_$_)]);
}

But that will not work!! The $_ will not be transfered to the value of $_!
How to make it work and get the following when $_ is test.
print OUT dumphash([\%$supcat, \%$supcatdesc], [qw(super_cat_test super_cat_desc_test)]); ??




0
Comment
Question by:mmcw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:psogaa
ID: 6490563
I don't think qw will interpolate the string inside. Try using qq or some other variable interpolating identifier.
0
 
LVL 6

Expert Comment

by:holli
ID: 6491637
from perlop: (sometimes its good to read the manual)
qw/STRING/

Evaluates to a list of the words extracted out of STRING, using embedded whitespace as the word delimiters. It can be understood as being roughly equivalent to:

    split(' ', q/STRING/);
the difference being that it generates a real list at compile time. So this expression:


    qw(foo bar baz)
is semantically equivalent to the list:


    'foo', 'bar', 'baz'


outcome:

foreach (@test) {
print OUT dumphash([\%$supcat, \%$supcatdesc], ["super_cat_$_", "super_cat_desc_$_"]);
}

0
 

Author Comment

by:mmcw
ID: 6492677
holli:
Won't work!!
0
 
LVL 6

Accepted Solution

by:
holli earned 200 total points
ID: 6493470
try
foreach $var (@test) {

print OUT dumphash([\%$supcat, \%$supcatdesc], ["super_cat_$var", "super_cat_desc_$var"]);
}

by the way. whats this: \%$supcat?
a reference to a hash named $supcat?
0
 

Author Comment

by:mmcw
ID: 6494439
That did it!!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question