Solved

qw command

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Extract data from span tag 1 95
quoting a comma separated list 20 87
Export Variables in Perl 3 86
Log File Creation with Header and Footer 17 130
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

828 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