[30934] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2179 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 3 03:10:26 2009

Date: Tue, 3 Feb 2009 00:09:50 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 3 Feb 2009     Volume: 11 Number: 2179

Today's topics:
        Can't figure this code out <yo@dude.yo>
    Re: Can't figure this code out <tadmc@seesig.invalid>
    Re: Can't figure this code out <ben.usenet@bsb.me.uk>
    Re: Can't figure this code out <cwilbur@chromatico.net>
    Re: Extracting printf(...) from  (void) printf(....) sln@netherlands.com
    Re: Extracting printf(...) from (void) printf(....) <guru.naveen@gmail.com>
        new CPAN modules on Tue Feb  3 2009 (Randal Schwartz)
    Re: Perl IP to Domain Name converter. <1usa@llenroc.ude.invalid>
    Re: Perl Peeves <hansmu@xs4all.nl>
    Re: pipe perl output to a bash command error snowsmash@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 2 Feb 2009 22:52:34 +0000 (UTC)
From: Ben Bacarisse <yo@dude.yo>
Subject: Can't figure this code out
Message-Id: <lnF8t8zuzi.fsf@nuthaus.mib.org>


I'm writing a little text game, and the interpreter is spitting back
an error for the following simple line: 

print "CLC complete-flood death countdown: 72 hours\n";

What the hell is a "broken token sequence"?


------------------------------

Date: Mon, 2 Feb 2009 17:58:01 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Can't figure this code out
Message-Id: <slrngof249.ans.tadmc@tadmc30.sbcglobal.net>


Ben Bacarisse <yo@dude.yo> wrote:


Why did you set followups to comp.lang.c?


> I'm writing a little text game, and the interpreter is spitting back
> an error for the following simple line: 


Line numbers in error messages are often incorrect so you often
need to look several lines before the line number called out
in the message...


> print "CLC complete-flood death countdown: 72 hours\n";


There is nothing wrong with that line of code:

    perl -we 'print "CLC complete-flood death countdown: 72 hours\n"'

works fine.


> What the hell is a "broken token sequence"?


Please post verbatim error message text.

Have you seen the Posting Guidelines that are posted here frequently?

The perldiag.pod man page lists all of the messages that perl
might issue.

It does not list that message, so it is not coming from perl.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


------------------------------

Date: Tue, 03 Feb 2009 00:30:43 +0000
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: Can't figure this code out
Message-Id: <87zlh4fjkc.fsf@bsb.me.uk>

Tad J McClellan <tadmc@seesig.invalid> writes:

> Ben Bacarisse <yo@dude.yo> wrote:
>
> Why did you set followups to comp.lang.c?

For the record: the original message had nothing to do with me.  It
looks like someone is practising for a back-spatter attack on
comp.lang.c.  I sometimes post here and I read this group with interest
so, I do care what people think.

-- 
Ben.


------------------------------

Date: Mon, 02 Feb 2009 19:49:25 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Can't figure this code out
Message-Id: <861vuguyy2.fsf@mithril.chromatico.net>

>>>>> "TJM" == Tad J McClellan <tadmc@seesig.invalid> writes:

    TJM> Why did you set followups to comp.lang.c?

comp.lang.c is suffering an assault from an asshat troll who's figured
out how to forge posts.  Its latest tactic is to forge inane questions
in other groups in the name of comp.lang.c regulars and set followups to
comp.lang.c.

Charlton


-- 
Charlton Wilbur
cwilbur@chromatico.net


------------------------------

Date: Mon, 02 Feb 2009 20:51:41 GMT
From: sln@netherlands.com
Subject: Re: Extracting printf(...) from  (void) printf(....)
Message-Id: <bsjeo4p6ojjpguu84kiclrjrbanr0nfq0g@4ax.com>

On 2 Feb 2009 18:54:43 GMT, jt@toerring.de (Jens Thoms Toerring) wrote:

>sln@netherlands.com wrote:
>> On Mon, 2 Feb 2009 06:04:50 -0800 (PST), guru <guru.naveen@gmail.com> wrote:
>
>> >How to search for (void) from the line.
>> >
>> >ex: (void) printf(....)
>> >
>> >I want to search if (void) is there at the beggining of the line.. if
>> >exist then extract printf(....) function.
>> >
>> >Please let me know how it can be done or tell me the reference so that
>> >I can try.
>
>> I assume this is just an example, the key phrase is 'void' and printf has
>> nothing to do with it.
>
>> printf() from CRT returns type 'int', the number of characters written.
>> To cast the return value to type (void) serves no purpose since only pointers
>> can be of type 'void', ie: not variables.
>
>It may not serve any purpose to the C compiler, but there are code
>testing tools like lint that complain when the return value of a
>function isn't used. And to keep lint etc. from doing so in cases
>where disregarding the return value is exactly what you want it is
>not uncommon practise to cast the such return values to '(void)'
>since lint only then understands that you don't want to do anything
>with it and shuts up.

Years ago, I read the description of Lint, even tried a code checker once.
Later on (a couple of years ago), I tried the Bounds Checker suite of stuff.
Total hogwash!! Bogged down bloated, slow, erroneous piece of crap.

Casting a function return value to void does not cast anything unless its assigned
to an lvalue, and then only as (void *). Other than that, nothing can be cast as void
except in function prototypes. I'm not suprised a Lint type tool can't tell the difference.
Possibly because the compiler will let any non-assignment type void cast take place.
Don't think Lint doesent use compiler compliant constructs, it does.
Lint is just a stoopid usless tool.

Imagine seeing (void) function(....) all over the code, possibly surrounded by define's.
What a dream job that would be to have to maintane such crap. Same with unit test bull crap.
Imagine having to code review that.

>
>To the OP: Of course you can search for such lines with something
>like
>
>/^\s*\(\s*void\*\)\s*printf\(.*?\)\s*;/
>
>or, if it's not just about printf() but all functions,
>
>/^\s*\(\s*void\*\)\s*[A-Za-z0-9_]+\s*\(.*?\)\s*;/
  ^
The beginning of the line doesen't matter.
There is no capture in this regex.

>
>but there are more possible cases like
>
>    if (some_condition) (void) printf(...);

Or            var = (void) printf(...);
Oh, that won't compile.

>
>or
>
>    do_something(); (void) printf(...);
>
>just to name a few - so just looking for the first piece of code
>on a line won't catch all instances. You would have to use at least
>(I probably forgot a few possibilities) something like the fol-
>lowing (assuming the function call isn't split up into more than
>one line):
>
>/(^|;|\)|,|}|(*/))\s*\(\s*void\*\)\s*[A-Za-z0-9_]+\s*\(.*?\)\s*;/
            ^ metachar, needs to be escaped
>/(^|;|\)|,|}|(*/))\s*\(\s*void\*\)\s*[A-Za-z0-9_]+\s*\(.*?\)\s*;/
              ^^^^ capturing a quantifier and a foward slash, the regex delimeter
>/(^|;|\)|,|}|(*/))\s*\(\s*void\*\)\s*[A-Za-z0-9_]+\s*\(.*?\)\s*;/
  ^^^^^^^^^^^^^^^^^ capturing, why?   ^                     ^ no capturing of function, why?
>/(^|;|\)|,|}|(*/))\s*\(\s*void\*\)\s*[A-Za-z0-9_]+\s*\(.*?\)\s*;/
                                      ^^^^^^^^^^^^^
functions can't begin with numeric digits, only underscore pluls alpha or alpha alone.
Better this (?:_[a-zA-Z]|[a-zA-Z])[\w-]

>/(^|;|\)|,|}|(*/))\s*\(\s*void\*\)\s*[A-Za-z0-9_]+\s*\(.*?\)\s*;/
                                       ^^^^^^^^^^ this is \w

>/(^|;|\)|,|}|(*/))\s*\(\s*void\*\)\s*[A-Za-z0-9_]+\s*\(.*?\)\s*;/
  ^^^^^^^^^^^^^^^^^
This is the right approach, but this is only needed if the line were being parsed
on a line-based, multiple occurances of (void) fn(..); within a looping while in
global context. As we know this is still inadequate.
In its simplest form, something like this might be enough but its not even close.
   /\(\s*void\s*\)\s*((?:_[a-zA-Z]|[a-zA-Z])[\w-]*\s*\(.*\))\s*;/

>
>But even that it still might get a few cases wrong (e.g. if you
>have printf()s with weird format strings like "xyz);" etc.) or
>produce false positives. To get it 100% right I guess you would
>have to write a parser for C, regexps probably aren't good enough
>for this since they just look at the input stream but without
>"understanding" what it means. To see how hairy C code can look
>like check out the winning entries of the obfuscated C contest;-)
>
>                                  Regards, Jens

Still though, to parse this with other than a full on C/C++ parser would involve much
more complexities. Thats not saying it can't be done with regular expressions.
If you can do   while(/./sg) {}  , then you can parse anything on the planet. And it is
a regular expression.

sln





------------------------------

Date: Mon, 2 Feb 2009 20:31:45 -0800 (PST)
From: guru <guru.naveen@gmail.com>
Subject: Re: Extracting printf(...) from (void) printf(....)
Message-Id: <60fdfcfb-8228-43e8-8725-4bfa75bd7034@x16g2000prn.googlegroups.com>

On Feb 2, 10:12=A0pm, s...@netherlands.com wrote:
> On Mon, 02 Feb 2009 16:54:19 GMT, s...@netherlands.com wrote:
> >On Mon, 2 Feb 2009 06:04:50 -0800 (PST), guru <guru.nav...@gmail.com> wr=
ote:
>
> >>HI all
>
> >>How to search for (void) from the line.
>
> [snip]
> >and be mixed with comments. A better solution is to get a C++ parser som=
ewhere.
>
> >But, if this isn't real source code text and all you want to do is parse=
 anything
> >in (void) "function(anything)" on a line by line basis, I guess you coul=
d adopt a quick and
> >dirty approach, something like this:
>
> >while (<DATA>) =A0# no caching of lines, raw per-line basis
> >{
> > =A0 =A0chomp;
> > =A0 =A0if (/(\s*void\s*)\s*([a-z][\w-]*?\s*\(.*\)\s*)/ { # greedy () in=
 liue of balanced parenthesis
>
> =A0 =A0 =A0 =A0 =A0 =A0 ^^^
> I forgot to mention this is untested. After looking at it a bit, this may=
 be better:
>
> =A0 =A0 =A0 =A0 /\(\s*void\s*\)\s*([a-zA-Z][\w-]*\s*\(.*\))/
>
> Gee, there are alot of paren's in this one..
>
> sln- Hide quoted text -
>
> - Show quoted text -

HI

yes this is not a real example.

the acually the pattern will be of type

1. (void) function(....)
2. function(....)
3. return (function(....)........)

I want to extract the function(....) from the above type of lines.

Thanks & Regards
Gururaja


------------------------------

Date: Tue, 3 Feb 2009 05:42:26 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Tue Feb  3 2009
Message-Id: <KEH6Iq.17ov@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Alien-BatToExeConverter-0.01
http://search.cpan.org/~adamk/Alien-BatToExeConverter-0.01/
Convert a DOS Batch Script to an Executable 
----
Apache2-ASP-2.23
http://search.cpan.org/~johnd/Apache2-ASP-2.23/
ASP for Perl, reloaded. 
----
Apache2-EmbedMP3-0.1
http://search.cpan.org/~damog/Apache2-EmbedMP3-0.1/
Embed MP3 audio files into a templated web interface using WP Audio Player. 
----
App-FQStat-6.2
http://search.cpan.org/~smueller/App-FQStat-6.2/
Interactive console front-end for Sun's grid engine 
----
CPAN-Reporter-Smoker-Safer-0.03
http://search.cpan.org/~davidrw/CPAN-Reporter-Smoker-Safer-0.03/
Turnkey smoking of installed distros 
----
CPAN-Testers-WWW-Statistics-0.60
http://search.cpan.org/~barbie/CPAN-Testers-WWW-Statistics-0.60/
CPAN Testers Statistics website. 
----
CPAN-WWW-Testers-0.47
http://search.cpan.org/~barbie/CPAN-WWW-Testers-0.47/
Present CPAN Testers data 
----
CPAN-WWW-Testers-0.48
http://search.cpan.org/~barbie/CPAN-WWW-Testers-0.48/
Present CPAN Testers data 
----
Catalyst-Controller-WrapCGI-0.0026
http://search.cpan.org/~rkitover/Catalyst-Controller-WrapCGI-0.0026/
Run CGIs in Catalyst 
----
Catalyst-Plugin-Session-Store-BerkeleyDB-0.02
http://search.cpan.org/~jrockway/Catalyst-Plugin-Session-Store-BerkeleyDB-0.02/
store sessions in a berkeleydb 
----
Catalyst-View-TT-ForceUTF8-0.12
http://search.cpan.org/~lyokato/Catalyst-View-TT-ForceUTF8-0.12/
(DEPRECATED) Template View Class with utf8 encoding 
----
Cindy-0.01
http://search.cpan.org/~jzobel/Cindy-0.01/
use unmodified XML or HTML documents as templates. 
----
Class-Sniff-0.04
http://search.cpan.org/~ovid/Class-Sniff-0.04/
Look for class composition code smells 
----
Class-Sniff-0.05
http://search.cpan.org/~ovid/Class-Sniff-0.05/
Look for class composition code smells 
----
Config-Model-OpenSsh-1.202
http://search.cpan.org/~ddumont/Config-Model-OpenSsh-1.202/
OpenSsh configuration files editor 
----
Crypt-FSHP-0.2.1
http://search.cpan.org/~bdd/Crypt-FSHP-0.2.1/
Fairly Secure Hashed Passwords. A PKCS#5 PBKDF1 similar implementation. 
----
Crypt-FSHP-0.2.2
http://search.cpan.org/~bdd/Crypt-FSHP-0.2.2/
Fairly Secure Hashed Passwords. A PKCS#5 PBKDF1 similar implementation. 
----
Data-Rx-0.006
http://search.cpan.org/~rjbs/Data-Rx-0.006/
perl implementation of Rx schema system 
----
Git-CPAN-Patch-0.1.0
http://search.cpan.org/~yanick/Git-CPAN-Patch-0.1.0/
Patch CPAN modules using Git 
----
Graphics-GnuplotIF-Shortcut-0.03
http://search.cpan.org/~borisz/Graphics-GnuplotIF-Shortcut-0.03/
Alternate interface to Graphics::GnuplotIF 
----
HTML-FormHandler-0.11
http://search.cpan.org/~gshank/HTML-FormHandler-0.11/
form handler written in Moose 
----
Hash-FieldHash-0.02
http://search.cpan.org/~gfuji/Hash-FieldHash-0.02/
A lightweight fieldhash implementation 
----
Lingua-Any-Numbers-0.25
http://search.cpan.org/~burak/Lingua-Any-Numbers-0.25/
Converts numbers into (any available language) string. 
----
Mail-Log-Trace-1.0101
http://search.cpan.org/~dstaal/Mail-Log-Trace-1.0101/
Trace an email through the mailsystem logs. 
----
Math-Polynomial-Solve-2.12
http://search.cpan.org/~jgamble/Math-Polynomial-Solve-2.12/
Find the roots of polynomial equations. 
----
MediaWiki-Bot-Plugin-CUP-0.3.1
http://search.cpan.org/~dcollins/MediaWiki-Bot-Plugin-CUP-0.3.1/
a plugin for MediaWiki::Bot which contains data retrieval tools for the 2009 WikiCup hosted on the English Wikipedia 
----
MediaWiki-Bot-Plugin-SE-0.2.0
http://search.cpan.org/~dcollins/MediaWiki-Bot-Plugin-SE-0.2.0/
a plugin for MediaWiki::Bot which contains data retrieval tools for the 2009 Steward elections 
----
MooseX-Role-Matcher-0.03
http://search.cpan.org/~doy/MooseX-Role-Matcher-0.03/
generic object matching based on attributes and methods 
----
MooseX-Types-Common-0.001000
http://search.cpan.org/~groditi/MooseX-Types-Common-0.001000/
----
Nagios-Object-0.21.2
http://search.cpan.org/~duncs/Nagios-Object-0.21.2/
----
Net-Mosso-CloudFiles-0.35
http://search.cpan.org/~lbrocard/Net-Mosso-CloudFiles-0.35/
Interface to Mosso CloudFiles service 
----
Net-OpenSSH-0.24
http://search.cpan.org/~salva/Net-OpenSSH-0.24/
Perl SSH client package implemented on top of OpenSSH 
----
Net-OpenSSH-0.25
http://search.cpan.org/~salva/Net-OpenSSH-0.25/
Perl SSH client package implemented on top of OpenSSH 
----
Net-OpenSSH-0.26
http://search.cpan.org/~salva/Net-OpenSSH-0.26/
Perl SSH client package implemented on top of OpenSSH 
----
PAR-Dist-0.44
http://search.cpan.org/~smueller/PAR-Dist-0.44/
Create and manipulate PAR distributions 
----
PAR-Repository-Client-0.23_02
http://search.cpan.org/~smueller/PAR-Repository-Client-0.23_02/
Access PAR repositories 
----
POE-Component-Fuse-0.04
http://search.cpan.org/~apocal/POE-Component-Fuse-0.04/
Using FUSE in POE asynchronously 
----
POE-Component-Fuse-0.05
http://search.cpan.org/~apocal/POE-Component-Fuse-0.05/
Using FUSE in POE asynchronously 
----
POE-Component-Server-SOAP-1.14
http://search.cpan.org/~apocal/POE-Component-Server-SOAP-1.14/
publish POE event handlers via SOAP over HTTP 
----
POE-Component-SimpleDBI-1.26
http://search.cpan.org/~apocal/POE-Component-SimpleDBI-1.26/
Asynchronous non-blocking DBI calls in POE made simple 
----
POE-Component-SmokeBox-Recent-1.10
http://search.cpan.org/~bingos/POE-Component-SmokeBox-Recent-1.10/
A POE component to retrieve recent CPAN uploads. 
----
POE-Component-SpreadClient-0.07
http://search.cpan.org/~apocal/POE-Component-SpreadClient-0.07/
Handle Spread communications in POE 
----
POE-Component-SpreadClient-0.08
http://search.cpan.org/~apocal/POE-Component-SpreadClient-0.08/
Handle Spread communications in POE 
----
Padre-Plugin-AcmePlayCode-0.08
http://search.cpan.org/~fayland/Padre-Plugin-AcmePlayCode-0.08/
Acme::PlayCode Plugin for Padre 
----
Padre-Plugin-Alarm-0.04
http://search.cpan.org/~fayland/Padre-Plugin-Alarm-0.04/
Alarm Clock in Padre 
----
Provision-Unix-0.42
http://search.cpan.org/~msimerson/Provision-Unix-0.42/
provision accounts on unix systems 
----
Provision-Unix-0.43
http://search.cpan.org/~msimerson/Provision-Unix-0.43/
provision accounts on unix systems 
----
SMS-Send-UK-Kapow-0.06
http://search.cpan.org/~jjones/SMS-Send-UK-Kapow-0.06/
SMS::Send driver for the Kapow.co.uk website 
----
SWISH-Filter-0.11
http://search.cpan.org/~karman/SWISH-Filter-0.11/
filter documents for indexing with Swish-e 
----
Set-Relation-0.2.0
http://search.cpan.org/~duncand/Set-Relation-0.2.0/
Relation data type for Perl 
----
Simo-0.05_01
http://search.cpan.org/~kimoto/Simo-0.05_01/
Very simple framework for Object Oriented Perl. 
----
Simo-0.05_02
http://search.cpan.org/~kimoto/Simo-0.05_02/
Very simple framework for Object Oriented Perl. 
----
Simo-0.05_03
http://search.cpan.org/~kimoto/Simo-0.05_03/
Very simple framework for Object Oriented Perl. 
----
Simo-0.05_04
http://search.cpan.org/~kimoto/Simo-0.05_04/
Very simple framework for Object Oriented Perl. 
----
Storable-AMF-0.49
http://search.cpan.org/~grian/Storable-AMF-0.49/
Perl extension for serialize/deserialize AMF0/AMF3 data 
----
String-Urandom-0.05
http://search.cpan.org/~mbrooks/String-Urandom-0.05/
Generate a truely random string 
----
String-Urandom-0.06
http://search.cpan.org/~mbrooks/String-Urandom-0.06/
Generate a truely random string 
----
Symbol-Util-0.01
http://search.cpan.org/~dexter/Symbol-Util-0.01/
Additional utils for Perl symbols manipulation 
----
Sys-Statistics-Linux-0.45
http://search.cpan.org/~bloonix/Sys-Statistics-Linux-0.45/
Front-end module to collect system statistics 
----
TAP-Formatter-HTML-0.07
http://search.cpan.org/~spurkis/TAP-Formatter-HTML-0.07/
TAP Test Harness output delegate for html output 
----
Test-Able-0.02
http://search.cpan.org/~jdv/Test-Able-0.02/
----
Test-Able-0.03
http://search.cpan.org/~jdv/Test-Able-0.03/
----
Test-Apocalypse-0.01
http://search.cpan.org/~apocal/Test-Apocalypse-0.01/
Apocalypse's favorite tests bundled into a simple interface 
----
Test-Apocalypse-0.02
http://search.cpan.org/~apocal/Test-Apocalypse-0.02/
Apocalypse's favorite tests bundled into a simple interface 
----
Test-POE-Server-TCP-0.18
http://search.cpan.org/~bingos/Test-POE-Server-TCP-0.18/
A POE Component providing TCP server services for test cases 
----
Tk-DateEntry-1.38_90
http://search.cpan.org/~srezic/Tk-DateEntry-1.38_90/
Drop down calendar widget for selecting dates. 
----
Tk-DateEntry-1.38_91
http://search.cpan.org/~srezic/Tk-DateEntry-1.38_91/
Drop down calendar widget for selecting dates. 
----
WWW-Shorten-2.02
http://search.cpan.org/~davecross/WWW-Shorten-2.02/
Interface to URL shortening sites. 
----
YAML-LoadURI-0.01
http://search.cpan.org/~fayland/YAML-LoadURI-0.01/
Load YAML from URI file 
----
ZConf-BGSet-0.1.0
http://search.cpan.org/~vvelox/ZConf-BGSet-0.1.0/
A perl module for background management. 
----
jaipo-0.0.6
http://search.cpan.org/~bluet/jaipo-0.0.6/
----
minismokebox-0.10
http://search.cpan.org/~bingos/minismokebox-0.10/
a small lightweight SmokeBox 
----
minismokebox-0.12
http://search.cpan.org/~bingos/minismokebox-0.12/
a small lightweight SmokeBox 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


------------------------------

Date: Tue, 03 Feb 2009 00:23:26 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl IP to Domain Name converter.
Message-Id: <Xns9BA6C53F164D3asu1cornelledu@127.0.0.1>

RedGrittyBrick <RedGrittyBrick@spamweary.invalid> wrote in
news:49870cbe$0$30301$da0feed9@news.zen.co.uk: 

> http://www.osix.net/modules/article/?id=194
> 
> Ick!

Ick! is right. For many reasons. Here is one:

<quote src="http://www.osix.net/modules/article/?id=194">
sub resolve_ip {
    my($this_ip);
    foreach $this_ip (keys %cached_ips) {
        $_[0] eq $this_ip ? return($cached_ips{$this_ip}) :"";
    }
    return(cache_ip($_[0]));
} 

sub cache_ip { 
    my $name;
    if( ($name= gethostbyaddr(inet_aton($_[0]), AF_INET)) eq "" ){
        return($cached_ips{$_[0]}=$_[0]);
    } else {
        return($cached_ips{$_[0]}=$name);
    }
}
</quote>

This is insanely bad. Here is something less bad:

#!/usr/bin/perl

use strict;
use warnings;

use Memoize;
use Socket;

memoize( 'resolve_ip' );

while ( <DATA> ) {
    chomp;
    last unless length;
    print "Looking up '$_'\n\t";
    print resolve_ip( $_ ), "\n";
}

sub resolve_ip {
    my ($ip) = @_;
    
    my $name = gethostbyaddr inet_aton($ip), AF_INET;

    return $name if defined $name;
    return $ip;
}

__DATA__
74.125.45.100
68.180.206.184
207.46.197.32
74.125.45.100
68.180.206.184
207.46.197.32

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


------------------------------

Date: Tue, 03 Feb 2009 03:53:11 +0100
From: Hans Mulder <hansmu@xs4all.nl>
Subject: Re: Perl Peeves
Message-Id: <4987b2d5$0$194$e4fe514c@news.xs4all.nl>

Jürgen Exner wrote:

> Either way, if unary + were to act like the unary -, i.e. evaluating its
> argument as a scalar and returning the numerical value of it, that would
> be more consistent with at least my intuitive expectations.

Your expectations are off: unary - does not always take the numerical
value of its argument:

$ perl -lwe '$x="blah"; print -$x;'
-blah

Perldoc perlop describes what unary - does with string arguments.

Hope this helps,

-- HansM







------------------------------

Date: Tue, 3 Feb 2009 00:02:18 -0800 (PST)
From: snowsmash@gmail.com
Subject: Re: pipe perl output to a bash command error
Message-Id: <ca900c6a-b4ff-4842-a9b4-fc2adab14d60@y1g2000pra.googlegroups.com>

On Feb 2, 3:18=A0pm, j...@toerring.de (Jens Thoms Toerring) wrote:
> Josef Moellers <josef.moell...@fujitsu-siemens.com> wrote:
> > TarekElganainywrote:
> > > I was wondering why the first line give me output but the second
> > > don't, any clue!!
>
> > > 1. while sleep 2;do printf "1\n1\n"|perl -e 'while ( <> )
> > > { print; }';done|perl -e 'while ( <> ) { print; }'
>
> > > 2. while sleep 2;do printf "1\n1\n"|perl -e 'while ( <> )
> > > { print; }';done|perl -e 'while ( <> ) { print; }'|cat
> >Buffering?
> > In the first instance, the last perl is writing to the screen, so the
> > output is unbuffered. In the second instance, the last perl is writing
> > to a pipe, hence the output is buffered and will appear only when a
> > couple of kilobytes have accumulated.
> > The first perl instance in each pipeline only does 2 lines, then exits
> > and flushes its buffers.
> > Just an (un?)educated guess,
>
> s/\(un\?\)//
>
> You can also test that this is the case. E.g. if you replace
>
> while sleep 2
>
> with
>
> while [ -n "qqq" ]
>
> or something similar that's always true then, after a delay needed
> to fill the buffer, you start getting output from 'cat'.
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Regards, J=
ens
> --
> =A0 \ =A0 Jens Thoms Toerring =A0___ =A0 =A0 =A0j...@toerring.de
> =A0 =A0\__________________________ =A0 =A0 =A0http://toerring.de



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 2179
***************************************


home help back first fref pref prev next nref lref last post