mmcw
asked on
qw command
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)]); ??
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)]); ??
I don't think qw will interpolate the string inside. Try using qq or some other variable interpolating identifier.
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_$_"]);
}
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_$_"]);
}
ASKER
holli:
Won't work!!
Won't work!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That did it!!