[16877] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4289 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 11 18:10:52 2000

Date: Mon, 11 Sep 2000 15:10:27 -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: <968710227-v9-i4289@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 11 Sep 2000     Volume: 9 Number: 4289

Today's topics:
    Re: how to extract data from html table document ? <jbowker@ozemail.com.au>
    Re: how to include a script in another script <bkennedy@hmsonline.com>
    Re: how to match the hole string by first word? (need h <lr@hpl.hp.com>
    Re: how to restart apache (The Drag)
    Re: How to use a date (i.e. "Aug 1 2000") in utime? (Otto Wyss)
    Re: How to use a date (i.e. "Aug 1 2000") in utime? <lr@hpl.hp.com>
    Re: HTML::Template <lr@hpl.hp.com>
    Re: HTML::Template (brian d foy)
    Re: Including Files nobull@mail.com
    Re: Including Files <claytons@nortelnetworks.com>
        Incremental HTML output as script is running <news@flish.co.uk>
    Re: LittleProblem <tim@ipac.caltech.edu>
    Re: LittleProblem <ren.maddox@tivoli.com>
    Re: LittleProblem <lr@hpl.hp.com>
    Re: LittleProblem <lr@hpl.hp.com>
        memory deallocation <sherlock@genome.stanford.edu>
    Re: Need Help! OK Who wants to laugh at my first perl a <lr@hpl.hp.com>
        Orphaning processes <cplager@uiuc.edu>
    Re: Orphaning processes <srevilak@cs.umb.edu>
        Perl 5.6.0 bug ? GEN33 opened only for output <joepepin@att.com>
        Perl and System Environment Variables lim_k@my-deja.com
    Re: Perl hases and memory <tim@ipac.caltech.edu>
    Re: Perl substraction weird result <tzz@iglou.com>
    Re: perl:sort & store hash <randy_734@my-deja.com>
    Re: perl:sort & store hash <uri@sysarch.com>
    Re: perl:sort & store hash <ren.maddox@tivoli.com>
    Re: perl:sort & store hash <randy_734@my-deja.com>
    Re: Qualifications for new Perl programmer????? <lr@hpl.hp.com>
    Re: Qualifications for new Perl programmer????? <smerr612@mailandnews.com>
    Re: Qualifications for new Perl programmer????? <smerr612@mailandnews.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 12 Sep 2000 06:42:50 +1000
From: John <jbowker@ozemail.com.au>
Subject: Re: how to extract data from html table document ?
Message-Id: <efgqrs8pubrl2gkl67lfs91ee190o4m0g7@4ax.com>

On Mon, 11 Sep 2000 14:15:34 +1100, jason <elephant@squirrelgroup.com>
wrote:

>Tom <tk28@gmx.net> wrote ..
>>is there an facility to extract data from an html ( table ) document
>>using perl on win32 ? 
>
>I don't know what "an html ( table ) document" is .. but on the off 
>chance that you mean - "a table within an HTML document" then have a 
>look at one of the many standard HTML parsing and tokenising modules 
>included with Perl
>
>if you're on Win32 and using the ActiveState port of Perl then you will 
>find them referenced in the HTML documentation that was installed when 
>you installed Perl .. it's in your Start menu

I've written an application to extract table data from HTML pages
using HTML::Tokeparser.

I must say, though, that tables are irritating things to parse by
brute force, firstly because tables may have other tables embedded in
them, and secondly because folks may or may not use </td> and </tr>. I
seem to spend a lot of time ungetting tokens...

I've sometimes wondered whether there's a BNF-like definition that
could be pushed through a parser module (is it RecDescent?)...

John


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

Date: Mon, 11 Sep 2000 20:12:31 GMT
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: how to include a script in another script
Message-Id: <P0bv5.21071$AW2.261287@news1.rdc2.pa.home.com>


"jos" <jos@feka.nl> wrote in message news:8phbrn$2rrp$1@buty.wanadoo.nl...
> is there anyway i can easily include a file with standard subs in a perl
> script?
> #include filename.pl

In a nutshell, you want the 'require' or 'use' functions.  For the whole
story, you should see 'perldoc perlmod' and 'perldoc -f use' to get you
started with creating perl modules

--Ben Kennedy





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

Date: Mon, 11 Sep 2000 13:59:15 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: how to match the hole string by first word? (need help)
Message-Id: <MPG.1426e77b1e9c55498ad54@nntp.hpl.hp.com>

In article <39BCFF74.9762CE52@nwu.edu> on Mon, 11 Sep 2000 10:51:16 -
0500, Alexandr Kogan <a-kogan@nwu.edu> says...

 ...

> I need to go through a huge text file find strings that start with
> the same word and convert the whole line to lowercase. I'm having 
> problems getiing a hold of a whole string, that's what I'm doing:
> 
> while (<INPUT>) {
>         if ($s =~ /^objectclass: /i) {
>         chop $_;
>         $_ = lc($_);
>         print OUTPUT $_;}
>         else {print OUTPUT $_;}	
>     }
> 
> Could someone tell me what is wrong and how to do it right? 

Good answers are already posted.  This is for the folks who object to 
compact syntax, including the ternary conditional operator:

  print OUTPUT /^objectclass: /i ? lc : $_ while <INPUT>;

This is 'clean' Golf -- clear, expressive, no superfluities.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 11 Sep 2000 18:13:02 GMT
From: thedrag@--X--houston.rr.com (The Drag)
Subject: Re: how to restart apache
Message-Id: <39bd20a4.13296797@news-server.houston.rr.com>

When all else fails, try the source. :-)
http://www.apache.org
I didn't even bother with the apache rpm distributed with RH.  I
needed to compile with php4 support and a few additional perl modules.

On Sun, 10 Sep 2000 02:48:04 -0600, "Jerri Blavitt³" <no@never.no>
wrote:

>
>
>
><thedrag@--X--houston.rr.com> wrote in message
>news:39b82648.4642137@news-server.houston.rr.com...
>> Just make a small script named
>> # !/bin/sh
>> #restart-apache.sh
>> /etc/rc.d/init.d/httpd restart
>> # end restart-apache.sh
>>
>> ICK, I hope you aren't going to seriously use the apache rpm from the
>> RH distro.
>> PLEASE DO NOT USE LINUXCONF to edit the apache config.
>> 1) The RH distro has an incomplete httpd.conf. some moron deleted the
>> majority of the documented config entries.
>
>I noticed that too. But where to find simply a complete httpd.conf template ...?
>
>
>
>



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

Date: Mon, 11 Sep 2000 22:59:28 +0200
From: otto.wyss@bluewin.ch (Otto Wyss)
Subject: Re: How to use a date (i.e. "Aug 1 2000") in utime?
Message-Id: <1egtbxd.1cnp7if3luiq6N%otto.wyss@bluewin.ch>

> > In a more generalized form: How do I convert a date in string form to a
> > numeric date, possibly written in a localized manner (i.e. "1. Aug.
> > 2000").
> >
> utime() does only accepts time in perl's time() format.
> You can convert from localtime() format, which is more human, to time()
> by using POSIX's mktime(), for example:
> 
> use POSIX;
> print "it works\n" if mktime(localtime) == time;
> 
I don't want to convert from perl's time, I want to convert from a date
in string form (i.e. "Aug 1 2000"). Do I really have to convert from the
string to the perl's time manually and afterwards apply the mktime?
There must be a function which does this job.

O. Wyss


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

Date: Mon, 11 Sep 2000 14:18:36 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How to use a date (i.e. "Aug 1 2000") in utime?
Message-Id: <MPG.1426ec073bda78bd98ad55@nntp.hpl.hp.com>

In article <1egtbxd.1cnp7if3luiq6N%otto.wyss@bluewin.ch> on Mon, 11 Sep 
2000 22:59:28 +0200, Otto Wyss <otto.wyss@bluewin.ch> says...
> > > In a more generalized form: How do I convert a date in string form to a
> > > numeric date, possibly written in a localized manner (i.e. "1. Aug.
> > > 2000").
> > >
> > utime() does only accepts time in perl's time() format.
> > You can convert from localtime() format, which is more human, to time()
> > by using POSIX's mktime(), for example:
> > 
> > use POSIX;
> > print "it works\n" if mktime(localtime) == time;
> > 
> I don't want to convert from perl's time, I want to convert from a date
> in string form (i.e. "Aug 1 2000"). Do I really have to convert from the
> string to the perl's time manually and afterwards apply the mktime?
> There must be a function which does this job.

perlfaq4: "How can I take a string and turn it into epoch seconds?"

I don't know what the mktime() in the above submission is intended to 
do.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 11 Sep 2000 10:55:02 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: HTML::Template
Message-Id: <MPG.1426bc5217ca7adc98ad4f@nntp.hpl.hp.com>

In article <brian-ya02408000R1009001223220001@news.panix.com> on Sun, 10 
Sep 2000 12:23:22 -0400, brian d foy <brian@smithrenaud.com> says...
> In article <39BBA30E.6E3E004E@peacecomputers.com>, fliptop@peacecomputers.com posted:

 ...

> >   @numbers = qw{01 02 03 04 05 06 07 08 09 10
> >                 11 12 13 14 15 16 17 18 19 20
> >                 21 22 23 24 25 26 27 28 29 30 31};
> 
> the range operater can save typing.
> 
>    @days = map sprintf("%02d", $_), 0 .. 31;

  The range operator can save typing.

     @days = '01' .. '31';

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 11 Sep 2000 15:43:30 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: HTML::Template
Message-Id: <brian-ya02408000R1109001543300001@news.panix.com>

In article <MPG.1426bc5217ca7adc98ad4f@nntp.hpl.hp.com>, Larry Rosler <lr@hpl.hp.com> posted:

> In article <brian-ya02408000R1009001223220001@news.panix.com> on Sun, 10 
> Sep 2000 12:23:22 -0400, brian d foy <brian@smithrenaud.com> says...

> > the range operater can save typing.
> > 
> >    @days = map sprintf("%02d", $_), 0 .. 31;

>   The range operator can save typing.
> 
>      @days = '01' .. '31';

gees.  i was just typing way too much in that post. ;)

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>


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

Date: 11 Sep 2000 19:03:08 +0100
From: nobull@mail.com
Subject: Re: Including Files
Message-Id: <u9aedebycj.fsf@wcl-l.bham.ac.uk>

rathmore@tierceron.com writes:


> How do I include the file Order_Methods.pm within OrderMan.pl when I
> compile?

use() or require() it.

> I've reviewed and tried both the require and use commands but get the
> following error when I do:
> 
> C:\Projects\Web_Order_Automation>perl OrderMan.pl
> Can't locate Projects/Web_Order_Automation/NNIorder_methods.pm in @INC
> (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at OrderMan.pl line 8.

You said your module was called Order_Methods but you appear to be
attempting to use a module called
Projects::Web_Order_Automation::NNIorder_methods

Make sure the filename of the module, the package name of the module
and the name used in the use() statement are consistant.

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


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

Date: Mon, 11 Sep 2000 14:57:24 -0400
From: Clayton Scott <claytons@nortelnetworks.com>
Subject: Re: Including Files
Message-Id: <39BD2B14.1155F409@nortelnetworks.com>

rathmore@tierceron.com wrote:

> I've reviewed and tried both the require and use commands but get the
> following error when I do:
> 
> C:\Projects\Web_Order_Automation>perl OrderMan.pl
> Can't locate Projects/Web_Order_Automation/NNIorder_methods.pm in @INC
> (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at OrderMan.pl line 8.

	You need to modify @INC so that the
 "Projects/Web_Order_Automation/" directory is in the search path.

 Look up @INC in the index of Programming Perl (under "I", not "@"). 
 More details are there.


Clayton


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

Date: Mon, 11 Sep 2000 20:08:59 +0100
From: Andy Flisher <news@flish.co.uk>
Subject: Incremental HTML output as script is running
Message-Id: <MPG.14273d6e81611d2d989689@alt-news.gradwell.net>

Hi,

Hopefully you can help here, I am at the end of a script that reads a 
number of text files in one by one and after some reformatting puts the 
data into MySQL.  The purpose is as part of an admin tool for a customer.

The script itself can take around two minutes to complete, and is 
initiated by the customer clicking a link from an HTML form.

Because of the length of time the script takes I would like to output 
various status lines as HTML to keep the customer informed as to what 
stage the script is at.

This all works a treat at command line, but when initiated as a CGI I 
simply get the hourglass until the script has finished, at which point it 
nicely outputs all the status lines at once :-(

My, albeit brief, understanding is that there are limits to this sort of 
output, and it has been recommended I look at flushing the cache?  Any 
pointers anyone, or a good source of reference as nothing has jumped up 
to help as of yet.
 TIA 
-- 
Andy Flisher

'All postings are a reflection of my state of mind,
and not necessarily of any worthwhile opinion'

news@flish.co.uk    http://www.flish.co.uk


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

Date: Mon, 11 Sep 2000 12:52:42 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: LittleProblem
Message-Id: <39BD380A.D197F10D@ipac.caltech.edu>

nezarite wrote:
> I'm trying to do an algorithm to cycle through all possible combinations 
> of a number of letters in a string. 
> I want to print the following:
> 
> aaaa
> aaab
> aaac
> ...
> ...
> zzzz

Here's another way:

$_="aaaa"; 
print while ++$_ ne "aaaaa";

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: 11 Sep 2000 15:09:12 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: LittleProblem
Message-Id: <m3snr61yjb.fsf@dhcp11-177.support.tivoli.com>

Tim Conrow <tim@ipac.caltech.edu> writes:

> $_="aaaa"; 
> print while ++$_ ne "aaaaa";

OK, I probably shouldn't bother, but I couldn't resist a little Golf:

$_="a"x4;print while$_++ne"z"x4

(Note that both of this need either a "-l" option or a "$\=$/;" or
similar, unless you just want all of the strings run together -- and
perhaps you do....)

Of course, that reminds me to make that change for my original answer:

print for"a"x4.."z"x4

(21 characters)

and if "-l" isn't allowed:

$\=$/;print for"a"x4.."z"x4

(27 characters)

So, 21 with "-l" or 27 without.  Anyone beat that?

-- 
Ren Maddox
ren@tivoli.com


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

Date: Mon, 11 Sep 2000 14:25:06 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: LittleProblem
Message-Id: <MPG.1426ed8946d0a14898ad56@nntp.hpl.hp.com>

In article <m3snr61yjb.fsf@dhcp11-177.support.tivoli.com> on 11 Sep 2000 
15:09:12 -0500, Ren Maddox <ren.maddox@tivoli.com> says...
> Tim Conrow <tim@ipac.caltech.edu> writes:
> 
> > $_="aaaa"; 
> > print while ++$_ ne "aaaaa";
> 
> OK, I probably shouldn't bother, but I couldn't resist a little Golf:
> 
> $_="a"x4;print while$_++ne"z"x4
> 
> (Note that both of this need either a "-l" option or a "$\=$/;" or
> similar, unless you just want all of the strings run together -- and
> perhaps you do....)
> 
> Of course, that reminds me to make that change for my original answer:
> 
> print for"a"x4.."z"x4
> 
> (21 characters)
> 
> and if "-l" isn't allowed:
> 
> $\=$/;print for"a"x4.."z"x4
> 
> (27 characters)
> 
> So, 21 with "-l" or 27 without.  Anyone beat that?

Easily.

  $,=$\;print aaaa..zzzz

16 or22.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 11 Sep 2000 14:45:29 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: LittleProblem
Message-Id: <MPG.1426f25388eab48698ad57@nntp.hpl.hp.com>

In article <MPG.1426ed8946d0a14898ad56@nntp.hpl.hp.com> on Mon, 11 Sep 
2000 14:25:06 -0700, Larry Rosler <lr@hpl.hp.com> says...
> In article <m3snr61yjb.fsf@dhcp11-177.support.tivoli.com> on 11 Sep 2000 
> 15:09:12 -0500, Ren Maddox <ren.maddox@tivoli.com> says...

 ...

> > $\=$/;print for"a"x4.."z"x4
> > 
> > (27 characters)
> > 
> > So, 21 with "-l" or 27 without.  Anyone beat that?
> 
> Easily.
> 
>   $,=$\;print aaaa..zzzz

Oops.  That requires '-l'.  The "$\" should be "$/" obviously.  But that 
doesn't put a newline after the last element, which costs another three 
characters.

    $,=$\=$/;print aaaa..zzzz

25 characters without '-l' (but 22 with '-l'; alas).

Another way to get 25:

    $,=$/;print aaaa..zzzz,""

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 11 Sep 2000 11:39:21 -0700
From: Gavin Sherlock <sherlock@genome.stanford.edu>
Subject: memory deallocation
Message-Id: <110920001139211510%sherlock@genome.stanford.edu>

Hi,
   I have a program (under perl 5.004, running on Solaris 2.6), that
uses large amounts of memory reading stuff from a database.  It does
some subsequent filtering of that data, which is in a nested hash, and
often filters out over half the data (the filtering can't be done on
the database side).  For that data that I don't need, I delete the
appropriate keys in the hash.  Memory usage never decreases (at least
when monitored via top), and so when I subsequently retrieve other
information from the database, the process goes over the 200Mb system
imposed limit, and gets killed.  Is there any way I can get that memory
freed up, or am I going to have to change my implementation?  If I move
to a two-dimensional array implementation, or even a hash of arrays,
will it be likely to save memory?  I have 300 users who need large
datasets :-(
Cheers,
Gavin Sherlock


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

Date: Mon, 11 Sep 2000 11:48:34 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Need Help! OK Who wants to laugh at my first perl attempt?
Message-Id: <MPG.1426c8e25858580198ad52@nntp.hpl.hp.com>

In article <8pivp0$k8o$1@nnrp1.deja.com> on Mon, 11 Sep 2000 16:04:00 
GMT, Greg Donovan <sysnovice@my-deja.com> says...
> In this line next if $letters =~ /^\.\.?$/;
>              next if $letters =~ /[__]/;    # This is a bug
> I was trying to ignore lines like
> __GENNAME__
> __VALIDITY__
> __deliver__
> __lock__
> 
> Can you please explain why the second line is a bug?

It matches a character class that contains either a '_' or a '_', i.e. 
the single character '_'.  Leave out the square brackets.  
Alternatively, use the index() function to look for the string '__'.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sun, 10 Sep 2000 10:58:51 -0400
From: Charles Plager <cplager@uiuc.edu>
Subject: Orphaning processes
Message-Id: <39BBA1AB.6017BBAB@uiuc.edu>

Hi,
	I'm trying to get a parent script to start a child script and then
completely ignore it (if the child script dies, faulters, seg faults I
don't care) on unix.  I started off with a simple forking script:
 #!/usr/local/bin/perl -w

$command = join (" ", @ARGV);
if ($pid = fork) {
    #parent process
} elsif (defined $pid) {
    #child process
        open(STDOUT,">/dev/null");
        open(STDERR,">&STDOUT");
        exec $command;
} elsif ($! =~ /No more process/) {
        die ("Too many processes\n");
} else {
        die ("Weird fork error\n");
}

and even went to a double fork (basically I used this script twice,
version 1 calling version 2 calling the command), but still my parent
script gets hung up when something bad happens to it child.  Does
anybody have any suggestions?
	Thanks,
	  Charles Plager

p.s. Please respond by email (as well as posting). 
-- 
------------------------------------------------------------------
Charles Plager                                    cplager@uiuc.edu
Dept of Physics, UIUC                 http://www.uiuc.edu/~cplager
office: (1) 607-255-7505                     fax: (1) 607-255-8062
------------------------------------------------------------------


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

Date: Mon, 11 Sep 2000 16:41:55 -0400
From: Steve Revilak <srevilak@cs.umb.edu>
To: Charles Plager <cplager@uiuc.edu>
Subject: Re: Orphaning processes
Message-Id: <Pine.GSO.4.05.10009111640470.5179-100000@eris.cs.umb.edu>

On Sun, 10 Sep 2000, Charles Plager wrote:

> 	I'm trying to get a parent script to start a child script and then
> completely ignore it (if the child script dies, faulters, seg faults I
> don't care) on unix.  I started off with a simple forking script:

> } elsif (defined $pid) {
>     #child process
>         open(STDOUT,">/dev/null");
>         open(STDERR,">&STDOUT");
>         exec $command;
> } elsif ($! =~ /No more process/) {


Maybe close STDERR & STDOUT in the child before re-opening them ?

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Steve Revilak
srevilak@cs.umb.edu



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

Date: Mon, 11 Sep 2000 16:10:57 -0400
From: "Joe Pepin" <joepepin@att.com>
Subject: Perl 5.6.0 bug ? GEN33 opened only for output
Message-Id: <8pjdth$jaq4@kcweb01.netnews.att.com>

I have a Perl 5.6.0 script that runs as a daemon on a machine that has few
available file descriptors.  To gain a few descriptors, I close STDIN and
STDOUT (I don't need them).  However, when I open a new FileHandle as in:

my $fh = new FileHandle("file.txt", "r") or die "can't open file.txt: $!";

and it happens that fileno($fh) == 1, I get the following on every
$fh->getline:

Filehandle Symbol::GEN33 opened only for output at
/usr/local/lib/perl5/5.6.0/sun4-solaris/IO/Handle.pm line 391.
Filehandle Symbol::GEN33 opened only for output at
/usr/local/lib/perl5/5.6.0/sun4-solaris/IO/Handle.pm line 391, <GEN33> line
1.

and so forth. The getline's read as they should. It looks like IO::Handle
still thinks that file descriptor 1 is STDOUT and is only open for output.




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

Date: Mon, 11 Sep 2000 19:11:21 GMT
From: lim_k@my-deja.com
Subject: Perl and System Environment Variables
Message-Id: <8pjao7$2bg$1@nnrp1.deja.com>

I know this question has been asked before, but I must have missed the
posting.  How would you pass system environment variables in a PERL
script for a cron'ed process?

I have tried:

$ENV{PATH} = "/yadda/yadda/yadda:/blah/blah/blah:";

print "PATH=$ENV{PATH};

TIA,
Ken


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


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

Date: Mon, 11 Sep 2000 12:09:24 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Perl hases and memory
Message-Id: <39BD2DE4.5F4E2916@ipac.caltech.edu>

Martin Djernæs wrote:
> I have created a script which read a file (about 512K) into an array,
> for accessing the data a bit later...

Martin,

Throw us a bone: Can you pare down your script to a very small sample program
that shows your data structures and your use of recursion? Can you specify what
you mean by "won't run"? Can you tell us what you've done to try and solve the
problem?

Without that concreteness it's going to be hard for us to give you suggestions.

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: 11 Sep 2000 14:51:26 -0500
From: Ted Zlatanov <tzz@iglou.com>
Subject: Re: Perl substraction weird result
Message-Id: <968697499.8193@iglou.com>

In article <8pj3k0$p4s$1@nnrp1.deja.com>, karabot@canada.com wrote:
>% perl -e 'print(30.4 - 30 . "\n")'
>0.399999999999999
>
>Does anybody know why the result is NOT 0.4 ?

Look in perlfaq4 (perldoc perlfaq4)

Does Perl have a round() function?  What about ceil() and floor()?  Trig
functions?

But that's just a start.  You should know what you are trying to achieve
with your code so you can choose the right printout for it.

perl -e 'printf("%f\n", 30.4 - 30.0)'
0.400000

perl -e 'printf("%.50f\n", 30.4 - 30.0)'
0.39999999999999857891452847979962825775146484375000

(your mileage may vary, this is on a Pentium-III)

>Sent via Deja.com http://www.deja.com/

You should use Deja to *search* for past discussions on this topic
(rounding, floating point calculations in Perl, IEEE floating point
formats).  There have been many, and the topic has been rehashed many times.

e.g. search for "IEEE Perl floating round" in all messages
http://www.deja.com/dnquery.xp?QRY=IEEE+perl+floating+round&svcclass=dnserver

and an article that mentions IEEE floating point inaccuracies
http://x55.deja.com/getdoc.xp?AN=544774453&CONTEXT=968698142.799539226

-- 
Teodor Zlatanov <tzz@iglou.com>
"Brevis oratio penetrat colos, longa potatio evacuat ciphos." -Rabelais


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

Date: Mon, 11 Sep 2000 19:19:59 GMT
From: Randy <randy_734@my-deja.com>
Subject: Re: perl:sort & store hash
Message-Id: <39bd2f1b.20581609@207.126.101.100>

One way to do it:

foreach (sort { $Hash{$a} cmp $Hash{$b} } keys %Hash) {
	$NewHash{$_}=$Hash{$_};
}

subbudeja@my-deja.com wrote:

>Plese help me out:
>I have to sort a hash by value in perl and store the sorted in another
>hash. Can somebody send me a code how to do this?
>I appreciate ur help
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.



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

Date: Mon, 11 Sep 2000 19:33:06 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: perl:sort & store hash
Message-Id: <x71yyqiv0t.fsf@home.sysarch.com>

>>>>> "R" == Randy  <randy_734@my-deja.com> writes:

  R> One way to do it:
  R> foreach (sort { $Hash{$a} cmp $Hash{$b} } keys %Hash) {
  R> 	$NewHash{$_}=$Hash{$_};
  R> }

huh??????

what does that do other than:

	@NewHash{ keys %Hash } = values %Hash ;

and if %Newhash is really now, then a plain assignment will do.

the sort is meaningless there as all you do is assign the elements to
another hash and lose all ordering.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 11 Sep 2000 14:51:44 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: perl:sort & store hash
Message-Id: <m3vgw21zcf.fsf@dhcp11-177.support.tivoli.com>

Uri Guttman <uri@sysarch.com> writes:

> >>>>> "R" == Randy  <randy_734@my-deja.com> writes:
> 
>   R> One way to do it:
>   R> foreach (sort { $Hash{$a} cmp $Hash{$b} } keys %Hash) {
>   R> 	$NewHash{$_}=$Hash{$_};
>   R> }
> 
> huh??????
> 
> what does that do other than:
> 
> 	@NewHash{ keys %Hash } = values %Hash ;

Well, it does exactly what the OP asked for... of course, what the OP
asked for is not really what the OP wanted -- or, it may be what the
OP wanted, but is not compatible with the fact that Perl's hashes are
not ordered.  The OP seemed to think that they could be.

> and if %Newhash is really now, then a plain assignment will do.
> 
> the sort is meaningless there as all you do is assign the elements to
> another hash and lose all ordering.

Perhaps something like this will meet the OPs needs:

my @sorted;
push @sorted, [$_, $Hash{$_}]
  for sort { $Hash{$a} cmp $Hash{$b} } keys %Hash;

or, as I found I preferred in my test code:

my @sorted = map [$_, $Hash{$_}],
      sort { $Hash{$a} cmp $Hash{$b} } keys %Hash;

In either case, get at the data with something like:

print "@$_\n" for @sorted;

-- 
Ren Maddox
ren@tivoli.com


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

Date: Mon, 11 Sep 2000 21:22:57 GMT
From: Randy <randy_734@my-deja.com>
Subject: Re: perl:sort & store hash
Message-Id: <39bd4c53.28061125@207.126.101.100>

You're correct.  If the sort results need to be saved, the obvious
solution is to put the them into an ordered array as suggested by
another response to the post.

Uri Guttman <uri@sysarch.com> wrote:

>>>>>> "R" == Randy  <randy_734@my-deja.com> writes:
>
>  R> One way to do it:
>  R> foreach (sort { $Hash{$a} cmp $Hash{$b} } keys %Hash) {
>  R> 	$NewHash{$_}=$Hash{$_};
>  R> }
>
>huh??????
>
>what does that do other than:
>
>	@NewHash{ keys %Hash } = values %Hash ;
>
>and if %Newhash is really now, then a plain assignment will do.
>
>the sort is meaningless there as all you do is assign the elements to
>another hash and lose all ordering.
>
>uri
>
>-- 
>Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
>SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
>The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
>The Best Search Engine on the Net  ----------  http://www.northernlight.com



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

Date: Mon, 11 Sep 2000 11:40:14 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Qualifications for new Perl programmer?????
Message-Id: <MPG.1426c6ea8992768998ad51@nntp.hpl.hp.com>

In article <slrn8rotnf.1bt.tjla@thislove.dyndns.org> on Mon, 11 Sep 2000 
06:05:10 GMT, Gwyn Judd <tjla@guvfybir.qlaqaf.bet> says...
> I was shocked! How could jason <elephant@squirrelgroup.com>
> say such a terrible thing:

 ...

> >2. Explain the bearing that the builtin input record separator
> >   variable $/ has on the diamond operator <>.
> 
> This is the character (or group of characters that the input operator
> '<>' seperates records on).

In the interests of a different form of Perl Golf:

     s/character \(or group of characters/string/;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 11 Sep 2000 20:45:14 GMT
From: Steven Merritt <smerr612@mailandnews.com>
Subject: Re: Qualifications for new Perl programmer?????
Message-Id: <8pjg8j$9ma$1@nnrp1.deja.com>

In article <39BC8699.BDEE5C92@stomp.stomp.tokyo>,
  "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:

> Employment Qualifications -
>
> Write an imaginative and creative Perl script with a minimum
> of five-hundred lines which produces results which will give
> me a smile, make me laugh or simply amaze me. This script
> must bend, break, twist, mutilate and violate every Perl
> rule possible, yet run with lightning fast perfection. It
> must be written Perl 4 style and not use pragma hints nor
> any modules. Scoring will be by how surprised I am.
>

an imaginative and creative Perl script with a minimum
of five-hundred lines which produces results which will give
me a smile, make me laugh or simply amaze me. This script
must bend, break, twist, mutilate and violate every Perl
rule possible, yet run with lightning fast perfection. It
must be written Perl 4 style and not use pragma hints nor
any modules. Scoring will be by how surprised I am.


There, I wrote exactly what you said to write.  Now let's talk
compensation. Oh, and I want a desk made out of Lego bricks.

Steven
--
King of Casual Play
The One and Only Defender of Cards That Blow


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


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

Date: Mon, 11 Sep 2000 20:58:50 GMT
From: Steven Merritt <smerr612@mailandnews.com>
Subject: Re: Qualifications for new Perl programmer?????
Message-Id: <8pjh1t$agh$1@nnrp1.deja.com>

In article <MPG.1426c6ea8992768998ad51@nntp.hpl.hp.com>,
  Larry Rosler <lr@hpl.hp.com> wrote:
> In article <slrn8rotnf.1bt.tjla@thislove.dyndns.org> on Mon, 11 Sep
2000
> 06:05:10 GMT, Gwyn Judd <tjla@guvfybir.qlaqaf.bet> says...

<Snip question about $\>

> > This is the character (or group of characters that the input
operator
> > '<>' seperates records on).
>
> In the interests of a different form of Perl Golf:
>
>      s/character \(or group of characters/string/;

s/character \(or group of characters/\(string/;

Slightly higher score in golf than yours, but mine won't have mismatched
parens.

Still better would be
s/character \(or group of characters/string/;
s/\)//;

Because the parens don't make any sense after the changes.

Steven
--
King of Casual Play
The One and Only Defender of Cards That Blow

My newsreader limits sigs to four lines, but I cleverly bypassed this by


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


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

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


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