[29976] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1219 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 21 18:09:38 2008

Date: Mon, 21 Jan 2008 15:09:05 -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           Mon, 21 Jan 2008     Volume: 11 Number: 1219

Today's topics:
    Re: A do-file location: how the code inside that do-fil <ced@blv-sam-01.ca.boeing.com>
    Re: Activestate help files calling out <1usa@llenroc.ude.invalid>
        More perl tutorials <clarjon1@gmail.com>
    Re: More perl tutorials <uri@stemsystems.com>
    Re: More perl tutorials <joost@zeekat.nl>
    Re: More perl tutorials <joost@zeekat.nl>
    Re: More perl tutorials <uri@stemsystems.com>
    Re: More perl tutorials <thepoet_nospam@arcor.de>
    Re: More perl tutorials <bik.mido@tiscalinet.it>
    Re: More perl tutorials <1usa@llenroc.ude.invalid>
    Re: More perl tutorials <usenet@davidfilmer.com>
    Re: Pipe input over several scripts xhoster@gmail.com
    Re: Pipe input over several scripts <glex_no-spam@qwest-spam-no.invalid>
    Re: sprintf rouding error <bart.lateur@pandora.be>
    Re: Wait for background processes to complete <dougie.stevenson@gmail.com>
        What's the best way to test existence of arguments <pgodfrin@gmail.com>
    Re: What's the best way to test existence of arguments <joost@zeekat.nl>
    Re: What's the best way to test existence of arguments <jurgenex@hotmail.com>
    Re: What's the best way to test existence of arguments <pgodfrin@gmail.com>
    Re: What's the best way to test existence of arguments <bik.mido@tiscalinet.it>
    Re: What's the best way to test existence of arguments <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 21 Jan 2008 15:02:46 -0800 (PST)
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: A do-file location: how the code inside that do-file find it?
Message-Id: <1280542d-d926-4329-8f2b-3ae1c3fcb4ac@u10g2000prn.googlegroups.com>

On Jan 19, 9:32 pm, S P Arif Sahari Wibowo <arifs...@yahoo.com> wrote:
> Hi!
>
> Let's say script A call a subscript B either by
> do, require, or use. Now the code inside
> subscript B need to  know what the
> ** file location of subscript B ***.
> How this can be done? The perldoc page of do
> mentioned that perl will keep track the
> file name (e.g. for error reporting), how to
> get access to this
> ** file name ** recorded by  perl?
>

Did you need the script's "file location"... or "file name"... because
you mention both.

I would have thought 'FindBin' (perldoc FindBin) would have been the
best answer if the former.

--
Charles DeRykus


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

Date: Mon, 21 Jan 2008 23:01:10 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Activestate help files calling out
Message-Id: <Xns9A2CB74BBE4C4asu1cornelledu@127.0.0.1>

"~greg" <g_m@remove-comcast.net> wrote in
news:RKudnf6AesEoAAnanZ2dnUVZ_uCinZ2d@comcast.com: 

> Anyone know why the activestate help files call out over the internet?

What makes you think that? I have not noticed that. I have 5.8.8, maybe 
something changed in the new package?

So, please describe what you are seeing and tell us the version you are 
using.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>



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

Date: Mon, 21 Jan 2008 18:28:21 +0000 (UTC)
From: clarjon1 <clarjon1@gmail.com>
Subject: More perl tutorials
Message-Id: <fn2o85$nad$1@registered.motzarella.org>

Hi all, this appears to be the right spot to post this.

I'm teaching myself Perl, after learning about the language thanks to the 
Linux Gazette.  I've been reading through the perldoc and perltut, and 
have downloaded a few ebooks on the subject, and am working through them.

I was wondering what materials, either online or offline, you would 
recommend for me to read?  Something along the lines of what a self-
teaching high-school level student would find useful.  Thanks!

-- 
clarjon1
clarjon1 at gmail dot com


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

Date: Mon, 21 Jan 2008 19:10:53 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: More perl tutorials
Message-Id: <x7fxwrq9j6.fsf@mail.sysarch.com>

>>>>> "c" == clarjon1  <clarjon1@gmail.com> writes:

  c> Hi all, this appears to be the right spot to post this.  I'm
  c> teaching myself Perl, after learning about the language thanks to
  c> the Linux Gazette.  I've been reading through the perldoc and
  c> perltut, and have downloaded a few ebooks on the subject, and am
  c> working through them.

  c> I was wondering what materials, either online or offline, you would
  c> recommend for me to read?  Something along the lines of what a
  c> self- teaching high-school level student would find useful.
  c> Thanks!

first off ignore almost every single perl tutorial on the web. there are
dozens and they just about all suck. they are full of errors,
mistatements, misunderstandings of the docs, and just awful writing. one
day when i rule the world, i will post reviews of them all and flog their
authors with python printouts.

there is a decent free book called beginning perl and you can find it on
beginners.perl.org.

i will guess that the ebooks you downloaded are bootlegs so you should
either pay for them or not use them. i have only seen bootlegs of
o'reilly books or bad books (not that there aren't good perl books that
aren't o'reilly but i haven't seen bootlegs of those).

you can buy ebooks cheaply enough of most of the quality perl
books. there are places which list many good perl books and you can ask
here for more recommendations.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Architecture, Development, Training, Support, Code Review  ------
-----------  Search or Offer Perl Jobs  ----- http://jobs.perl.org  ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Mon, 21 Jan 2008 20:16:39 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: More perl tutorials
Message-Id: <878x2jhtuw.fsf@zeekat.nl>

clarjon1 <clarjon1@gmail.com> writes:

> Hi all, this appears to be the right spot to post this.
>
> I'm teaching myself Perl, after learning about the language thanks to the 
> Linux Gazette.  I've been reading through the perldoc and perltut, and 
> have downloaded a few ebooks on the subject, and am working through them.
>
> I was wondering what materials, either online or offline, you would 
> recommend for me to read?  Something along the lines of what a self-
> teaching high-school level student would find useful.  Thanks!
>

The O'Reilly "Learning Perl" and "Programming Perl" books are widely
regarded as good. Programming Perl may not have the right structure for
a beginner, and it's definitely more of a reference book, but it's very
readable and I actually preferred it to the Learning Perl book, but that
was when Learning Perl was in the first edition, and I'm told it's
improved a lot since then.

For both books, you should make sure you get the latest editions.

Note that none of the books AFAIK have info on perl 5.8 and higher. So
for reliable/up-to-date docs on ithreads, unicode (5.8ish) and the new
operators in 5.10, you're probably best off reading the man pages (but
as a beginner the only thing you may *need* is more info on the
unicode/utf8 system - depending on the kind of data/languages you're
dealing with).

From the man pages, you may want to check out:

perldata, perldsc, perlrequick, and maybe other things mentioned under
tutorials in the "perl" man page. And personally, I find perltoc very
useful when I want to find the right man page for some subject. As are
"perldoc -q something" and "perldoc -r something".

Joost.


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

Date: Mon, 21 Jan 2008 20:23:30 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: More perl tutorials
Message-Id: <874pd7htjh.fsf@zeekat.nl>

Uri Guttman <uri@stemsystems.com> writes:

> beginners.perl.org

That doesn't seem to work. I think this is the same book:

http://www.perl.org/books/beginning-perl/

Joost.


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

Date: Mon, 21 Jan 2008 20:21:08 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: More perl tutorials
Message-Id: <x7lk6jorpo.fsf@mail.sysarch.com>

>>>>> "JD" == Joost Diepenmaat <joost@zeekat.nl> writes:

  JD> Uri Guttman <uri@stemsystems.com> writes:
  >> beginners.perl.org

  JD> That doesn't seem to work. I think this is the same book:

my brain fart. i knew it was up on perl.org

  JD> http://www.perl.org/books/beginning-perl/

that is the book. the OP should read that first.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Architecture, Development, Training, Support, Code Review  ------
-----------  Search or Offer Perl Jobs  ----- http://jobs.perl.org  ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Mon, 21 Jan 2008 21:40:17 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: More perl tutorials
Message-Id: <479501ac$0$27202$9b4e6d93@newsspool1.arcor-online.net>

clarjon1 wrote:
> Hi all, this appears to be the right spot to post this.
> 
> I'm teaching myself Perl, after learning about the language thanks to the 
> Linux Gazette.  I've been reading through the perldoc and perltut, and 
> have downloaded a few ebooks on the subject, and am working through them.
> 
> I was wondering what materials, either online or offline, you would 
> recommend for me to read?  Something along the lines of what a self-
> teaching high-school level student would find useful.  Thanks!

What really brought my attention to the interesting facets of
Perl programming were the perlgolf tournaments, that have sadly
(almost?) ceased activity. The goal in perlgolfing is to solve
a given problem in a given time frame with the least number of
keystrokes. A real golfing course also comes with a test suite
that makes sure that no side constraints get overlooked. There
have also been quite a number of minigolf challenges organized
by Terje Kristensen that make for an interesting read.

It's often astounding how easily really complex problems can be
solved. And though most golf solutions include the one or other
"dirty trick" to spare keystrokes, there's a lot to learn
about Perl's builtin variables and efficient data manipulation.

The links are
http://terje2.frox25.no-ip.org
http://perlgolf.sourceforge.net/

There's also the fun-with-perl mailing list, that takes a
similar approach without the tournament characteristics:
http://lists.cpan.org/showlist.cgi?name=fun-with-perl

-Chris


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

Date: Mon, 21 Jan 2008 21:51:35 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: More perl tutorials
Message-Id: <6c1ap31epg0footr6o76u1fi9p2p95i4u3@4ax.com>

On Mon, 21 Jan 2008 21:40:17 +0100, Christian Winter
<thepoet_nospam@arcor.de> wrote:

>What really brought my attention to the interesting facets of
>Perl programming were the perlgolf tournaments, that have sadly
>(almost?) ceased activity. The goal in perlgolfing is to solve
>a given problem in a given time frame with the least number of
>keystrokes. A real golfing course also comes with a test suite
>that makes sure that no side constraints get overlooked. There
>have also been quite a number of minigolf challenges organized
>by Terje Kristensen that make for an interesting read.

I personally believe that golf is cool, and I wholeheartedly disagree
with those that see in it a major risk for Perl. However I would also
shy away from recommending it as a *learning tool*.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Mon, 21 Jan 2008 22:55:21 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: More perl tutorials
Message-Id: <Xns9A2CB64F1914asu1cornelledu@127.0.0.1>

Joost Diepenmaat <joost@zeekat.nl> wrote in news:874pd7htjh.fsf@zeekat.nl:

> Uri Guttman <uri@stemsystems.com> writes:
> 
>> beginners.perl.org
> 
> That doesn't seem to work.

ITHM http://learn.perl.org/

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>



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

Date: Mon, 21 Jan 2008 14:59:40 -0800
From: David Filmer <usenet@davidfilmer.com>
Subject: Re: More perl tutorials
Message-Id: <ZPudnZ6U6oIBvgja4p2dnAA@giganews.com>

Michele Dondi wrote:
> However I would also shy away from recommending [Perl golf]
 > as a *learning tool*.

I agree with that.  In fact, I would recommend almost the opposite - 
read Perl Best Practices by Damian Conway.  It should be the second book 
that any Perl learner reads.  _PBP_ and the techniques used in golf have 
few intersections.



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

Date: 21 Jan 2008 16:28:45 GMT
From: xhoster@gmail.com
Subject: Re: Pipe input over several scripts
Message-Id: <20080121112847.235$sG@newsreader.com>

spoertsch <spoertsch@gmail.com> wrote:
> Hi,
>
> The problem is that script c is not getting the input.
>
> Script A:
> #!/usr/bin/perl
> use strict;
> use warnings;
> use IPC::Open2;
>
> my @input   = ('test1', 'test2', 'test3', 'test4');
> my $out     = "";
> my $timeout = 7200;
> my $RDR;
> my $WTR;
> my $cmd = 'perl script_b.pl';
>
> my $pid = open2($RDR,$WTR, $cmd) || die("ERROR: Could not execute: " .
> $cmd);
>
> foreach (@input){
>     print $WTR $_."\n";
> }

You are cramming all of the output into script_b.  Because script_b uses
buffered input, it reads a large chunk of input, essentially being all
of the input intended for both b and c, but processes only the first
two lines.  Nothing is left for c to read as it is sitting in b's internal
buffer.

If you make script_a print exactly and only that input expected by
script_b, then issue a read (to get script_bs response), then print the
rest of the data, then it will work.  Or make script_b use unbuffered reads
to read only that input that it needs, leaving the rest in the OS-level
buffer where script_c can get it.


> Script B:
> #!/usr/bin/perl
> use strict;
> use warnings;
> my $input = '';
>
> print "Input 1: ";
> chomp($input = <STDIN>);

replace the <STDIN> with:

sysread STDIN, $input, 1, length $input until $input =~ /\n/;
chomp $input;

(may need to adjust /\n/ to reflect whatever line ending you are using.)

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Mon, 21 Jan 2008 10:31:37 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Pipe input over several scripts
Message-Id: <4794c8ea$0$515$815e3792@news.qwest.net>

spoertsch wrote:
> Hi,
> 
> The problem is that script c is not getting the input.
[...]
> system('perl script_c.pl');
> print "Script B finished\n";

Of course not, you're not passing it anything. Use a similar
open2 that you did in the first script, printing to $WTR,
or pass the arguments on the command line.

I find it odd that you know how to use open2 in one script
and don't have any idea how to use it to pass information,
in the next script.


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

Date: Mon, 21 Jan 2008 22:30:30 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: sprintf rouding error
Message-Id: <iu6ap3l12mgpcarsad1ko376g3ttd26cns@4ax.com>

Broki@gmx.de wrote:

>x=1.5;sprintf("%.0f",$x);->2 [ok]
>BUT
>$x=5830*1.15; ->the calculated 6704.5 gets rounded down to 6704 ![not
>okay].
>
>Is this a known problem?!

It is caused by the fact that in binary presentation, 1.15 is not
exactly the same as 115/100. Just like 1/3 is not exactly the same as
0.333333333...  There's a limited number of bits available to represent
that number, and it's not enough for an exact representation -- you'd
need an infinite number of bits, because 5 is not a power of 2. Just
like 3 is not a power of 10.

-- 
	Bart.


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

Date: Mon, 21 Jan 2008 09:39:34 -0800 (PST)
From: "Dougie!" <dougie.stevenson@gmail.com>
Subject: Re: Wait for background processes to complete
Message-Id: <55a1b188-9654-4051-a096-20caae1f8657@j78g2000hsd.googlegroups.com>

On Jan 13, 9:08 pm, pgodfrin <pgodf...@gmail.com> wrote:
> Greetings,
> Well - I've spent a bunch of time trying to figure this out - to no
> avail.
>
> Here's what I want to do - run several commands in the background and
> have the perl program wait for the commands to complete. Fork doesn't
> do it, nor does wait nor waitpid.
>
> Any thoughts?
>
> Here's a sample program which starts the processes:
>
>    while (<*.txt>)
>    {
>         print "Copying  $_ \n";
>         system("cp $_ $_.old &") ;
>    }
>    print "End of excercise\n";
>    exit;
>
> I mean if this were a shell program - this would work:
>
>    for x in `ls *.txt`
>    do
>       print "Copying  $_ \n"
>       cp $_ $_.old &
>    done
>    wait
>
> thanks,
> pg

I know you're probably looking for something very simple.  Amazing how
simple things get really complex.

Take a look at http://poe.perl.org/ - specifically the Job Server in
the Cookbook section.
anding framework for doing stuff like what you are looking to do.

Dougie!!!



POE Rocks... It is an outst


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

Date: Mon, 21 Jan 2008 09:11:33 -0800 (PST)
From: pgodfrin <pgodfrin@gmail.com>
Subject: What's the best way to test existence of arguments
Message-Id: <23a9fb9a-b1a5-42b8-ae65-4cc89b6546ac@s13g2000prd.googlegroups.com>

Greetings,

Is there a better way to test for existence of arguments besides
$#ARGV ? I have a little program that uses -s via the getopts module,
and if that option is used I want to force an argument. I suppose I
could use getopts(s:) - but I wondered if there is another "clean" way
to do that?

pg


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

Date: Mon, 21 Jan 2008 18:24:30 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: What's the best way to test existence of arguments
Message-Id: <87d4rvhz1t.fsf@zeekat.nl>

pgodfrin <pgodfrin@gmail.com> writes:

> Greetings,
>
> Is there a better way to test for existence of arguments besides
> $#ARGV ? I have a little program that uses -s via the getopts module,
> and if that option is used I want to force an argument. I suppose I
> could use getopts(s:) - but I wondered if there is another "clean" way
> to do that?

GetOpt::Long should give you all the control you'd need, including
default values, types and real named options and readable variable
names. It's a bit more verbose than GetOpt, but IMO it's also more
readable and definitely more flexible.

Joost.


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

Date: Mon, 21 Jan 2008 17:32:13 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: What's the best way to test existence of arguments
Message-Id: <sll9p318gfkubmulcvo3rrrrhgj3kh8241@4ax.com>

pgodfrin <pgodfrin@gmail.com> wrote:
>Is there a better way to test for existence of arguments besides
>$#ARGV ?

What about using @ARGV in scalar context?
	if (! @ARGV) {
		#I got no command line arguments
	}

jue


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

Date: Mon, 21 Jan 2008 09:42:30 -0800 (PST)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: What's the best way to test existence of arguments
Message-Id: <5719ad8d-2445-4f9e-9376-51d258cbc5e5@i72g2000hsd.googlegroups.com>

On Jan 21, 11:32 am, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> pgodfrin <pgodf...@gmail.com> wrote:
> >Is there a better way to test for existence of arguments besides
> >$#ARGV ?
>
> What about using @ARGV in scalar context?
>         if (! @ARGV) {
>                 #I got no command line arguments
>         }
>
> jue

doy - I'm a nitwit...
thanks,
pg


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

Date: Mon, 21 Jan 2008 21:47:21 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: What's the best way to test existence of arguments
Message-Id: <g61ap31h6akodjk7jliipeshdj68nm86ur@4ax.com>

On Mon, 21 Jan 2008 09:11:33 -0800 (PST), pgodfrin
<pgodfrin@gmail.com> wrote:

>Is there a better way to test for existence of arguments besides
>$#ARGV ? I have a little program that uses -s via the getopts module,

@ARGV


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Mon, 21 Jan 2008 20:32:41 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: What's the best way to test existence of arguments
Message-Id: <94cf65-kjb.ln1@osiris.mauzo.dyndns.org>


Quoth pgodfrin <pgodfrin@gmail.com>:
> 
> Is there a better way to test for existence of arguments besides
> $#ARGV ? 

I would use @ARGV in scalar context rather than $#ARGV, but what's wrong
with that?

    @ARGV or die "You need an argument!\n";

seems pretty clear to me.

> I have a little program that uses -s via the getopts module,
> and if that option is used I want to force an argument. I suppose I
> could use getopts(s:)

 ...or indeed that?

Ben



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

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 1219
***************************************


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