I was doing a relatively simple piece of code,
for my $var (@vars) {
print "Value: " . $hash_ref->{lc $var} . "\n" if exists $hash_ref-
+>{lc $var};
}
I had to lc() the $var variable to for the key comparision. I started thinking, is there another way to do this? Well I could have done this,
for my $var (@vars) {
my $new_var = lc $var;
print "Value: " . $hash_ref->{$new_var} . "\n" if exists $hash_ref
+->{$new_var};
}
Then I started thinking, what if I wanted to do this except it was invalid Perl.
for my $var = lc $_ (@vars) {
print "Value: " . $hash_ref->{$var} . "\n" if exists $hash_ref->{$
+var};
}
NOW, I am thinking, how does a value get from @vars to my $var? If there is an internal iterator used by the for loop, does it put a value into the variable assignment or can you put an expression in there in some way? I admit I have never seen it before, but it is Perl!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.