[17170] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4582 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 11 11:05:38 2000

Date: Wed, 11 Oct 2000 08:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <971276711-v9-i4582@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 11 Oct 2000     Volume: 9 Number: 4582

Today's topics:
    Re: A lot of s///g; feels like a slow idea. <godzilla@stomp.stomp.tokyo>
        a value of variable in child process <ken91174@aol.com>
    Re: a value of variable in child process (Rafael Garcia-Suarez)
    Re: a value of variable in child process <ken91174@aol.com>
        Bidirectional client-server : needs tweaking <bruce_phipps@my-deja.com>
        Calculating in Perl. <paul@crocodile.iis.nsk.su>
    Re: Calculating in Perl. (Rafael Garcia-Suarez)
    Re: Calculating in Perl. <epa98@doc.ic.ac.uk>
    Re: Calculating in Perl. <ubl@schaffhausen.de>
        Defining an Operator (not overloading) <yacob@rcn.com>
        File::Find How to pass parameters to wanted function <gio@ilogix.co.il>
    Re: File::Find How to pass parameters to wanted functio <jeffp@crusoe.net>
    Re: File::Find How to pass parameters to wanted functio <james@NOSPAM.demon.co.uk>
    Re: format() from a variable? (Damian Conway)
    Re: format() from a variable? <dwilgaREMOVE@mtholyoke.edu>
    Re: How do I change the position on screen where to pri mexicanmeatballs@my-deja.com
        How to remove all white spaces alichambers@madasafish.com
    Re: How to remove all white spaces <wyzelli@yahoo.com>
    Re: How to remove all white spaces <jeffp@crusoe.net>
    Re: included files: missing one important concept... (Gwyn Judd)
    Re: Is perl object oriented? (Gwyn Judd)
        Newbie question about LWP use <davesisk@ipass.net>
    Re: Newbie question about LWP use (Rafael Garcia-Suarez)
    Re: OPEN file efficiancy issue, <mjcarman@home.com>
        open without die?? <michael_roper@hotmail.com>
    Re: open without die?? <bill.kemp@wire2.com>
    Re: open without die?? (Rafael Garcia-Suarez)
    Re: open without die?? <wyzelli@yahoo.com>
        Perl CBT training suggestions? <johnssonm@nospam.accuread.com>
        pipe <mtveerman_nospam@mindless.com>
    Re: pipe <Cheng3@email.msn.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 11 Oct 2000 07:14:27 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: A lot of s///g; feels like a slow idea.
Message-Id: <39E475C3.531BB3DC@stomp.stomp.tokyo>

Jimmy Lantz wrote:

> I have the sub below and it's full of s///g; I think 
> I've seen a better way to do this somewhere,


I am very certain you have.


(snipped)

There is no need to envoke a series of regex
substitution engines for your input if your
input does not need to be filtered. Should
your input need to be filtered, there is no
need to envoke a series of regex substitution
engines for each and every character to be 
filtered. You will find this code more efficient
for your stated parameters.

Best of all, there is no need to use a memory
bloating module which will also slow down your
script, significantly.

if ($line =~ /[\W]/)
 {
  @Array = qw 
   (à¦&agrave á¦&aacute â¦&acirc ä¦&auml à¦&agrave á¦&aacute â¦&acirc ä¦&auml 
    è¦&egrave é¦&eacute ê¦&ecirc ë¦&euml Ȧ&Egrave ɦ&Eacute ʦ&Ecirc ˦&Euml 
    ì¦&igrave î¦&icirc í¦&iacute ï¦&iuml ̦&Igrave Φ&Icirc ͦ&Iacute Ϧ&Iuml 
    ò¦&ograve ó¦&oacute ô¦&ocirc ö¦&ouml ù¦&ouml ú¦&ugrave û¦&uacute ü¦&uuml 
    Ҧ&Ograve Ӧ&Oacute Ԧ&Ocirc ֦&Ouml ٦&Uuml ڦ&Ugrave ۦ&Uacute ܦ&Uuml);

 foreach $element (@Array)
  {
   ($key, $value) = split (/¦/, $element);
   if ($line =~ /$key/)
    { $line =~ s/$key/$value/g; }
  }
 }

Godzilla!


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

Date: Wed, 11 Oct 2000 20:11:30 +0900
From: ken <ken91174@aol.com>
Subject: a value of variable in child process
Message-Id: <20001011201008.2A2F.KEN91174@aol.com>


Hello,
I am studying fork.
How can I remain a variable in the child process?
For example,
-----------------------
$SIG{CHLD} = sub{wait};
$data = 0;
if ($pid == 0){
	#child
	$data = 1;
	exit;
}
#parent
while (wait != -1) #wait until all of child process die.
print "$data\n";
-----------------------
If I run the above code, 0 is displayed.
But I want to remain the value of $data in child process
and display 1.

Could you teach me how to do that?

With kind regards,
Ken

--------
ken <ken91174@aol.com>
I am Japanese.Please allow my childish English.




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

Date: Wed, 11 Oct 2000 11:25:32 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: a value of variable in child process
Message-Id: <slrn8u8jue.ios.rgarciasuarez@rafael.kazibao.net>

ken wrote in comp.lang.perl.misc:
>
>Hello,
>I am studying fork.
>How can I remain a variable in the child process?
>For example,
>-----------------------
>$SIG{CHLD} = sub{wait};
>$data = 0;
>if ($pid == 0){
>	#child
>	$data = 1;
>	exit;
>}
>#parent
>while (wait != -1) #wait until all of child process die.
>print "$data\n";
>-----------------------
>If I run the above code, 0 is displayed.
>But I want to remain the value of $data in child process
>and display 1.

Basically you want to pass data from your child process to its parent.
You can't do that easily because the child and the parent share no
memory. There are many ways to implement this, but I don't know what
you're trying to do. Look at the perlipc manpage for more info.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Wed, 11 Oct 2000 22:05:15 +0900
From: ken <ken91174@aol.com>
Subject: Re: a value of variable in child process
Message-Id: <20001011220332.E86C.KEN91174@aol.com>


Dear Rafael,

Thank you for advice.
I intend to look up perlipc.


With kind regards,
Ken
--------
ken <ken91174@aol.com>
I am Japanese. Please allow my childish English.



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

Date: Wed, 11 Oct 2000 15:33:29 +0100
From: "Bruce Phipps" <bruce_phipps@my-deja.com>
Subject: Bidirectional client-server : needs tweaking
Message-Id: <8s1tp8$400$1@sshuraac-i-1.production.compuserve.com>

I am writing some code to set up a bidirectional client-server connection.
The client code is based on "biclient" in the excellent Perl Cookbook. The
server code is my own work...so the any problems will probably come from
there.

Looking from the client end, expected behaviour is...
>one
>received by server: one
>two
>received by server: two

[the server acknowledges receipt of data from the server]

but I get:
>one
>two
>received by server: two
>three
>four
>received by server: four

Can someone help me on this, please?

================Client code================
#!/usr/bin/perl -w
# biclient - bidirectional forking client from perl Cookbook
    use strict;
use IO::Socket;
my($port, $host, $handle, $line, $kidpid);

$port = "1999";
$host = "localhost";

# create a tcp connection to the specified host and port
$handle = IO::Socket::INET->new(Proto     => "tcp",
                                PeerAddr  => $host,
                                PeerPort  => $port)
       or die "can't connect to port $port on $host: $!";

$handle->autoflush(1);              # so output gets there right away
print STDERR "[Connected to $host:$port]\n";

# split the program into two processes, identical twins
die "can't fork: $!" unless defined($kidpid = fork());

if ($kidpid) {
# parent copies the socket to standard output
  while (defined ($line = <$handle>)) {
        print STDOUT $line;
  }
   # kill("TERM" => $kidpid);        # send SIGTERM to child
}
else

  # child copies standard input to the socket
    while (defined ($line = <STDIN>)) {
        print $handle $line;
 }
}

#exit;
============end of Client code============

====================Server code================
#!/usr/bin/perl

use IO::Socket;

$local = IO::Socket::INET->new(Proto=>"tcp", LocalPort=>"1999", Listen=>1)
or die "Cannot create server socket: $!\n";

$remote = $local->accept;
$remote->autoflush(1);

while (<$remote>) {
$incoming = <$remote>;
#send acknowledgement to client
print $remote "received by server:$incoming";
}

close $local, $remote;

====================================end of server code=======

Thanks
Bruce





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

Date: Wed, 11 Oct 2000 17:26:53 +0700
From: Paul Dortman <paul@crocodile.iis.nsk.su>
Subject: Calculating in Perl.
Message-Id: <Pine.LNX.4.21.0010111607490.1337-100000@crocodile.iis.nsk.su>

Hello!

I'm writing program in Perl, that must perform calculation with certain
accuracy. I'll try to explain what I mean: I need to have all
calculations (addition, subtraction,  multiplication and division) only
with two or three digits after decimal point. Standard Perl calculation is
not appropriate, they have not high accuracy and it is not convenient to
round result each time.

Does anybody know is there any available module for these purposes?

Can anybody give me advice?

Thanks ia advance,
And sorry for my english.


Paul




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

Date: Wed, 11 Oct 2000 11:27:59 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Calculating in Perl.
Message-Id: <slrn8u8k31.ios.rgarciasuarez@rafael.kazibao.net>

Paul Dortman wrote in comp.lang.perl.misc:
>Hello!
>
>I'm writing program in Perl, that must perform calculation with certain
>accuracy. I'll try to explain what I mean: I need to have all
>calculations (addition, subtraction,  multiplication and division) only
>with two or three digits after decimal point. Standard Perl calculation is
>not appropriate, they have not high accuracy and it is not convenient to
>round result each time.

What do you want, higher or lower accuracy?
Lower accuracy can be achieved by rounding (use the sprintf function).
If you want higher accuracy, use the Math::BigFloat standard package.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: 11 Oct 2000 13:36:27 +0100
From: Edward Avis <epa98@doc.ic.ac.uk>
Subject: Re: Calculating in Perl.
Message-Id: <xn9u2aj8shg.fsf@texel35.doc.ic.ac.uk>

If you want floating-point calculations, but to display the answer
with only a few places of accuracy, then do all the calculations at
full precision and round the answer only to display it.  printf and
sprintf are useful for this:

printf("%.3f\n", 0.12345);

Don't round during the calculations or you'll lose accuracy.
(Probably so much accuracy that the result will be wrong even if it's
only shown to a few d.p.)

If you want to do calculations with a fixed number of decimal places
(eg dollars and cents), calculate using integers and divide by 100 (or
whatever) before printing.

-- 
Ed Avis
epa98@doc.ic.ac.uk


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

Date: Wed, 11 Oct 2000 15:23:27 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Calculating in Perl.
Message-Id: <39E469CE.307D7F63@schaffhausen.de>



Rafael Garcia-Suarez schrieb:

> Paul Dortman wrote in comp.lang.perl.misc:
> >Hello!
> >
> >I'm writing program in Perl, that must perform calculation with certain
> >accuracy. I'll try to explain what I mean: I need to have all
> >calculations (addition, subtraction,  multiplication and division) only
> >with two or three digits after decimal point. Standard Perl calculation is
> >not appropriate, they have not high accuracy and it is not convenient to
> >round result each time

Yeah but you shouldn't round one result more than once.

malte



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

Date: Wed, 11 Oct 2000 14:45:04 GMT
From: Daniel Yacob <yacob@rcn.com>
Subject: Defining an Operator (not overloading)
Message-Id: <8s1ude$abo$1@nnrp1.deja.com>

Greetings,

I've been searching for how to define a new operator in Perl and have
been coming up with lots of info on overloading operators which is not
what I want to do.

My interest is to simply define a new operator, imported from its own
package via 'use', and have it be functional for scalars, it can reject
any arguements that are refs.  What I'm after is a prefix operator that
would be similar to .=, lets call it `= though the choice is arbitrary
for discussion:

  $string `= $prefix;

performs:

  $string = $prefix . $string;

which happens to be a common occurance for me, I expect others as well.
Any help would be appreciated.

thanks,

/Daniel



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 11 Oct 2000 16:23:33 +0200
From: Gio <gio@ilogix.co.il>
Subject: File::Find How to pass parameters to wanted function
Message-Id: <39E477E5.11ED1051@ilogix.co.il>

Hi.
I'm trying to pass parameters to wanted function in the find function.
Something like this:

use strict;
use File::Find;

find (\&wanted(parameter), 'my_dir');

sub wanted {
    my $p = shift;
    ...
}

It does not work as it written above.

Any help is highly appreciated.




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

Date: Wed, 11 Oct 2000 10:17:14 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: File::Find How to pass parameters to wanted function
Message-Id: <Pine.GSO.4.21.0010111016020.14163-100000@crusoe.crusoe.net>

[posted & mailed]

On Oct 11, Gio said:

>I'm trying to pass parameters to wanted function in the find function.
>
>find (\&wanted(parameter), 'my_dir');
>
>sub wanted {
>    my $p = shift;
>    ...
>}

You can take a reference to a function with arguments being passed to
it.  You CAN, however, do something like:

  find(sub { wanted($param) }, @dirs);

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Wed, 11 Oct 2000 15:33:35 +0100
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: File::Find How to pass parameters to wanted function
Message-Id: <ant111435b49fNdQ@oakseed.demon.co.uk>

In article <39E477E5.11ED1051@ilogix.co.il>, Gio wrote:
> I'm trying to pass parameters to wanted function in the
> find function.

Something that Jeff Pinyan told me recently has made me think about
closures. It's still rather new to me, but your posting made me try it
out. You should be able to do what you want like this:

#!/usr/bin/perl -w

use strict;
use File::Find;

sub makewanted ($) {
    my $p = shift;

    return sub {
        print $p, "\n";
    }
}

find (makewanted(3), 'my_dir');
# ...
find (makewanted(17), 'my_dir');

-- 
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02



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

Date: 11 Oct 2000 14:25:13 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: format() from a variable?
Message-Id: <8s1t89$9bt$1@towncrier.cc.monash.edu.au>

belg4mit@mit.edu writes:

>So I've searched deja, TPC, the web, perlfaq, etc. And nothing...
>I'm not asking for much, really all I want to do is assign some value to
>a variable,
>and use this variable's value as my format.... Any ideas?

>I see that I can resort to formline, but is there another way?


You might like to try the C<form> subroutine from the Text::Autoformat
module.

Damian


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

Date: Wed, 11 Oct 2000 14:59:52 GMT
From: Dan Wilga <dwilgaREMOVE@mtholyoke.edu>
Subject: Re: format() from a variable?
Message-Id: <dwilgaREMOVE-9132A8.10594911102000@news.mtholyoke.edu>

In article <8s1t89$9bt$1@towncrier.cc.monash.edu.au>, damian@cs.monash.edu.au 
(Damian Conway) wrote:

> belg4mit@mit.edu writes:
> 
> >So I've searched deja, TPC, the web, perlfaq, etc. And nothing...
> >I'm not asking for much, really all I want to do is assign some value to
> >a variable,
> >and use this variable's value as my format.... Any ideas?
> 
> >I see that I can resort to formline, but is there another way?

Another way would be to use eval.

Dan Wilga          dwilgaREMOVE@mtholyoke.edu
** Remove the REMOVE in my address address to reply reply  **


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

Date: Wed, 11 Oct 2000 10:43:29 GMT
From: mexicanmeatballs@my-deja.com
Subject: Re: How do I change the position on screen where to print?
Message-Id: <8s1g8h$ula$1@nnrp1.deja.com>

In article <8s0eu8$f61@news.or.intel.com>,
  rdsmith@sedona.intel.com (Ron D. Smith~) wrote:
> In article <3fpC5.163$u23.12398@news000.worldonline.dk>, Anders Lund
<anders@wall.alweb.dk> writes:
> |> Peter Levi wrote:
> |>
> |> > Help guys!I want to show on the screen the process of downloading
a file -
> |> > so I have to print for example "12%, 12520 bytes read".And I want
this to
> |> > appear on one and the same place on the screen. (to replace the
previous
> |> > "10%, 10380 bytes read" for
> |> > example).How do I do this!Because currently  I print the new data
on a new
> |> > line - very embarassing and ugly!How can I change the position of
the
> |> > marker where I want to print?Peter
> |> >
> |>
> |> You'd like to take a look at Term::Screen
>
> Another suggestion that is easy to implement is:
>
> print "\c[[0Kfile: $file bytes: $bytes_read\r";
>
> this works iff your xterm behaves like a vt100.  The '\c[[0k' is
"clear to end of
> line" in vt100-speak. Next, you print the string, then you do a
carriage return
> (*not* a newline) which does not advance the output.
>
> This is hardly general (x,y) cursor positioning but it *does* help the
> "scrolling forever" problem, and it is an easy hack for most cases.
>

Well, if we're playing VT'terms then ESC[X;YH positions the cursor.
"\c[[$row;${column}H$message"

Use Term::Screen though..

--
Jon
perl -e 'print map {chr(ord($_)-3)} split //, "MrqEdunhuClqdph1frp";'


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 11 Oct 2000 13:17:11 GMT
From: alichambers@madasafish.com
Subject: How to remove all white spaces
Message-Id: <8s1p8h$5pb$1@nnrp1.deja.com>

Hi there

I have a designed a HTML form that allows users to enter their
address.  The form is processed with a PERL script and the form
postcode is assigned to $postcode.

I'd like to be able to remove all the whitespaces from the string. Eg-
BS1 1AA or BS 1 1 AA would both become BS11AA.

Can anyone help?

Many regards

Dr Alex Chambers


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 11 Oct 2000 23:06:01 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: How to remove all white spaces
Message-Id: <w0_E5.12$lw4.2476@vic.nntp.telstra.net>

<alichambers@madasafish.com> wrote in message
news:8s1p8h$5pb$1@nnrp1.deja.com...
> Hi there
>
> I have a designed a HTML form that allows users to enter their
> address.  The form is processed with a PERL script and the form
> postcode is assigned to $postcode.
>
> I'd like to be able to remove all the whitespaces from the string. Eg-
> BS1 1AA or BS 1 1 AA would both become BS11AA.
>
> Can anyone help?
>

Simply.

$string =~ s/\s+//g;

This will remove ALL whitespace from the string (including tabs etc)

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';




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

Date: Wed, 11 Oct 2000 10:19:15 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: How to remove all white spaces
Message-Id: <Pine.GSO.4.21.0010111018460.14163-100000@crusoe.crusoe.net>

[posted & mailed]

On Oct 11, alichambers@madasafish.com said:

>I'd like to be able to remove all the whitespaces from the string. Eg-
>BS1 1AA or BS 1 1 AA would both become BS11AA.

Either use s/// or tr///.  I'd suggest

  $string =~ tr/\r\n\t\f //d;

for speed.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Wed, 11 Oct 2000 12:11:56 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: included files: missing one important concept...
Message-Id: <slrn8u8m89.78n.tjla@thislove.dyndns.org>

I was shocked! How could Brian McDonald <mcdonabNO@SPAMyahoo.com>
say such a terrible thing:
>Hi. I believe that I am something of a dunce here. I've read perlfunc...
>perlfaq8... perlmod; I've combed through HUNDREDS of posts at deja; I've
>read dozens of replies to my (same) question, where the perl intelligentsia
>say "check perldoc do;perldoc require;perldoc use"... as if that is all that
>is needed for comprehension; I've seen many posters driven into the ground
>for asking this very question.
>
>And my post is sitting here... unresponded to... perhaps laughed at... (or
>silently and universally mocked???)

Hardly, give us all some ime to react. The time difference between your
first post and this one was barely 3 hours, maybe you need to be a
little more patience. Oh and if you've combed through hundreds of posts
at deja, how come you never read anyone saying you should always post
replies *below* the thing you are replying to?

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
There is no education that is not political.  An apolitical
education is also political because it is purposely isolating.


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

Date: Wed, 11 Oct 2000 12:18:21 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Is perl object oriented?
Message-Id: <slrn8u8mkb.78n.tjla@thislove.dyndns.org>

I was shocked! How could brian d foy <brian@smithrenaud.com>
say such a terrible thing:

>all the important features needed for OO are in Perl (although some
>may miss their favorite features) although the bondage and discipline
>are absent.

Oh Yeah? Well some of us *like* the Bondage and Discipline...oh wait
this isn't alt.java.whips.and.chains.beat.beat.beat is it? whoops

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
"I have walked in the valley of -"
'Good! Keep on walking.'
	-- Amis and G'Kar, "The Long Dark"


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

Date: Wed, 11 Oct 2000 13:56:11 GMT
From: "David Sisk" <davesisk@ipass.net>
Subject: Newbie question about LWP use
Message-Id: <%j_E5.25319$oA2.3809957@typhoon.southeast.rr.com>

My ISP (unix-based ) allows Perl scripts to be run, but doesn't have the LWP
module installed.  Can I simply upload the necessary modules into my private
directory?  If I put them in a dir called "lib" under the dir where the
script runs from (ie. ...cgi-bin/lib), will that work?  How do I "use" it?
use lib::UserAgent, for instance?  Do I need to upload all the modules
associated with LWP, or just the ones that I explicitly use?

Any help appreciated!  Please post or email...

Regards,
Dave





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

Date: Wed, 11 Oct 2000 14:40:58 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Newbie question about LWP use
Message-Id: <slrn8u8vcs.ji1.rgarciasuarez@rafael.kazibao.net>

David Sisk wrote in comp.lang.perl.misc:
>My ISP (unix-based ) allows Perl scripts to be run, but doesn't have the LWP
>module installed.  Can I simply upload the necessary modules into my private
>directory?  If I put them in a dir called "lib" under the dir where the
>script runs from (ie. ...cgi-bin/lib), will that work?  How do I "use" it?
>use lib::UserAgent, for instance?  Do I need to upload all the modules
>associated with LWP, or just the ones that I explicitly use?

The answer is in the faq, more precisely in the perlfaq8 section of the
docs: "How do I keep my own module/library directory?"

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Wed, 11 Oct 2000 07:53:59 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: OPEN file efficiancy issue,
Message-Id: <39E462E7.F711309E@home.com>

nobull@mail.com wrote:
> 
> Jimmy Lantz <webmaster@ostas.lu.se> writes:
> 
> > Is it faster not to close(IN) and then do a second "while"
> 
> Almost certainly the implicit close() by open() will be faster than a
> explicit close() since there's less bytecode being interpreted at
> run-time.  If you really wany to find out how much faster use
> Benchmark.pm.  I wouldn't be supprised if the effect was unmeasurably
> small.

Instead of closing and reopening (even implicitly) I'd use seek():

seek(IN, 0, 0);

That's due to my stylistic preferences rather than efficiency, though.
I'd expect it to be faster, but I've never benchmarked it.

-mjc


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

Date: Wed, 11 Oct 2000 23:13:52 +1000
From: "Michael Roper" <michael_roper@hotmail.com>
Subject: open without die??
Message-Id: <8s1l74$3vk$1@spacebar.ucc.usyd.edu.au>

Hi,
    Does anyone know what problems can arise by using open without the
standard 'or die' catch? ie
    open(FOO, ">$foo");
vs
    open(BAR, ">$bar") || die $!;

The reason I ask is that I have a large number of inherited Perl programs
running as CGI processes which end up WAITing on some thread which never
seem to give control back.
(Had a Netscape Fasttrack 3.01 daemon at 72 Megabytes with 475 active
threads (all from **100** broken Perl scripts hanging around in process
table) on a site with only a reasonably small number of hits before someone
restarted it!!

Any thoughts much appreciated,
Michael





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

Date: Wed, 11 Oct 2000 13:21:02 +0100
From: "W Kemp" <bill.kemp@wire2.com>
Subject: Re: open without die??
Message-Id: <971267153.12318.0.nnrp-13.c3ad6974@news.demon.co.uk>


Michael Roper wrote in message <8s1l74$3vk$1@spacebar.ucc.usyd.edu.au>...
>Hi,
>    Does anyone know what problems can arise by using open without the
>standard 'or die' catch? ie
>    open(FOO, ">$foo");
>vs
>    open(BAR, ">$bar") || die $!;


You need to do something, just in case.  Otherwise a file permission error,
or something really quite minor would be far harder to diagnose.

what about-

unless (open(FOO, ">$foo")  ) {
    # tell a log?
    # do something more useful
    # go on to another task
    # return (0) ?
}




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

Date: Wed, 11 Oct 2000 12:26:19 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: open without die??
Message-Id: <slrn8u8nfj.j2d.rgarciasuarez@rafael.kazibao.net>

Michael Roper wrote in comp.lang.perl.misc:
>Hi,
>    Does anyone know what problems can arise by using open without the
>standard 'or die' catch? ie
>    open(FOO, ">$foo");
>vs
>    open(BAR, ">$bar") || die $!;

This can erase your filesystem, or mail porn to Al Gore's children.
No kidding. Depends on what's after the unchecked open.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
use overload '""' => sub { shift @{ ( shift ) } };
sub japh { bless [ split /(?= )/ => $_[1] ] => $_[0] }
$_ = japh main "Just another Perl hacker,\n"; print; print; print; print;


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

Date: Wed, 11 Oct 2000 23:01:10 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: open without die??
Message-Id: <1YZE5.11$lw4.2151@vic.nntp.telstra.net>

"Michael Roper" <michael_roper@hotmail.com> wrote in message
news:8s1l74$3vk$1@spacebar.ucc.usyd.edu.au...
> Hi,
>     Does anyone know what problems can arise by using open without the
> standard 'or die' catch? ie
>     open(FOO, ">$foo");
> vs
>     open(BAR, ">$bar") || die $!;
>
> The reason I ask is that I have a large number of inherited Perl programs
> running as CGI processes which end up WAITing on some thread which never
> seem to give control back.
> (Had a Netscape Fasttrack 3.01 daemon at 72 Megabytes with 475 active
> threads (all from **100** broken Perl scripts hanging around in process
> table) on a site with only a reasonably small number of hits before
someone
> restarted it!!
>

The point is not so much that you should have the program 'die' but that you
should check for the success or otherwise of the open and make use of the
special variable $! to report why the open failed.  'die' is used to
illustrate the point simply.

I have seen the syntax:-

open (IN, "$filename") or &error ("failed to open $filename because $!");

and the error sub defined appropriately for the environment (print some html
advising the user to contact the webmaster?)

A program that does not check for the success of the open and then handle
the error condition can trundle on blindly and do a whole bunch of nothing
forever (which you seem to have experienced) or do really bad stuff or
unexpected stuff.

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';




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

Date: Wed, 11 Oct 2000 10:59:30 +0100
From: "M Johnsson" <johnssonm@nospam.accuread.com>
Subject: Perl CBT training suggestions?
Message-Id: <KPWE5.38$N81.20263@newsr1.u-net.net>

Hi all,

Does anyone know of any _good_ perl CBT training packages?
Beginner / Intermediate level.

Thanks  a mill
Matt




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

Date: Wed, 11 Oct 2000 13:17:37 +0200
From: "Maarten Veerman" <mtveerman_nospam@mindless.com>
Subject: pipe
Message-Id: <8s1i9v$ed6$1@news.tudelft.nl>

I want to redirect incoming mail to a perl script. I know it can be done by
opening the script with a pipe, e.g.: |script.pl

My question is:
How do I read the input? Can I use @ARGV for that? Or do I need to do some
special things?

Maarten




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

Date: Wed, 11 Oct 2000 08:57:00 -0400
From: "Liang Cheng" <Cheng3@email.msn.com>
Subject: Re: pipe
Message-Id: <eawgYH4MAHA.318@cpmsnbbsa07>

Well if you do pipe ie '|' the input in your STDIN filedescriptor, assuming
you use *nix.  You can do read <> or <STDIN> inorder to get that input.
example
ls | myscript.pl

#!/usr/bin perl -w
#this is myscript.pl
while(<>)
{
    print;
}
#this print out whatever is taken from ls

Good bye and good luck.
Maarten Veerman <mtveerman_nospam@mindless.com> wrote in message
news:8s1i9v$ed6$1@news.tudelft.nl...
> I want to redirect incoming mail to a perl script. I know it can be done
by
> opening the script with a pipe, e.g.: |script.pl
>
> My question is:
> How do I read the input? Can I use @ARGV for that? Or do I need to do some
> special things?
>
> Maarten
>
>




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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4582
**************************************


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