<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6180060022439114324</id><updated>2011-07-30T11:30:38.377-07:00</updated><category term='perl gotcha'/><category term='Perl IPv6 GermanPerlWorkshop'/><title type='text'>EINTR</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://eintr.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6180060022439114324/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://eintr.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>me</name><uri>http://www.blogger.com/profile/00999965525169315547</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6180060022439114324.post-8817644772003516393</id><published>2009-06-19T11:29:00.000-07:00</published><updated>2009-06-20T00:53:11.114-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl gotcha'/><title type='text'>Perl Gotcha II</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-size:100%;"&gt;Don't exit an each loop unless you really know what you do.&lt;br /&gt;Consider the following code&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  1 my %h = ( one =&gt; 1, two =&gt; 2, three =&gt; 3 );&lt;br /&gt;  2 sub find_key {&lt;br /&gt;  3   my $val = shift;&lt;br /&gt;  4   while ( my ($k,$v) = each %h ) {&lt;br /&gt;  5     return $k if $v == $val;&lt;br /&gt;  6   }&lt;br /&gt;  7 }&lt;br /&gt;  8 find_key(2) eq 'two' or die "key not found";&lt;br /&gt;  9 # and again&lt;br /&gt; 10 find_key(2) eq 'two' or die "key not found";&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;The call to find_key in line 10 fails, because it does not iterate through %h again, but continues where the last each call left off.&lt;br /&gt;&lt;br /&gt;This is the documented behavior, but one might not expect it.&lt;br /&gt;perldoc says: &lt;/span&gt;&lt;pre&gt;&lt;br /&gt;The next call to "each" after that will start iterating again.  There is a&lt;br /&gt;single iterator for each hash, shared by all "each", "keys", and "values"&lt;br /&gt;function calls in the program; it can be reset by reading all the elements&lt;br /&gt;from the hash, or by evaluating "keys HASH" or "values HASH".&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6180060022439114324-8817644772003516393?l=eintr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://eintr.blogspot.com/feeds/8817644772003516393/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://eintr.blogspot.com/2009/06/perl-gotcha-ii.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6180060022439114324/posts/default/8817644772003516393'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6180060022439114324/posts/default/8817644772003516393'/><link rel='alternate' type='text/html' href='http://eintr.blogspot.com/2009/06/perl-gotcha-ii.html' title='Perl Gotcha II'/><author><name>me</name><uri>http://www.blogger.com/profile/00999965525169315547</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6180060022439114324.post-2249520820463614458</id><published>2009-06-17T12:19:00.000-07:00</published><updated>2009-06-17T13:03:34.732-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl gotcha'/><title type='text'>Perl Gotcha I</title><content type='html'>&lt;span style="font-family:arial;"&gt;I'm trying to write some interesting, sometimes unexpected, things one can experience with Perl in the next time.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;They are partly based on a talk I did at the German Perl Workshop 2008, see &lt;a href="http://noxxi.de/pws/2008/perl-gotchas.html"&gt;my talk in german&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;How does the regex&lt;br /&gt;&lt;pre&gt;  m/foo$\nbar/m&lt;/pre&gt; gets interpreted?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;At first it looks like it matches "foo", then end of line with the $, then a newline with \n and finally "bar".&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Let' see:&lt;br /&gt;&lt;pre&gt;  my $string = "foo\nbar";&lt;br /&gt;  print $string =~/foo$\nbar/m ? 'match':'no match'&lt;/pre&gt;Surprisingly the regex does not match like expected.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The regex is interpreted as &lt;pre&gt;  /foo $\ nbar/mx&lt;/pre&gt; e.g. it matches "foo", then the content of the special variable $\ (usually undef) and finally "nbar"&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6180060022439114324-2249520820463614458?l=eintr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://eintr.blogspot.com/feeds/2249520820463614458/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://eintr.blogspot.com/2009/06/perl-gotcha-i.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6180060022439114324/posts/default/2249520820463614458'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6180060022439114324/posts/default/2249520820463614458'/><link rel='alternate' type='text/html' href='http://eintr.blogspot.com/2009/06/perl-gotcha-i.html' title='Perl Gotcha I'/><author><name>me</name><uri>http://www.blogger.com/profile/00999965525169315547</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6180060022439114324.post-9030116012818936291</id><published>2009-03-14T14:13:00.000-07:00</published><updated>2009-03-15T02:48:29.004-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Perl IPv6 GermanPerlWorkshop'/><title type='text'>The (bad) State of IPv6 in Perl</title><content type='html'>&lt;h1&gt;&lt;a name="hdr1"&gt;&lt;/a&gt;&lt;/h1&gt; &lt;h2&gt;&lt;a name="hdr1.1"&gt; Introduction &lt;/a&gt;&lt;/h2&gt; &lt;p&gt;IPv6 is the next generation internet protocol.  In the last time there were an increased technical and political activity for better support of IPv6.  &lt;/p&gt;&lt;p&gt;I'm working in a company which does a lot of networking stuff with Perl so we want to make use of IPv6 from Perl. So I did some research about this topic which resultat in a &lt;a href="http://noxxi.de/pws/2009/pdf/ipv6.pdf"&gt;talk (in german)&lt;/a&gt; held at the &lt;a href="http://www.perl-workshop.de/de/2009/index.html"&gt;German Perl Workshop 2009&lt;/a&gt; and some code.  &lt;/p&gt;&lt;p&gt;This article is a short summary of this talk in english, in the hope, that the topic will get more publicity and finally result in better IPv6 support in Perl.  &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;a name="hdr1.2"&gt;The current state is bad &lt;/a&gt;&lt;/h2&gt; &lt;p&gt;According to &lt;a href="http://www.personal.psu.edu/dvm105/blogs/ipv6/2008/02/ipv6-support-in-programming-li.html"&gt;IPv6 support in programming libraries&lt;/a&gt; the support for IPv6 in Perl is bad.  Although I really like programming in Perl I think the author of this blog is right: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul&gt; &lt;li&gt;There is no support for IPv6 in the Perl CORE.  &lt;/li&gt;&lt;li&gt;But one can program with IPv6 using Socket6 and IO::Socket::INET6 which is mostly the same like using Socket or IO::Socket::INET.  &lt;/li&gt;&lt;li&gt;But because these packages are not in CORE one has to either depend on them or each module has to fallback to IPv4 if these modules are not available.  &lt;/li&gt;&lt;li&gt;The result is, that none of the CORE modules and other famous modules can be used with IPv6, for example Net::SMTP, Net::POP3, Net::FTP, LWP, WWW::Mechanize (which is based on LWP).  &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;If modules have IPv6 support the implementation or usage is more complex, than it would be, if perl had IPv6 support in the CORE. For example: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul&gt; &lt;li&gt;AnyEvent does IPv6 but does not like to depend on Socket6 because it's not in CORE, so it has hard coded AF_INET6 for various operating systems, does it's own DNS lookup (slightly different from getaddrinfo), ...See AnyEvent::Socket.  &lt;/li&gt;&lt;li&gt;POE hast IPv4 code which uses inet_aton and gethostbyname, if it can find Socket6 it has similar code for IPv6 which uses inet_pton and getaddrinfo, see POE::Wheel::SocketFactory.  &lt;/li&gt;&lt;li&gt;IO::Socket::SSL depends in IO::Socket::INET6 if it finds it, otherwise it will use IO::Socket::INET (it used to be worse, see &lt;a href="http://www.personal.psu.edu/dvm105/blogs/ipv6/2008/07/perl-considered-harmful.html"&gt;Perl considered harmful&lt;/a&gt; &lt;/li&gt;&lt;li&gt;Net::LDAP need to be given a special 'inet6' switch if it should try to connect with IPv6 &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;a name="hdr1.3"&gt; Existing Workarounds &lt;/a&gt;&lt;/h2&gt; &lt;p&gt;The usual workaround is to code for IPv4 and have additional support for IPv6 if Socket6 or IO::Socket::INET6 is available. This does not help for existing modules, but there are some modules I've created in preparatation of the German Perl Workshop which might help: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul&gt; &lt;li&gt;Net::INET6Glue::INET_is_INET6 simply make IO::Socket::INET6 behave like IO::Socket::INET which helps for modules like Net::SMTP, Net::POP3, LWP (http connections only).  &lt;/li&gt;&lt;li&gt;Net::INET6Glue::FTP adds support for EPRT and EPSV to Net::FTP to make it IPv6 capable. This also helps LWP, because it uses Net::FTP for ftp connections.  &lt;/li&gt;&lt;li&gt;Net::SSLGlue::LWP forces LWP to use IO::Socket::SSL instead of Crypt::SSLeay/Net::SSL for https connections. Contrary to Net::SSL IO::Socket::SSL can do IPv6 (maybe Net::INET6Glue::INET_is_INET6 would make Net::SSL IPv6 capable too, but IO::Socket::SSL is the better choice anyway if you would like to have proper certificate checking) &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;a name="hdr1.4"&gt; What should be done &lt;/a&gt;&lt;/h2&gt; &lt;p&gt;&lt;/p&gt;&lt;ul&gt; &lt;li&gt;Add IPv6 support to the Perl CORE as soon as possible (e.g for perl5.10.X, do not wait for perl5.12 or perl6).  &lt;/li&gt;&lt;li&gt;One way would be to just as Socket6 and IO::Socket::INET6 as they are, but I would prefer to have IO::Socket::INET6 merged into IO::Socket::INET and Socket6 into Socket, to have just one Socket API, and not one API which does only IPv4 and another, which does IPv6+IPv4 (like Socket6 and IO::Socket::INET6 do).  This is what other modern languages (Python, Java) do.  &lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6180060022439114324-9030116012818936291?l=eintr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://eintr.blogspot.com/feeds/9030116012818936291/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://eintr.blogspot.com/2009/03/bad-state-of-ipv6-in-perl.html#comment-form' title='1 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6180060022439114324/posts/default/9030116012818936291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6180060022439114324/posts/default/9030116012818936291'/><link rel='alternate' type='text/html' href='http://eintr.blogspot.com/2009/03/bad-state-of-ipv6-in-perl.html' title='The (bad) State of IPv6 in Perl'/><author><name>me</name><uri>http://www.blogger.com/profile/00999965525169315547</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
