[15736] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3149 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 24 14:15:33 2000

Date: Wed, 24 May 2000 11:15:22 -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: <959192122-v9-i3149@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 24 May 2000     Volume: 9 Number: 3149

Today's topics:
    Re: Q: exec output into string (Gwyn Judd)
    Re: Q: exec output into string nobull@mail.com
    Re: Simple alphabetical name sort tasher1234@my-deja.com
    Re: Testing the getstore function in the LWP::Simple mo <rootbeer@redcat.com>
    Re: timeout a perl script? <rootbeer@redcat.com>
    Re: Trouble running perlcc baconrad@my-deja.com
    Re: Trouble running perlcc <rootbeer@redcat.com>
    Re: use english <bmb@dataserv.libs.uga.edu>
    Re: valid email address <khera@kciLink.com>
    Re: Writing a concurrent server in perl <sweeheng@usa.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 24 May 2000 15:08:11 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Q: exec output into string
Message-Id: <slrn8iqgit.be8.tjla@thislove.dyndns.org>

I was shocked! How could Thomas Åhlen <thomas2@dalnet.se>
say such a terrible thing:
>How do i get the output from en executed program inta a $string.
>
>I have done it thi way before:
>
>my $sys_cmd = "du -ks " . $path;
>$string = `$sys_cmd`;
>
>But i want to use exec instead:
>
>exec 'du', '-ks', $path
>    or die "can't exec du: $!";
>
>How do i get the output from exec to $string.

Well using exec() for this purpose is pretty pointless since the whole
purpose of exec is it replaces the running program (ie. your script)
with the exec'ed program. What about this:

open(DU, "du -ks|") || die "cannot fork: $!";

while (<DU>)
{
	$string .= $_;
}

but for this purpose I think $string = `du -ks`; is heaps better. This
is exactly the purpose it was designed for.

-- 
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
I saw you smile and my mind could not erase the beauty of your face.
		-- Richard Marx


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

Date: 24 May 2000 17:47:36 +0100
From: nobull@mail.com
Subject: Re: Q: exec output into string
Message-Id: <u9u2fnki8n.fsf@wcl-l.bham.ac.uk>

"Thomas Åhlen" <thomas2@dalnet.se> writes:

> How do i get the output from en executed program inta a $string.
> 
> I have done it thi way before:
> 
> my $sys_cmd = "du -ks " . $path;
> $string = `$sys_cmd`;
> 
> But i want to use exec instead:
> 
> exec 'du', '-ks', $path
>     or die "can't exec du: $!";
> 
> How do i get the output from exec to $string.

# A popen that works like system()
sub popen {
    # First argument must be "|-" or "-|"
    my $handle = new FileHandle;
    my $pid = $handle->open(shift);
    return undef unless defined $pid;
    unless ($pid) {
	# Child
        exec @_;		
        die "Failed to exec $_[0]: $!";
    }
    $handle; 
}	

my $handle = popen '-|', 'du', '-ks', $path or die; 
my $string = join ' ', <$handle>;
close($handle) or die;

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 24 May 2000 16:40:52 GMT
From: tasher1234@my-deja.com
Subject: Re: Simple alphabetical name sort
Message-Id: <8gh0mh$ifq$1@nnrp1.deja.com>

In article <8gebk1$q96$1@clematis.singnet.com.sg>,
  "Swee Heng" <sweeheng@usa.net> wrote:
> <tasher1234@my-deja.com> wrote in message
> news:8ge91f$kgb$1@nnrp1.deja.com...
> > Okay, I can't believe that this hasn't been done before, but I've
> > looked all through this news group and I can't find one sort routine
> > that just sorts names by last,middle initial and first name.
> > My fields are entered like so:
> > first name, middle initial (if any) and last name.
> > The problem is that if there is no middle initial then the sort
> > incorrectly compares the last name with the middle initial.
> > For example here is how it sorts:
> > Mary Khaliq
> > Mary L. Bash
> > Eric Larsen
> > Here is my code:
> Here is mine:
> ^^^^^^^^^^^^^
> @array = ('Mary Khaliq', 'Mary L. Bash', 'Eric Larsen',
>           'Donald Duck', 'Donald E. Duck', 'Donald G. Duck',
>           'Tom E. Duck', 'April E. Duck', 'Peter Pan');
> print "$_\n" for sort ByLMF @array;
> sub ByLMF {
>     ($aF, $aM, $aL) = $a=~ /^(\w+)\s*(.*)\s+(\w+)$/;
>     ($bF, $bM, $bL) = $b=~ /^(\w+)\s*(.*)\s+(\w+)$/;
>     ($aL cmp $bL) || ($aM cmp $bM) || ($aF cmp $bF);
> }
>
> OUTPUT:
> ^^^^^^^
> Mary L. Bash
> Donald Duck
> April E. Duck
> Donald E. Duck
> Tom E. Duck
> Donald G. Duck
> Mary Khaliq
> Eric Larsen
> Peter Pan
>
> Seems to work fine. Adapt it to your purpose.
>
> Swee Heng

To Swee Heng,
     Thanks for your prompt reply.  It doesn't quite work.
Here is what my input file looks like:
Location:Adel
Name:Bill Guske
Address:100 North 8th
Phone:515-993-5555

Location:Adel
Name:Mike Hammen
Address:100 North 8th
Phone:515-993-4551

Location:Adel
Name:Sherry L. Asher
Address:4447 Axel Rd.
Phone:515-288-3333

Location:Adel
Name:Mary B. Able
Address:555 West 1st
Phone:515-222-3333

There are, of course, other cities than Adel.
I have this routine to sort by the cities first:
@brokers = sort {

($a2=$a)=~s/.*Location:(.*?)\nName:(.*?)\n.*/sprintf("%-50s%s",$1,$2)/es
;


($b2=$b)=~s/.*Location:(.*?)\nName:(.*?)\n.*/sprintf("%-50s%s",$1,$2)/es
;

        $a2 cmp $b2;
                } @brokers;

Then I put in your sub ByLMF and here is the output:
Location:Adel
Name:Bill Guske
Address:100 North 8th
Phone:515-993-5555

Location:Adel
Name:Mary B. Able
Address:555 West 1st
Phone:515-222-3333

Location:Adel
Name:Mike Hammen
Address:100 North 8th
Phone:515-993-4551

Location:Adel
Name:Sherry L. Asher
Address:4447 Axel Rd.
Phone:515-288-3333

Thanks for any help at all.
I really appreciate it.
Terry Asher


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


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

Date: Wed, 24 May 2000 09:40:02 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Testing the getstore function in the LWP::Simple module
Message-Id: <Pine.GSO.4.10.10005240927340.23375-100000@user2.teleport.com>

On Wed, 24 May 2000, Sordid One wrote:

> I have tried to eval the code, but the program still dies.

Well, eval of a block will trap die(). Maybe the author of the code you're
using used exit()? If so, send a patch to the author. Subroutines in
general (and ones in modules in particular) shouldn't use exit() if
there's any chance the caller will want to trap the error.

> I've switched to the LWP::UserAgent module where there is a timeout
> feature and still the program dies. In fact, when fetching the "slow"
> URL, I've witnessed the timeout being ignored!!

If you're using it properly, that sounds like a bug. (Of course, that's
"if"! :-)  But have you filed a bug report?

> I've set the timeout to 0 seconds and it still gets stuck on this URL.

Could it be the DNS lookup, rather than the HTTP request, that's getting
stuck? Have you tried stepping through the code in the debugger to see
what's happening?

> I did try something that you made me think of...pinging the server to
> see if it's reachable...

Of course, a pingable host doesn't necessarily have a webserver, and
vice-versa. For example, you can't ping www.microsoft.com, but it's got a
webserver. You can ping b.root-servers.net, but it lacks a webserver.

> I've noticed, or rather stumbled upon some more info on this
> matter.....the URL's that cause the death of my program return a
> "There was no response" error in Netscape, but that doesn't help me
> out too much.

Maybe the remote site isn't following the protocol? Maybe it's not running
a webserver?

Good luck with it!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 24 May 2000 09:21:43 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: timeout a perl script?
Message-Id: <Pine.GSO.4.10.10005240921020.23375-100000@user2.teleport.com>

On Wed, 24 May 2000, Dave Brondsema wrote:

> That's all and good, but is there any way to do it automatically?  
> What I'd like to do is code a few lines at the top and not worry about
> it anywhere else.  This is mostly preventitive so any mistakes won't
> be troublesome.

Well, unless you've got alarm(), I don't think there's anything that's so
easy as you want. Oh, well!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 24 May 2000 15:43:17 GMT
From: baconrad@my-deja.com
Subject: Re: Trouble running perlcc
Message-Id: <8ggtag$fog$1@nnrp1.deja.com>

The manpage ony says I can't compile shared objects in Win32 (which I'm
not) and that I need at least perl 5.005 (I have build 613 for perl
v5.6.0 ). Is there something else I am missing?

Has anybody out there ever seen perlcc run on a Windows 9x platform?
From other postings, it appears that others have gotten farther than me.

I would really like to use this as an alternative to installing perl on
many client machines. I tried running from one network shared perl
directory, and in some cases this was too slow over a network (my
clients are in schools with slow networks).

Thanks again for any information.


In article<Pine.GSO.4.10.10005230939580.23375-
100000@user2.teleport.com>,
  Tom Phoenix <rootbeer@redcat.com> wrote:
> On Tue, 23 May 2000 baconrad@my-deja.com wrote:
>
> > I am having a hell of a time getting perlcc to work at all.
>
> Have you seen the BUGS section of the manpage? Cheers!
>
> --
> Tom Phoenix       Perl Training and Hacking       Esperanto
> Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/
>
>


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


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

Date: Wed, 24 May 2000 10:45:12 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Trouble running perlcc
Message-Id: <Pine.GSO.4.10.10005241043130.14618-100000@user2.teleport.com>

On Wed, 24 May 2000 baconrad@my-deja.com wrote:

> The manpage ony says I can't compile shared objects in Win32 (which I'm
> not) and that I need at least perl 5.005 (I have build 613 for perl
> v5.6.0 ). Is there something else I am missing?

It should include these paragraphs as well:

    The whole compiler suite (C<perlcc> included) should be considered
    very experimental.  Use for production purposes is strongly
    discouraged.

    Bugs in the various compiler backends still exist, and are perhaps too
    numerous to list here.

> I would really like to use this as an alternative to installing perl
> on many client machines.

That is strongly discouraged. :-)

It's still easier in general to install perl on each client machine, then
to install all the scripts you'd like.

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 24 May 2000 11:55:51 -0400
From: Brad Baxter <bmb@dataserv.libs.uga.edu>
Subject: Re: use english
Message-Id: <Pine.GSO.4.21.0005241153220.15216-100000@dataserv.libs.uga.edu>

On Tue, 23 May 2000, Steven Smolinski wrote:

> On Tue, 23 May 2000, Brad Baxter <bmb@dataserv.libs.uga.edu> wrote:
> >On Tue, 23 May 2000, Michael Carman wrote:
> >...
> >> For one, the long names are there for a reason -- they're descriptive
> >> and easier to remember than secret code of $!^*& stuff. What you use in
> >...
> >
> >     1  #!/usr/local/bin/perl -w
> >     2  use strict;
> >     3
> >     4  print $!^*&;
> >     5
> >     6  __END__
> >     7  Output:
> >     8
> >     9  *main::&
> 
> Brad, that's just fscked up.  Can anyone give me a short tutorial
> on this?

(Tutorial left to Uri and Larry.)

The moral: be careful what you do with line noise.  Perl (perl) just might
do something useful like optimize your OS.

-- 
Brad




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

Date: 24 May 2000 12:06:08 -0400
From: Vivek Khera <khera@kciLink.com>
Subject: Re: valid email address
Message-Id: <x7hfboj5lb.fsf@onceler.kcilink.com>

>>>>> "UG" == Uri Guttman <uri@sysarch.com> writes:

>>>>> "TEB" == The Evil Beaver <evilbeaver.picksoft@NOSPAMzext.net> writes:
TEB> /(\w+)\@(\w)(\w+).(\w)(\w+)/
TEB> or something similar.

UG> or something wrong. that fails in so many ways such as 3 level
UG> domain names.

UG> read the faq on this. email addresses cannot be fully verified. even
UG> partially verified is difficult.

In theory yes, but in practicality, this set of matches catches a lot,
and has had exactly one false-positive match in the 4 years of using
it (compared against several hundred thousand email addresses people
really use).

=pod

=head2 check_address($addr)

Check the syntactical format of an email address to reduce risk of
bogus addresses.  Return empty string if OK, otherwise return the error
message we should display.

Ensures that the address is in somewhat reasonable domain style, does
not contain blanks, commas, brackets, colons, semicolons, or end in a
period.

=cut

sub check_address {
  my ($addr) = @_;

  # make sure email address is somewhat reasonable (domain style address)
  return q{You specified an improper Internet email address format.  Please
           use an address like <KBD>yourname@domain.com</KBD>. If you do not
           know what your address is, please do not guess or make one up --
           ask your system administrator what it is.}
  unless ($addr =~ m/\S+@[\-\w]+\.[\-\w]+/);

  return q{Email addresses may not have blanks, commas,
           brackets, colons, or semicolons.  Please go back and correct your
           address. If you believe your address contains these characters, you
           are probably mistaken about what your address is.  Please check
           with your system administrator to find out your proper address.}
  if ($addr =~ m/[;:,\s\<\>]/);

  return q{Internet email addresses do not end in a period &quot;.&quot; 
           character.}
  if ($addr =~ m/\.$/);

  return '';                    # return empty string if ok!
}



-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D.                Khera Communications, Inc.
Internet: khera@kciLink.com       Rockville, MD       +1-301-545-6996
GPG & MIME spoken here            http://www.khera.org/~vivek/


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

Date: Wed, 24 May 2000 23:55:51 +0800
From: "Swee Heng" <sweeheng@usa.net>
Subject: Re: Writing a concurrent server in perl
Message-Id: <8ggvkg$2l7$1@violet.singnet.com.sg>

<hritzman@my-deja.com> wrote in message news:8ggmp8$aju$1@nnrp1.deja.com...
> I am trying to write a concurrent server in perl, i.e. work for the
> daemon comes in faster than it can be serviced so I want to fork a
> child to handle each request.  The problem I'm having is that if I use a
> signal handler to reap the children, the daemon itself is also killed.
> Without the signal handler I create a bunch of defunct processes that
> have the potential of filling up the process table.  The code below is a
> trimmed down version of the problem.  The child dies at 15 seconds
> taking the parent with it.  Any suggestions would be greatly
> appreciated.

Maybe this is of use:
http://www.webreference.com/perl/tutorial/9/





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

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


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