in reply to Re: Loop Control
in thread Loop Control

Here are some pointers to help you assimilate to a more Perlish way of thinking (RESISTANCE IS FUTILE)

There are other things that could be greatly simplified as well, but those are just some of the more critical stylistic faux pas that jumped out at me. Honestly, if your code works exactly as expected, then there's not really anything wrong with it :) And if you can understand why and how it works, then it's Good Enough(tm). When I was just starting out with Perl, map confused the hell out of me, so I never used it and I always avoided solutions that people gave me that used it. Then when it clicked I thought "Holy llama balls, this shit is The Shit" and tried using it for everything. Neither ways are necessarily the best approach. In the end, all that matters is that you're constantly learning how and when to use the unique features of Perl that make it so slackfully elegant. Just lurk around and look at code examples passed around and you'll start to get it.

But seriously, do some experimenting with map, because it will greatly simplify any operation where you have to turn one set of values into another.


$,=qq.\n.;print q.\/\/____\/.,q./\ \ / / \\.,q.    /_/__.,q..
Happy, sober, smart: pick two.

Replies are listed 'Best First'.
Re^3: Loop Control
by ateague (Monk) on Aug 02, 2013 at 15:49 UTC
    Off the top of my head, I can't think of an instance where $a = $b would give a different result than $a = "$b".
    This will explode horribly if $b is a reference. Compare the following:
    [ateague@dingbat mod]$ perl -MData::Dumper -E '$b = [qw/1 2 3 4 5/]; $ +a = $b; say Dumper $a;' $VAR1 = [ '1', '2', '3', '4', '5' ]; [ateague@dingbat mod]$ perl -MData::Dumper -E '$b = [qw/1 2 3 4 5/]; $ +a = qq|$b|; say Dumper $a;' $VAR1 = 'ARRAY(0x12609e4)';
    The first one prints the array referenced by the reference. The second one simply prints a string containing the memory address of the array reference.