[25047] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7297 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 24 18:10:49 2004

Date: Sun, 24 Oct 2004 15:10:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 24 Oct 2004     Volume: 10 Number: 7297

Today's topics:
    Re: Missing functions in h2ph converted headers <usenet@morrow.me.uk>
    Re: Optimize Perl.. <perl@my-header.org>
    Re: Optimize Perl.. <perl@my-header.org>
    Re: perl optimazation guide/book (buildmorelines)
    Re: Practical Extraction Recording Language el_roachmeister@yahoo.com
    Re: Practical Extraction Recording Language <usa1@llenroc.ude.invalid>
    Re: Practical Extraction Recording Language <tadmc@augustmail.com>
    Re: Practical Extraction Recording Language <usa1@llenroc.ude.invalid>
    Re: Practical Extraction Recording Language (krakle)
        Problem with useless use error message (delfuego)
    Re: Problem with useless use error message <usa1@llenroc.ude.invalid>
        where download web application source code examples ? (Jasper)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 24 Oct 2004 17:07:33 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Missing functions in h2ph converted headers
Message-Id: <5j0t42-hm4.ln1@osiris.mauzo.dyndns.org>


Quoth cjs.lists@gmail.com (Chris Snell):
>
> I need to access the getifaddrs() function, as defined in ifaddrs.h on
> FreeBSD/OpenBSD/Mac OS X.  I'm trying to read the kernel's traffic
> counters for the machine's network interfaces.

It's possible you may be able to get the info you need with Net::Pcap: I
don't know what getifaddrs(2) does, so I can't tell.

> I ran h2ph on /usr/include/ifaddrs.h but it did not make the
> getifaddrs() function available to me.  How can I make this system
> call from Perl?

Don't use h2ph or syscall: they're a perl4 mechanism. Instead, write (or
check CPAN to see if someone else has written) an XS module that calls
the C function and returns the values you need in a perlish form. If you
are not happy with learning XS, you could try Inline::C instead, which
hides most of the XS for you and lets you get away with only knowing
Perl and C.

> Also, getifaddrs provides its data in a struct which contains other
> structs.  It's a pretty gnarly data structure.  Supposing that I can
> access this from Perl's syscall, how can I quickly determine the total
> size of the idaddrs struct that getifaddrs returns so that I can
> allocate space in my scalar for this data?

Errr.... you can't. :)

Using XS or Inline::C, you can allocate a buffer with 
NEWSV(1, sizeof(struct ifaddr)) (or whatever). To get at its members,
you use unpack: either unpack it yourself into a sensible Perl data
structure to return, or use Inline::Struct to wrap an object around it
(in which case you will probably need to copy the appropriate struct
defns from the header, and possibly provide typemaps for the members).

Good luck!

Ben

-- 
And if you wanna make sense / Whatcha looking at me for?          (Fiona Apple)
                            * ben@morrow.me.uk *


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

Date: Sun, 24 Oct 2004 20:33:27 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: Optimize Perl..
Message-Id: <8brnn01o5616qd2g6nelsohjkr273qaef6@4ax.com>

X-Ftn-To: A. Sinan Unur 

"A. Sinan Unur" <usa1@llenroc.ude.invalid> wrote:
>> Usually they have good articles but this one isn't nearly there, and I
>> doubt that author is just making jokes in it?
>
>It is an odd article. The author starts with non-issues and comes up with 
>the obvious solutions: "If you are going to concatenate a string a million 
>times, don't use a loop!"
>
>In any case, even if that is the level of the target audience, I would not 
>put much stock in this article. How can someone fail to mention the 
>Benchmark module in an article about optimization?

Yes, it would be nice to mention it; at first I was surprised with foreach
being replaced with map in void context, as a superior solution to foreach
loop? Then it shows some sorting example (yes, map is once again being
misused) where it shows caching technique altering primary data and calling
twice keys of the same hash. Then I looked back to the title and tried to
make some connection between them. :)



-- 
Matija


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

Date: Sun, 24 Oct 2004 20:33:28 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: Optimize Perl..
Message-Id: <3atnn0hmii80b2vhu6id6u4fub9fanikh3@4ax.com>

X-Ftn-To: Uri Guttman 

Uri Guttman <uri@stemsystems.com> wrote:
>        the speed difference between single and double quoted strings is
>        negligible. try a benchmark yourself. double quoted strings are
>        converted to a join of the string parts at compile time so there
>        is no runtime loss for simple strings.
>
>        want more? write to me at uri@sysarch.com.
>
>let's see if i get any response.

I hope they'll remove the article; the one thing that can happen is that
someone will read it and embrace as coding guidelines.



-- 
Matija


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

Date: 24 Oct 2004 08:10:54 -0700
From: bulk88@hotmail.com (buildmorelines)
Subject: Re: perl optimazation guide/book
Message-Id: <ee659c69.0410240710.474d06fa@posting.google.com>

John Bokma <postmaster@castleamber.com> wrote in message news:<Xns958BC988381C8castleamber@130.133.1.4>...
> buildmorelines wrote:
> 
> > The fasterness was determined by running a perl script that runs a
> > loop 20x that runs another perl through `` and processes smallprof.out
> > getting the average. The other perl being run through `` is a one line
> > perl program that is like "$r = pop(@array);" or "$r = $array[-1];"
> > running with -d:SmallProf on the command line arguments to the
> > interpreter.
> 
> http://search.cpan.org/~nwclark/perl-5.8.5/lib/Benchmark.pm
> 
> Note that benchmarks also depend on which Perl version you are running.

Here you go.

This is perl, v5.8.4 built for MSWin32-x86-multi-thread
(with 3 registered patches, see perl -V for more detail)

Copyright 1987-2004, Larry Wall

Binary build 810 provided by ActiveState Corp. http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Jun  1 2004 11:52:21


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

Date: 24 Oct 2004 11:00:52 -0700
From: el_roachmeister@yahoo.com
Subject: Re: Practical Extraction Recording Language
Message-Id: <5d705481.0410241000.649a77e1@posting.google.com>

As someone who has been programming in perl for several years, I found
the site useful. It was simple and well organized and I picked up
several new tips to add to my "arsenal". Yeah, it may not be 100%
accurate, but perl is about getting the job done, not about splitting
hairs.

Next time you insult someone's work, why dont you post a link of your
own tutorial?  Don't have one, I didnt think so.

"A. Sinan Unur" <usa1@llenroc.ude.invalid> wrote in message news:<Xns958CE837A2D0asu1cornelledu@132.236.56.8>...
> Just for laughs:
> 
> http://www.unc.edu/~husted/Work/PerlReference.htm#anchor8
> 
> Sinan.


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

Date: 24 Oct 2004 18:43:04 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Practical Extraction Recording Language
Message-Id: <Xns958C95B7BCBF0asu1cornelledu@132.236.56.8>

el_roachmeister@yahoo.com wrote in
news:5d705481.0410241000.649a77e1@posting.google.com: 

[ top posting corrected ... please do not do that 
  It seems like it is your first time posting here so
  please go ahead and read the posting guidelines.
]

> "A. Sinan Unur" <usa1@llenroc.ude.invalid> wrote in message
> news:<Xns958CE837A2D0asu1cornelledu@132.236.56.8>... 
>> Just for laughs:
>> 
>> http://www.unc.edu/~husted/Work/PerlReference.htm#anchor8

> As someone who has been programming in perl for several years, I found
> the site useful. 

If that is the case, then you might find http://learn.perl.org/ even 
more useful.

Sinan.


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

Date: Sun, 24 Oct 2004 13:51:10 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Practical Extraction Recording Language
Message-Id: <slrncnnucu.fpi.tadmc@magna.augustmail.com>

Uri Guttman <uri@stemsystems.com> wrote:
>>>>>> "ASU" == A Sinan Unur <usa1@llenroc.ude.invalid> writes:
> 
>  ASU> Just for laughs:
>  ASU> http://www.unc.edu/~husted/Work/PerlReference.htm#anchor8


> 	; - The semicolon is the part of Perl language that terminates a
>             statement. A perl statement is an expression or series of
>             expressions that will not be executed without the semicolon.
> 
> huh??? perl -e 'print "the author is a doofus\n"'
> 
> don't see no ; there!


Just so that we might realize some practical value from shredding
the bullshit that is that "reference" page, let's learn about the role
of semicolon.

In most languages the semicolon is a "statement terminator" so it
must terminate each statement.

It is not like that in Perl.

In Perl the semicolon is a "statement separator" so it is only
needed when you have 2 statements that need "separating". 

This is why the final semicolon in any block is optional in Perl.
You leave it off at the end, or if you put it in, you are really
inserting an "empty statement" (which has no effect) after the
final (visible) statement.


> this page is mind boggling.


It really packed in the grins-per-sentence, I feel better after
a humor break like that.

Thanks for posting the link Sinan, it was a real hoot!


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 24 Oct 2004 19:03:45 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Practical Extraction Recording Language
Message-Id: <Xns958C993914DB1asu1cornelledu@132.236.56.8>

Tad McClellan <tadmc@augustmail.com> wrote in 
news:slrncnnucu.fpi.tadmc@magna.augustmail.com:

> Thanks for posting the link Sinan, it was a real hoot!

You are welcome. I had googled for something and it came up second or third 
so I decided to follow the link. It took a while for my initial reaction to 
subside and then I realized it might be appreciated over here.

Sinan.


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

Date: 24 Oct 2004 12:41:39 -0700
From: krakle@visto.com (krakle)
Subject: Re: Practical Extraction Recording Language
Message-Id: <237aaff8.0410241141.504e3449@posting.google.com>

"A. Sinan Unur" <usa1@llenroc.ude.invalid> wrote in message news:<Xns958CE837A2D0asu1cornelledu@132.236.56.8>...
> Just for laughs:
> 
> http://www.unc.edu/~husted/Work/PerlReference.htm#anchor8
> 
> Sinan.

A great college education UNC offers...


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

Date: 24 Oct 2004 11:21:12 -0700
From: djcameron60616@yahoo.com (delfuego)
Subject: Problem with useless use error message
Message-Id: <6b28e43f.0410241021.3ba24178@posting.google.com>

Hello,

I am trying to write a simple Perl program to do the following:
Open /etc/passwd for read, create an output file in cwd for append,
cut the fields 1,3-4,6 from /etc/passwd and redirect that output to
the output file password, then close the two file handles for the
input and output files.

Here is the code:

#!/usr/bin/perl -w
#
my $FIN;
my $FOUT;
#
open ($FIN, "</etc/passwd") or die "Cannot open input file.\n";
open ($FOUT, ">>password") or die "Cannot open output file.\n";
#
while ($myline = <$FIN>) {
    readline($FIN);
    $myline=$printable;
    print($FOUT,$printable,"\n");
i    $myline = chop($myline = `cut -d: -f1,3-4,6`);
}
#
close ($FIN);
close ($FOUT);
#

Here is the error message:

[root@localhost james]# ./program.pl
Use of uninitialized value in print at ./program.pl line 12, <$FIN>
line 2.
GLOB(0x804ca88)
 
[root@localhost james]#


Thank you for your help.

James


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

Date: 24 Oct 2004 18:57:33 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Problem with useless use error message
Message-Id: <Xns958C982C1C1F7asu1cornelledu@132.236.56.8>

djcameron60616@yahoo.com (delfuego) wrote in 
news:6b28e43f.0410241021.3ba24178@posting.google.com:

> Hello,
> 
> I am trying to write a simple Perl program to do the following:
> Open /etc/passwd for read, create an output file in cwd for append,
> cut the fields 1,3-4,6 from /etc/passwd and redirect that output to
> the output file password, then close the two file handles for the
> input and output files.
> 
> Here is the code:
> 
> #!/usr/bin/perl -w

use strict;
use warnings;

If you haven't done so already, please read the posting guidelines posted 
here regularly.

> my $FIN;
> my $FOUT;

> open ($FIN, "</etc/passwd") or die "Cannot open input file.\n";
> open ($FOUT, ">>password") or die "Cannot open output file.\n";

I recommend using the 3 argument form of open. You also don't need to 
declare $FIN and $FOUT separately. Finally, it is useful to report the 
actual reason open failed:

open my $FIN, '<', '/etc/passwd' 
    or die "Cannot open '/etc/passwd': $!";

open my $FOUT, '>>', 'password' 
    or die "Cannot open 'password': $!";

> while ($myline = <$FIN>) {

while(my $myline = <$FIN>) {

OK, so you have read a line from $FIN.

>     readline($FIN);

Now, you read another line and discard it.

>     $myline=$printable;

But this is the best. You now replace the contents of the line you had 
earlier managed to read and store in $myline with the contents of 
$printable. However, $printable is undef at this point. If you had used 
strict, you would have caught this error.

>     print($FOUT,$printable,"\n");

Now that you have nuked $myline you attempt to output $printable to $FOUT. 
You might want to check 

perldoc -f print

because this will never output aything to $FOUT.

> i    $myline = chop($myline = `cut -d: -f1,3-4,6`);

Ahem, what is that 'i' up there. Oh, I see, you did not actually post the 
code you ran on your system. Don't do that.

So, now you are over-writing the line you had stored in $myline with the 
return value of the chop call. Do you know what chop returns? I have a 
feeling you don't. You can look it up:

perldoc -f chop


> [root@localhost james]# ./program.pl
> Use of uninitialized value in print at ./program.pl line 12, <$FIN>
> line 2.
> GLOB(0x804ca88)

perl has just told you everything I said above.

> [root@localhost james]#

Are you sure you want to mess with your system's crucial files while you 
are logged in as root?

> Thank you for your help.

You are welcome.

Sinan.


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

Date: 24 Oct 2004 11:36:09 -0700
From: jasper_marzin@yahoo.com (Jasper)
Subject: where download web application source code examples ?
Message-Id: <89b27d52.0410241036.198f58aa@posting.google.com>

Hi building an ecommerce website here, is there anywhere on the web
one can download the perl source for a basic one ?  Its probably a
search problem but I cant find any..

thanks !

Jasper


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

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 V10 Issue 7297
***************************************


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