Solved

qw command

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Perl Script to append xml file 32 184
Perl output collect 7 64
crawling gofundme 4 103
Perl Application JSON Receiving Strange Java Error 3 65
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now