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

x
?
Solved

qw command

Posted on 2001-09-18
5
Medium Priority
?
1,461 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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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

971 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