<?xml version="1.0" encoding="iso-8859-1"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:admin="http://webns.net/mvcb/"
xmlns="http://purl.org/rss/1.0/">
<channel rdf:about="http://aplawrence.com//rss/fullProgramming.rdf">
<title>Programming Site News at A.P.Lawrence.com</title>
<link>http://aplawrence.com/</link>
<description>
Programming feed at aplawrence.com: Thousands of articles, reviews, consultants listings, skills tests, opinion, how-to's for Unix, Linux and Mac OS X, networking, web site maintenance and more.. 
</description>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>6</sy:updateFrequency>
<sy:updateBase>2008-01-01T00:00+00:00</sy:updateBase>
<dc:language>en</dc:language>
<dc:publisher>A.P. Lawrence</dc:publisher>
<dc:rights>Copyright  A.P. Lawrence</dc:rights>
<dc:creator>A.P. Lawrence (mailto:rssfeeds@aplawrence.com)</dc:creator>
<dc:date>2017-02-17T10:37:54+00:00</dc:date>
<image rdf:resource="http://aplawrence.com/image21.gif">
</image>
<items>
<rdf:Seq>
<rdf:li rdf:resource="http://aplawrence.com/Unixart/perl-map-function.html" />
<rdf:li rdf:resource="http://aplawrence.com/Reviews/amazon-echo-sdk.html" />
</rdf:Seq>
</items>
</channel>
<image rdf:about="http://aplawrence.com/image21.gif">
<title>A.P.Lawrence Logo</title>
<url>http://aplawrence.com/image21.gif</url>
<link>http://aplawrence.com</link>
</image>


<item rdf:about="http://aplawrence.com/Unixart/perl-map-function.html">
<title>Understanding Perl's map function  </title>
<description>
<![CDATA[

<!-- <html><head><title>Understanding Perl's map function</title></head><body> -->

<!-- 2015/09/17 -->

<p>Anonymous asks: <br />
<p><i>I've seen "map" used in Perl code and I do not understand it at all. Can you explain it?</i></p>


<p>Perl's map function is often under-appreciated and not understood by Perl newbies. That's probably because it works on arrays, transforming one array into another array or hash. It's a time saver, both in typing time and when the code runs. Map does nothing you cannot do with a loop and if you are new to Perl a loop is likely exactly what you do use.</p>
<p>That may contribute to confusion. Because map turns up in code written by more experienced coders, that code tends to be more difficult for newbies to understand. That was certainly the case for me: I ignored map for years because I didn't understand it when I saw it. Even after I did understand it, I still tended to write loops for code I published here so as not to confuse newbies!</p>
<p>So what kinds of loops can map replace? Let's start with something simple: we have an array of numbers and want another array that contains those numbers times .75 when the number is greater than 49 and times .85 otherwise. Here's how you might code that in a loop:</p>
<pre>
#!/usr/bin/perl
my @array = (20, 10, 1, 100, 200, 50);
my @computed=();
foreach (@array) {
 $newvalue=$_ * .75;
 $newvalue=$_ * .85 if $_ &lt; 50;
 push @computed,$newvalue;
}
print join(",", @computed), "\n";

</pre>
<p>The output of that would be "17,8.5,0.85,75,150,37.5". Now let's do it with map:</p>
<pre>
#!/usr/bin/perl
my @array = (20, 10, 1, 100, 200, 50);
my @computed= (map { $_ &lt; 50 ? $_ * .85 : $_ * .75 } @array);
print join(",", @computed), "\n";

</pre>
<p>Honestly, that map line still gives me a headache. It's harder to read, but if your @array was large, that code would chew through it much more quickly.</p>
<p>Suppose instead we wanted to only extract the numbers greater than 49 and multiply those by .75?  Our loop code might be:</p>
<pre>
#!/usr/bin/perl
my @array = (20, 10, 1, 100, 200, 50);
my @computed=();
foreach (@array) {
 next if $_ &lt; 50;
 push @computed,$_ * .75;
}
print join(",", @computed), "\n";

</pre>
<p>The output of that would be "75,150,37.5".</p>
<p>Here's a map version:</p>
<pre>
#!/usr/bin/perl
my @array = (20, 10, 1, 100, 200, 50);
my @computed=(map { $_ &gt; 49 ? $_ * .75 : ()} @array);
print join(",", @computed), "\n";

</pre>
<p>Again, faster but perhaps confusing at first glance.</p>
<p>Even more confusing is that you'll see map used like this:</p>

<pre>
#!/usr/bin/perl
my @array = (65,83, 81, 79, 100, 88, 75);
my @new_array = map (chr,@array);
print join(",", @new_array), "\n";

</pre>
<p>That produces "A,S,Q,O,d,X,K".  Why parentheses instead of squiggly brackets? It's because initially we were writing code and code needs to be in a code block, but chr is another function.  The map function can handle its arguments in two ways: map EXPR,LIST or map BLOCK LIST. Unfortunately for those of us with small brains, those squiggly brackets in Perl can also mean that you are about to reference a hash and not a code block. This leads us to headaches because map can be used to build hashes instead of arrays. See the first link below for more on that.</p>

<p><a href="http://perldoc.perl.org/functions/map.html">Perldoc.perl.org "map"</a></p>
<p><a href="http://stackoverflow.com/questions/136204/whats-the-point-of-perls-map">What's the point of Perl's map?</a></p>



<p style="word-break: break-word; max-width: 100%; color: rgb(70, 70, 70); font-family: -apple-system-font; font-size: 17px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 24px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">-- This feed and its contents are the property of A.P. Lawrence, and use is subject to our terms. It may be used for personal consumption, but may not be distributed on a website.</p><br class="Apple-interchange-newline">

]]>
</description>
<link>http://aplawrence.com/Unixart/perl-map-function.html</link>
</item>
<item rdf:about="http://aplawrence.com/Reviews/amazon-echo-sdk.html">
<title>Amazon Echo SDK  </title>
<description>
<![CDATA[

<!-- <html><head><title>Amazon Echo now has a SDK </title></head><body> -->

<!-- 2015/07/01 -->


<p>Amazon now allows anyone to buy Echo and has also announced a SDK that allows anyone to write application functions. That really fired me up, at least momentarily: I can think of many things I'd like to do with Alexa myself and at least some of those might be of interest to others.  You can write in Json or Java, neither of which I have great experience with, but I do have a little and I was able to read and at least mostly understand the provided sample code.</p>
<div style="text-align:center">

<p><a href="http://aplawrence.com/cgi-bin/showpic.pl?image=amazon-echo-sdk_lg.jpg&amp;mytitle=Amazon%20Echo%20SDK%20testing&amp;returnpage=Reviews/amazon-echo-sdk.html&amp;returntitle=Amazon%20Echo%20SDK"><img src="http://aplawrence.com/images/amazon-echo-sdk.jpg" alt="Amazon Echo SDK testing" title="Amazon Echo SDK testing (click for larger view)" /></a></p>

</div>
<p>That's as far as I got, though.  Amazon lets you deploy through AWS (Amazon Web Services).  I was able to create an account and actually test some sample code, but when it came to getting that code to test on my Echo, I fell on my face. I think I followed their directions, and my Echo does try to respond, but it fails and I haven't a clue what to do next. From my point of view, AWS and this new SDK assume to much prior knowledge and leave out far too much.  I do realize that I'm a crusty old dinosaur and my brain plasticity is long gone, so my point of view is probably completely invalid, but regardless, I had to give up. As much as I'd like to, I don't think I'll be developing anything for Amazon Echo.</p>
<p>Oh well. At least my brain was fired up and excited for a few minutes.</p>
<p>Other people will figure this out and I expect exciting things. Opening this up to let anyone create capabilities is smart. There will be a deluge of useful (and silly, of course) new features coming to Echo very soon!</p>

<p><a href="https://developer.amazon.com/public/community/post/Tx205N9U1UD338H/Introducing-the-Alexa-Skills-Kit-Enabling-Developers-to-Create-Entirely-New-Voic">Introducing the Alexa Skills Kit, Enabling Developers to Create Entirely New Voice Driven Capabilities</a></p>




<p style="word-break: break-word; max-width: 100%; color: rgb(70, 70, 70); font-family: -apple-system-font; font-size: 17px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 24px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">-- This feed and its contents are the property of A.P. Lawrence, and use is subject to our terms. It may be used for personal consumption, but may not be distributed on a website.</p><br class="Apple-interchange-newline">

]]>
</description>
<link>http://aplawrence.com/Reviews/amazon-echo-sdk.html</link>
</item>
</rdf:RDF>
