Solved

qw command

Posted on 2001-09-18
5
1,420 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 50 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Uploading Binary Data using Perl 5 106
Perl strange behaviour 5 79
how to exit a  for loop inside a function with return value in bash 5 114
Control Number of Log Files -Perl 7 102
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 …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

752 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