[17176] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4588 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 11 18:15:48 2000

Date: Wed, 11 Oct 2000 15:15:28 -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: <971302528-v9-i4588@ruby.oce.orst.edu>
Content-Type: text

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

Today's topics:
        Perl script question thundaar54@my-deja.com
    Re: Perl script question <tim@ipac.caltech.edu>
    Re: Perl script question <newsposter@cthulhu.demon.nl>
        Perl under win2000 <squeek@club.brunssum.net.remove>
    Re: Perl under win2000 (Brett W. McCoy)
    Re: Reading a whole file into a string mexicanmeatballs@my-deja.com
    Re: Reading a whole file into a string <godzilla@stomp.stomp.tokyo>
    Re: reading/writing binary data (Mark-Jason Dominus)
    Re: reading/writing binary data <sariq@texas.net>
    Re: reading/writing binary data (Randal L. Schwartz)
    Re: reading/writing binary data <uri@sysarch.com>
    Re: Reg exp help <lr@hpl.hp.com>
    Re: regex challenge (Craig Berry)
    Re: regex challenge <james@NOSPAM.demon.co.uk>
        Return Value from DBI Execute? <jwade1@iupui.edu>
        running a program in the background rbeau@my-deja.com
    Re: running a program in the background (Brett W. McCoy)
    Re: running a program in the background <anmcguire@ce.mediaone.net>
    Re: running a program in the background <mtaylorlrim@my-deja.com>
    Re: save blob from database <christopher_j@uswest.net>
    Re: save blob from database <pilsl@goldfisch.atat.at>
    Re: sendmal doesn't return emails to unknown email-addr (Alan Curry)
    Re: sendmal doesn't return emails to unknown email-addr <haertig@avaya.com>
    Re: splitting an array into a hash of sub-arrays stdenton@my-deja.com
    Re: substring search (Mark-Jason Dominus)
    Re: Trying to add a service in win32 env. eedlin@my-deja.com
    Re: Using each() on hash of hashes = Thanks dustintodd@my-deja.com
    Re: Using each() on hash of hashes <tim@ipac.caltech.edu>
    Re: Using each() on hash of hashes dustintodd@my-deja.com
    Re: will perl 5 work w/o server on my PC (Craig Berry)
    Re: will perl 5 work w/o server on my PC <camerond@mail.uca.edu>
    Re: Will perl help me to create directory in writing fi <lr@hpl.hp.com>
    Re: Writing to a file... <tim@ipac.caltech.edu>
    Re: Writing to a file... <mauldin@netstorm.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 11 Oct 2000 19:54:37 GMT
From: thundaar54@my-deja.com
Subject: Perl script question
Message-Id: <8s2ghp$r4u$1@nnrp1.deja.com>

Ok, either I'm going nuts or this script is wrong.  I've got a perl cgi
script that is designed to access a database and return some results
based on what the web user enters into a html form.

When the script runs, I get this error message:

Can't call method "Sql" on an undefined value at E:\WEB\new_page\cgi-
bin\search2.cgi line 35.

Now, I know that this seems self-evident, but now here's the piece of
code that the messgae is refering to:

<....>
   $dsn = "cw7474";
   $sql = "SELECT * FROM export2 WHERE cli_id='$in{'cli_id'}' or
resort='$in{'resort'}' or country='$in{'country'}' or state='$in
{'state'}' or city='$in{'city'}';";

   $db = new Win32::ODBC($dsn);
   $db->Sql($sql);          <-----this is the line in question

   while ($db->FetchRow()) {
      $count = $count + 1;
      if ($count == 1) {
         &printDataHeader;
<....>

Am I just missing something or what?


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


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

Date: Wed, 11 Oct 2000 13:55:57 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Perl script question
Message-Id: <39E4D3DD.F6860C3F@ipac.caltech.edu>

thundaar54@my-deja.com wrote:
> 
> Ok, either I'm going nuts or this script is wrong.  I've got a perl cgi
> script that is designed to access a database and return some results
> based on what the web user enters into a html form.
> 
> When the script runs, I get this error message:
> 
> Can't call method "Sql" on an undefined value at E:\WEB\new_page\cgi-
> bin\search2.cgi line 35.
> 
> Now, I know that this seems self-evident, but now here's the piece of
> code that the messgae is refering to:
> 
> <....>
>    $dsn = "cw7474";
>    $sql = "SELECT * FROM export2 WHERE cli_id='$in{'cli_id'}' or
> resort='$in{'resort'}' or country='$in{'country'}' or state='$in
> {'state'}' or city='$in{'city'}';";
> 
>    $db = new Win32::ODBC($dsn);
>    $db->Sql($sql);          <-----this is the line in question
> 
>    while ($db->FetchRow()) {
>       $count = $count + 1;
>       if ($count == 1) {
>          &printDataHeader;
> <....>
> 
> Am I just missing something or what?

You're missing a test for an error return on the instantiation of $db.
Apparently the call to 'new Win32::ODBC' is failing, which would, following
normal Perl coding conventions, put undef into $db.

--

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


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

Date: 11 Oct 2000 21:00:54 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: Perl script question
Message-Id: <8s2ke6$4jq$1@internal-news.uu.net>

thundaar54@my-deja.com wrote:

> When the script runs, I get this error message:

> Can't call method "Sql" on an undefined value at E:\WEB\new_page\cgi-
> bin\search2.cgi line 35.

  This tells you $db is undefined

> Now, I know that this seems self-evident, but now here's the piece of
> code that the messgae is refering to:

>    $db = new Win32::ODBC($dsn);
>    $db->Sql($sql);          <-----this is the line in question

> Am I just missing something or what?

Yep, you're missing a check on whether the connection succeeded.

Erik



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

Date: Wed, 11 Oct 2000 21:37:25 +0200
From: "Squeek" <squeek@club.brunssum.net.remove>
Subject: Perl under win2000
Message-Id: <971293058.612209@fermion.b.fw.brunssum.net>

Hya,

I`m fairly new to Perl and would like it to install and run it on my Windows
2000 running IIS.
I already installed Perl but I need to know where to put the CGI-BIN to
store my script in a
way that they can be used locally.

Thnx.

Squeek




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

Date: Wed, 11 Oct 2000 19:46:10 GMT
From: bmccoy@chapelperilous.net (Brett W. McCoy)
Subject: Re: Perl under win2000
Message-Id: <slrn8u9gtv.4b3.bmccoy@chapelperilous.net>

On Wed, 11 Oct 2000 21:37:25 +0200, Squeek
<squeek@club.brunssum.net.remove> wrote:

> I`m fairly new to Perl and would like it to install and run it on my Windows
> 2000 running IIS.
> I already installed Perl but I need to know where to put the CGI-BIN to
> store my script in a
> way that they can be used locally.

That's a question best answered by consulting your IIS documentation.

Brett W. McCoy
                                              http://www.chapelperilous.net
---------------------------------------------------------------------------
If I'd known computer science was going to be like this, I'd never have
given up being a rock 'n' roll star.
		-- G. Hirst


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

Date: Wed, 11 Oct 2000 18:07:37 GMT
From: mexicanmeatballs@my-deja.com
Subject: Re: Reading a whole file into a string
Message-Id: <8s2a91$lh5$1@nnrp1.deja.com>

In article <39E4A77E.85EAFF3F@stomp.stomp.tokyo>,
  "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
> mexican "Frank" noballs wrote:
^^
Oh, witty.

> > How stupid are you?
> Certainly not as stupid as you. As always
> and always will, I own your mind. You are
> my funny little puppet and, myself, your
> talented puppet mistress pulling your
> strings so very artistically, Frank.

You're just making a fool of yourself.
Now sit down and shut up.

--
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 11:50:35 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Reading a whole file into a string
Message-Id: <39E4B67B.2AD6C370@stomp.stomp.tokyo>

mexicanmeatballs@my-deja.com wrote:

> Godzilla! wrote:
> > mexican "Frank" noballs wrote:

 
> You're just making a fool of yourself.
> Now sit down and shut up.


Just as the Sioux and Northern Cheyenne made
fools of themselves in June of 1876, George.

Tatanka Yotanka Godzilla!


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

Date: Wed, 11 Oct 2000 18:22:02 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: reading/writing binary data
Message-Id: <39e4afc9.4674$2b@news.op.net>
Keywords: Bremen, constituent, tool, treetop


In article <8s296m$kf1$1@nnrp1.deja.com>,
Rich More  <rmore1@my-deja.com> wrote:
>>  Can anyone point me to a good tutorial anywhere?
>try the online docs for:
>perldoc -f pack
>perldoc -f unpack

The online docs for pack and unpack are *not* a good tutorial.  There
is definitely a gap here waiting to be filled.  Here is an opportunity
for someone to garner fame and renown, as well as a good understanding
of 'pack':  Write the 'pack' tutorial.

>perldoc -f bin ( for dos/unix )

I think you mean 'binmode'.  perldoc -f 'bin' does not yield any results.



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

Date: Wed, 11 Oct 2000 18:33:41 GMT
From: Tom Briles <sariq@texas.net>
Subject: Re: reading/writing binary data
Message-Id: <39E4B285.B63D1DED@texas.net>

Mark-Jason Dominus wrote:
> 
> The online docs for pack and unpack are *not* a good tutorial.  There
> is definitely a gap here waiting to be filled.  Here is an opportunity
> for someone to garner fame and renown, as well as a good understanding
> of 'pack':  Write the 'pack' tutorial.

Randal once said that he was going to write an article on pack() and
unpack() for one of his columns.

I don't see it on his website, though.

- Tom


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

Date: 11 Oct 2000 11:42:00 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: reading/writing binary data
Message-Id: <m1d7h7md8n.fsf@halfdome.holdit.com>

>>>>> "Tom" == Tom Briles <sariq@texas.net> writes:

Tom> Randal once said that he was going to write an article on pack() and
Tom> unpack() for one of his columns.

Tom> I don't see it on his website, though.

It's still in my "idea" list.  I have to come up with a clever thing
to do with it before I write about it. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Wed, 11 Oct 2000 19:45:11 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: reading/writing binary data
Message-Id: <x7aecbyxfc.fsf@home.sysarch.com>

>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:

>>>>> "Tom" == Tom Briles <sariq@texas.net> writes:
  Tom> Randal once said that he was going to write an article on pack() and
  Tom> unpack() for one of his columns.

  Tom> I don't see it on his website, though.

  RLS> It's still in my "idea" list.  I have to come up with a clever
  RLS> thing to do with it before I write about it. :)

but there is no idea on earth that will use all or even many of pack's
formats. so that wouldn't make a good tute in any case. mjd's request is
good. we need a packtoot perldoc.

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: Wed, 11 Oct 2000 13:18:11 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Reg exp help
Message-Id: <MPG.144e6ada330c61de98ae27@nntp.hpl.hp.com>

In article <39E4869B.B6BB012A@cc.gatech.edu> on Wed, 11 Oct 2000 
11:26:19 -0400, Stephen Kloder <stephenk@cc.gatech.edu> says...
> a94eribe@my-deja.com wrote:

 ...

> > I need to check that the user submitted a correct quantity.
> >
> > A correct quantity is numeral and can contain one comma (,).
> >
> > How would the notation for that be?
> 
> /^\d*,?\d*$/
> Change *'s to +'s to restrict comma locations (e.g. change both *'s if
> comma can only be between 2 digits).

As written, the regex accepts ',' which is surely wrong.  And if both 
*'s are changed to +'s in accordance with your suggestion, the regex 
would reject '1', which is surely wrong.

The regex also accepts a trailing newline, which is doubtful.  So:

  /^\d+(?:,\d+)?\z/

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


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

Date: Wed, 11 Oct 2000 18:37:38 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: regex challenge
Message-Id: <su9crijabr8901@corp.supernews.com>

Matt Martini (martini@invision.net) wrote:
: I am looking for a regex (an elegant one) that will convert a mac
: address from one form to another.
: The SNMP module returns mac addresses in the format:
: 
:     " AB 21 34 65 78 09 "
: 
: Yes, including the quotes and leading/trainling spaces.  I want to
: convert this into a more standard
: notation for mac addresses:
: 
:     AB21:3465:7809

How I'd do it, given the first string above in $_:

  tr/A-Fa-f0-9//cd;
  $newval = join ':', m/.{4}/g;

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Quidquid latine dictum sit, altum viditur."
   |


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

Date: Wed, 11 Oct 2000 22:44:50 +0100
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: regex challenge
Message-Id: <ant112150345fNdQ@oakseed.demon.co.uk>

In article <su9crijabr8901@corp.supernews.com>, Craig Berry wrote:
> 
> How I'd do it, given the first string above in $_:
> 
>   tr/A-Fa-f0-9//cd;
>   $newval = join ':', m/.{4}/g;

Astounding clarity! That's got my vote.

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



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

Date: Wed, 11 Oct 2000 16:23:50 -0400
From: Joe Wade <jwade1@iupui.edu>
Subject: Return Value from DBI Execute?
Message-Id: <39E4CC55.15E8A143@iupui.edu>

This may be more a SQL question than a Perl question, but here goes.

I’m using perl 5.005_02 built for i86pc-solaris and DBI version 1.06 to
access Oracle 8.0.5 running on a Dell server under Solaris for Intel
2.6.

Here is the SQL statement of interest.

$select_clause  = q{
                update bill_data bd2
                set bd2.st_id = (select sm2.st_id from status_master sm2

                                where sm2.st_desc = 'STATUS_2')
                where   bd2.bd_id in
                (select bd.bd_id
                from    bill_data bd,
                        file_params fp,
                        status_master st
                where   bd_episode_id = ?
                and     bd_service_code_prefix = ?
                and     bd_bill_code = ?
                and     bd_service_date = to_date(?, 'mmddrr')
                and     bd_debit_credit_flag = ?
                and     fp.fp_date_str = ?
                and     bd.fp_id = fp.fp_id
                and     bd.st_id = st.st_id
                and     st.st_desc = 'STATUS_1') };


        $uh = $dbh->prepare($select_clause);

        $rv = $uh->execute($param1, $param2, $param3,
                            $param4, $param5, $param6);

I need to know if no rows were updated (because nothing matched the
inner select) so I can write the non-matching data out to a log file.
However, all I ever get as a return value from the execute of the update
is ‘0E0’.

If I execute the SQL statement in Oracle’s SQL Worksheet, SQL Worksheet
always tells me the number of rows that were updated. Is SQL Worksheet
privy to internal Oracle values that DBI is not?

If this is the case, in order to achieve the above objective must I
break this into two operations, a select to match the data of interest
(returning rowid’s perhaps) and then a loop to iterate through them in a
separate update statement? Would this have potential for locking
problems and/or race conditions if multiple users were accessing the
data?

Thanks in advance for any help.

Joe Wade
Department of Pathology
Indiana University School of Medicine



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

Date: Wed, 11 Oct 2000 18:36:09 GMT
From: rbeau@my-deja.com
Subject: running a program in the background
Message-Id: <8s2bup$n2k$1@nnrp1.deja.com>

I have a program that I need to run in the
background while my computer goes about its normal
business.  How might I be able to accomplish this?


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


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

Date: Wed, 11 Oct 2000 19:12:53 GMT
From: bmccoy@news.speakeasy.org (Brett W. McCoy)
Subject: Re: running a program in the background
Message-Id: <slrn8u9evh.3v5.bmccoy@chapelperilous.net>

On Wed, 11 Oct 2000 18:36:09 GMT, rbeau@my-deja.com <rbeau@my-deja.com>
wrote:

>I have a program that I need to run in the
>background while my computer goes about its normal
>business.  How might I be able to accomplish this?

And what does this have to do with Perl?

-- 
Brett W. McCoy
                                              http://www.chapelperilous.net
---------------------------------------------------------------------------
The average income of the modern teenager is about 2 a.m.


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

Date: Wed, 11 Oct 2000 14:40:04 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: running a program in the background
Message-Id: <Pine.LNX.4.21.0010111439290.19242-100000@hawk.ce.mediaone.net>

On Wed, 11 Oct 2000, rbeau@my-deja.com quoth:

> I have a program that I need to run in the
> background while my computer goes about its normal
> business.  How might I be able to accomplish this?

What type of OS do you use, and is your question Perl specific?

anm
-- 
perl -wMstrict -e ' # Jim Menard -> Wyzelli -> Andrew McGuire
$\=$/;for$;(reverse(1..100)){$$=$;==$|++?q++:"s";$@="bottle";$_=("e"x2).
("l"x2);m?(..)(..)?;print"$;",v32,"$@$$",v32,"of b$1r on the wa$2,",v10,
"$; $@$$ of b$1r,\012Take one down, pass it around,";$;--;$$=$;==1?q??x1
:q-s-;print "$; $@$$ of b$1r ",v111,v110=>" the wa$2",v10 }print"*burp*"
'



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

Date: Wed, 11 Oct 2000 19:48:41 GMT
From: Mark <mtaylorlrim@my-deja.com>
Subject: Re: running a program in the background
Message-Id: <8s2g6m$qu9$1@nnrp1.deja.com>

Depends on the OS.  What ya got?

In article <8s2bup$n2k$1@nnrp1.deja.com>,
  rbeau@my-deja.com wrote:
> I have a program that I need to run in the
> background while my computer goes about its normal
> business.  How might I be able to accomplish this?
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

--
Please reply to this newsgroup as my Deja mail
is used as a spam catcher only!


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


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

Date: Wed, 11 Oct 2000 11:35:05 -0700
From: "Christopher M. Jones" <christopher_j@uswest.net>
Subject: Re: save blob from database
Message-Id: <cp2F5.513$505.197636@news.uswest.net>


"Malte Ubl" <ubl@schaffhausen.de> wrote:
> Well, the file you download is called download.pl, right? So one would
expect
>
> the downloaded file to be called download.pl.
>
> A solution (not a nice one) to your problem would be to write to a
temporary
> file with the correct name and then redirect the user to that file.


Or, you could do it right and use the "Content-Disposition" header
line.

print "Content-Disposition: attachment; filename=$filename\n";
print "Content-type: $contenttype\n\n";
 ...





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

Date: Wed, 11 Oct 2000 19:10:52 GMT
From: peter pilsl <pilsl@goldfisch.atat.at>
Subject: Re: save blob from database
Message-Id: <MPG.144eda3a9403f6009898d8@news.chello.at>

In article <cp2F5.513$505.197636@news.uswest.net>, 
christopher_j@uswest.net says...
> 
> Or, you could do it right and use the "Content-Disposition" header
> line.
> 
> print "Content-Disposition: attachment; filename=$filename\n";
> print "Content-type: $contenttype\n\n";
> ...
> 

yuppie !! ;)
thats it. thanks a lot.

The solution mentioned by another poster, to use script.pl/filename
is working on my apacheserver, but leads to a high responsetime when 
downloading ...

I guess, there are still more than the above content-types (maybe one to 
specify the filesize). Can anyone point me to a list/book or just tell me 
the ones he knows.

thanx,
peter

-- 
pilsl@
goldfisch.at


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

Date: Wed, 11 Oct 2000 18:30:58 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: sendmal doesn't return emails to unknown email-addresses
Message-Id: <Cl2F5.74326$Sr.69300@newsfeed.slurp.net>

In article <39e44c2c$0$26698@SSP1NO25.highway.telekom.at>,
Marc Pölzer <marc.poelzer@jk.uni-linz.ac.at> wrote:
>I encountered a problem when using sendmail in my perl-program.
>The sending of emails works perfectly well. But there's one problem i have.
>Whenever an invalid or non-existing email-adress is passed to sendmail thru
>my program, sendmail doesn't return this email to the address specified in
>the "From: ...:" field.

Delivery failures are reported to the address given as envelope sender (some
mail servers do use the From: header as a destination for failure notices,
but they are wrong - see RFC822 3.6 and RFC1123 5.3.3). sendmail's -f option
might do what you want, or you might be able to do it by using Return-Path:
(which, unlike From:, is actually meant to hold the envelope sender address).
If it doesn't, go to comp.mail.sendmail for further discussion of sendmail.

-- 
Alan Curry    |Declaration of   | _../\. ./\.._     ____.    ____.
pacman@cqc.com|bigotries (should| [    | |    ]    /    _>  /    _>
--------------+save some time): |  \__/   \__/     \___:    \___:
 Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman


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

Date: Wed, 11 Oct 2000 14:13:52 -0600
From: David Haertig <haertig@avaya.com>
Subject: Re: sendmal doesn't return emails to unknown email-addresses
Message-Id: <39E4CA00.63CF0714@avaya.com>

Hi Marc -

> But there's one problem i have.
> Whenever an invalid or non-existing email-adress is passed to sendmail thru
> my program, sendmail doesn't return this email to the address specified in
> the "From: ...:" field.
> Why ?

I use sendmail from a PERL cgi script extensively.  Improperly
addressed email always bounces back to the sender.  How are you
invoking sendmail?

I'm using:

    my($Mail) = "/usr/lib/sendmail -f $Sender -t";
    open(MAIL, "|$Mail") || die;
    print MAIL <<EOF;
    To: $Recipient
    Subject: Blah blah blah
    
    Here is the message.
    
    EOF
    close(MAIL);

Of course you have to specify $Recipient and $Sender prior to
executing this snippet of code.

Good luck,
--
Dave Haertig
haertig@avaya.com


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

Date: Wed, 11 Oct 2000 20:54:50 GMT
From: stdenton@my-deja.com
Subject: Re: splitting an array into a hash of sub-arrays
Message-Id: <8s2k2n$ubh$1@nnrp1.deja.com>

This is a day late and a dollar short, but wot de heck...

In article <8rj1be$vsd$1@nnrp1.deja.com>,
  post_to_group <already_seen@my-deja.com> wrote:
> However for the nuts and bolts, you have definitely posted a helpful
> answer.  Also thanks to the other gent who suggested Data::Dumper.
What
> I prefer about the above is it uses direct code instead of some black
> box module and as a beginner I prefer to "code the stuff by hand."

Hmm, actually I was only using Data::Dumper to pretty-print the results
of what I was doing.  The "meat" of my posting was almost exactly the
same as Ren's.

Compare my code:
for (my $i = 0; $i < numSubsets; $i++) {
  my @s = splice(@hosts, 0, $numInEachSubset);
  $subset[$i] = \@s;
}

to Ren's code:
push @hostgroups, [ splice(@hosts, 0, $hosts_per_group) ]
  while @hosts;

We both have a loop the iterates the same number of times (mine is a
"for" loop, Ren's is a "while" looop).  We both use splice to pull a
bunch of elements from the array at once.  Ren's gets a higher golf
score, mine (I hope!) would be simpler for a novice to understand.

> thanks to both of you,

You're welcome!


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


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

Date: Wed, 11 Oct 2000 20:42:57 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: substring search
Message-Id: <39e4d0d0.4ba8$34d@news.op.net>
Keywords: freight, homunculus, morose, patch


In article <ant101639b49fNdQ@oakseed.demon.co.uk>,
James Taylor  <james@NOSPAM.demon.co.uk> wrote:
>>   $filestring =~ tr/\n/ / ;
>
>Surely that's not necessary if you use single line mode on the match
>operator like this:  m/Runner\s+is\s+done/sg;

Single-line mode is unnecessary.  \s+ will do what you want whether
there is /s or not.

The /s modifier only affects the meaning of the . symbol.
Since the pattern has no dots, the /s is not doing anything.


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

Date: Wed, 11 Oct 2000 20:04:51 GMT
From: eedlin@my-deja.com
Subject: Re: Trying to add a service in win32 env.
Message-Id: <8s2h4t$rlj$1@nnrp1.deja.com>

In article <39E4382F.E967846D@patriot.net>,
  H C <carvdawg@patriot.net> wrote:
> > Win32::Lanman???
>
> http://www.perl.com/CPAN-local/authors/id/J/JH/JHELBERG/
>
> > Daemon???
>
> http://www.roth.net/perl/#Win32Daemon
>

Thanks for the links.  I have downloaded Win32::Daemon and still have
the same error.  Using Win32::Daemon, the service is created, but never
started .  When I manually start it from services, the service keeps
timing out ("unable to start service in a timely fashion").  Maybe a
permissions issue?  I'm not too familiar w/ NT administration, only
unix.  The example in the Daemon perldocs shows launching a perl program
while running perl.exe as a service.  Since my package may be installed
on machines without perl, I'm making all of my perl scripts executable.
I need to launch one of the executables as a service.  So I'm still
stuck in the same place as before. ;(


> > Can't find anything about them.  Not even a
> > hit on CPAN!?!
>
>


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


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

Date: Wed, 11 Oct 2000 21:41:26 GMT
From: dustintodd@my-deja.com
Subject: Re: Using each() on hash of hashes = Thanks
Message-Id: <8s2mq5$t3$1@nnrp1.deja.com>

Thanks for info.

- Dustin -

In article <8s09q3$1mb$1@nnrp1.deja.com>,
  dustintodd@my-deja.com wrote:
> My brain has jumped out of my head and is floping around on the
ground.
> If I wish to iterate through a hash using while and each, but the hash
> is actually stored inside another hash. I am not sure how to get
> reference to has stored inside a hash that I can then give to each().
> Please help.
>
> - Dustin -
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


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


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

Date: Wed, 11 Oct 2000 11:59:30 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Using each() on hash of hashes
Message-Id: <39E4B892.E88B28A6@ipac.caltech.edu>

Eric Kuritzky wrote:
> 
> In article <slrn8u7rdo.3sj.tjla@thislove.dyndns.org>,
> Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
> >I was shocked! How could dustintodd@my-deja.com <dustintodd@my-deja.com>
> >say such a terrible thing:
> >>My brain has jumped out of my head and is floping around on the ground.
> >>If I wish to iterate through a hash using while and each, but the hash
>                                             ^^^^^^^^^^^^^^^
> >>is actually stored inside another hash. I am not sure how to get
> >>reference to has stored inside a hash that I can then give to each().
> >>Please help.
> [snip]
> while(my($family,$hashref)=each(%HoH)){
>    print "$family => {\n";
>    while(my($role,$name)=each(%$hashref)){print qq(\t$role => "$name",\n)};
>    print "},\n"};

Just so the OP sees the all-in-one syntax once (i.e. without intermediate helper
variables):

my($key,$val) = each %{$HoH{key}};

--

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


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

Date: Wed, 11 Oct 2000 21:43:36 GMT
From: dustintodd@my-deja.com
Subject: Re: Using each() on hash of hashes
Message-Id: <8s2mu6$uh$1@nnrp1.deja.com>

Thanks so much. The %$ syntax was the missing bit of info.

- Dustin -

In article <8s0vb9$mkh$1@agate.berkeley.edu>,
  kuritzky@math.berkeley.edu (Eric Kuritzky) wrote:
> In article <slrn8u7rdo.3sj.tjla@thislove.dyndns.org>,
> Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
> >I was shocked! How could dustintodd@my-deja.com <dustintodd@my-
deja.com>
> >say such a terrible thing:
> >>My brain has jumped out of my head and is floping around on the
ground.
> >>If I wish to iterate through a hash using while and each, but the
hash
>                                             ^^^^^^^^^^^^^^^
> >>is actually stored inside another hash. I am not sure how to get
> >>reference to has stored inside a hash that I can then give to each
().
> >>Please help.
> >
> >Have a look at:
> >
> >perldoc perldsc
>
> This doesn't use while and each, which is what the original poster
> wanted.  Using while and each saves memory.  Try this instead:
>
>  %HoH = (
>         flintstones => {
>                 lead      => "fred",
>                 pal       => "barney",
>         },
>         jetsons     => {
>                 lead      => "george",
>                 wife      => "jane",
>                 "his boy" => "elroy",
>         },
>         simpsons    => {
>                 lead      => "homer",
>                 wife      => "marge",
>                 kid       => "bart",
>         },
>  );
>
> while(my($family,$hashref)=each(%HoH)){
>    print "$family => {\n";
>    while(my($role,$name)=each(%$hashref)){print qq(\t$role
=> "$name",\n)};
>    print "},\n"};
>
>


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


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

Date: Wed, 11 Oct 2000 21:43:49 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: will perl 5 work w/o server on my PC
Message-Id: <su9nolj0rpmm28@corp.supernews.com>

ericio (ericio@pd.jaring.my) wrote:
: im using WinME...i manage to install the activeperl 5.005
: can i ask whether i can develop the CGI using perl without any web server on
: my terminal???

You have my permission.  If anyone challenges you, have them come talk to
me.

: can i learn the perl with just in client way(using PC alone)?

Of course.  Perl is not CGI.  CGI is not Perl.  CGI is an interface
specification between a web server and external programs.  Perl is a
programming language.  They have a relationship similar to that between
the concepts 'traffic law' and 'a Jaguar convertible'. 

: TQ in advance...

As long as it's Cuervo.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Quidquid latine dictum sit, altum viditur."
   |


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

Date: Wed, 11 Oct 2000 17:04:48 -0500
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: will perl 5 work w/o server on my PC
Message-Id: <39E4E400.DAC7F437@mail.uca.edu>

Craig Berry wrote:
> 
> ericio (ericio@pd.jaring.my) wrote:
> : im using WinME...i manage to install the activeperl 5.005
> : can i ask whether i can develop the CGI using perl without any web server on
> : my terminal???
> 
> You have my permission.  If anyone challenges you, have them come talk to
> me.

From Webster's Revised Unabridged Dictionary (1913) :

Can \Can\, v. t. & i.
  3. To be able; -- followed by an infinitive without to; as, I
        can go, but do not wish to.

May \May\, v. [imp. Might] 
An auxiliary verb qualifyng the meaning of another verb, by
     expressing:
     (b) Liberty; permission; allowance.

Cameron

-- 
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu


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

Date: Wed, 11 Oct 2000 14:38:14 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Will perl help me to create directory in writing file?
Message-Id: <MPG.144e7d9df1c289f98ae2a@nntp.hpl.hp.com>

In article <slrn8u8k7u.ios.rgarciasuarez@rafael.kazibao.net> on Wed, 11 
Oct 2000 11:30:37 GMT, Rafael Garcia-Suarez <rgarciasuarez@free.fr> 
says...
> Carfield Yim wrote in comp.lang.perl.misc:
> >I would like to write something to a file:
> >
> >open(FILE, ">>file_with_fullpath");
> >
> >if the file and the the directory don't exist yet, will perl make the
> >directory for me? assume that the user run the perl program have the
> >right the create directory and write file.
> 
> No. (You could have tried it yourself.)
> 
> Some hints :
>   -d tests the existence of a directory
>   mkdir creates a directory

Another (perhaps more useful) hint:

  See the function mkpath() in the standard modules File::Path .

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


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

Date: Wed, 11 Oct 2000 13:53:43 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Writing to a file...
Message-Id: <39E4D357.9D16089E@ipac.caltech.edu>

boulemann@my-deja.com wrote:
> 
> Please look at the script below. Everything seems to work except for
> the "print OUT $line;" line. The out file is created but it remains
> empty.  When i remove the "OUT" (i.e. "print $line;") it prints the
> lines properly on the screen...
> Any ideas?

Maybe,but if there's an obvious bug, I've missed it. I'll take a guess anyway.
See below. If you don't mind, I'll make some other code suggestions too. (I will
try to keep to your loquacious coding style and resist the temptation to
markedly shorten your code.)

First:

use strict;
use warnings;

my ($outfile,@files,$date);

Turning on strong syntax checking and using lexical var.s instead of globals can
cut down on a ton of common coding errors. (I eliminate $i and $j in my
suggestions below.) Also:

$|=1; # To aid debug o/p. See perlvar and 'perldoc -f select'.

> 
> opendir(DIR,'.');

You need to check for errors here:

opendir(DIR,'.') || die "Can't open .; $!";

Note the presence of $!. It's important. See perlvar.

> @files = grep(/\.log$/, readdir(DIR));
> closedir DIR;
> 
> $j = 0;
> 
> while ($files[$j]) {

Since you don't use $j anywhere, why not just do

for my $file (@files) {

 ... and replace $files[$j] with $file everywhere below.

>         $i=1;

You can use the builtin variable $. rather than define your own. See perlvar.

> /       open (IN, "$files[$j]") || die "Couldn't open read file.";

(I'll assume the leading '/' is a transcription goof.)

Print the file name and $! in the error message. Also, the quotes around the
$files[$j] are unecessary.

>         $outfile = $files[$j];
>         $outfile =~ s/ex/mo/;

What if the file name doesn't have an 'ex' in it? You'll overwrite the input
file. I'd think this would be a bad thing. You could do this:

next if ! ($outfile =~ s/ex/mo/);

> 
>         open (OUT, "> $outfile")  || die "Couldn't open write file";

Print the file name and $! in the error message.

Add a debug line here:

print "OPENED $outfile.\n";

>         while (defined($line = <IN>)) {

while(<IN>) {

 ... will work fine. Refer to $_ in place of $line below. See perlvar.

If <IN> is empty, OUT will be created but nothing will be put in it. Could that
be what's happening? What do you see if you put this
debug line in your code?

print "INFILE=$file, OUTFILE=$outfile\nLINE $.='$_'\n";

Does that clarify things any? You could also line-buffer OUT, just in case
there's some sort of buffering snafu:

select OUT; $|=1; select STDOUT;

>                 if ($i == 3) {
>                         $date = substr($line,7,10);
>                 } elsif ($i == 4) {
>                         $line =~ s/time/date time/;
>                 } elsif ($i > 4) {
>                         $line =~ s/^/$date /;
>                 }
>                 print OUT $line;

My wild guess is that for some reason you can't write to OUT even though you
could open it. Rewrite this line as

print OUT $line or die "Couldn't write to $outfile; $!";

 ... and see what happens.

>                 $i = $i+1;

You can use $. instead of $i, but if you're going to increment your own
variable, use the much prettier auto-increment operator: '++$i'.
 
>         }
>         close (IN) || die "Couldn't close read file";
>         close (OUT) || die "Couldn't close write file";

 ... filename ... $! ...

I hope one of those suggestions clears things up.

--

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


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

Date: Wed, 11 Oct 2000 21:17:36 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: Writing to a file...
Message-Id: <39E4D893.7CFF2E16@netstorm.net>

boulemann@my-deja.com wrote:
> 
> Please look at the script below. Everything seems to work except for
> the "print OUT $line;" line. The out file is created but it remains
> empty.  When i remove the "OUT" (i.e. "print $line;") it prints the
> lines properly on the screen...
> Any ideas?
> 
> Thanks!
> 
> opendir(DIR,'.');
> @files = grep(/\.log$/, readdir(DIR));
> closedir DIR;
> 
> $j = 0;
> 
> while ($files[$j]) {
>         $i=1;
> /       open (IN, "$files[$j]") || die "Couldn't open read file.";
>         $outfile = $files[$j];
>         $outfile =~ s/ex/mo/;
> 
>         open (OUT, "> $outfile")  || die "Couldn't open write file";

What happens if the substitution $outfile =~ s/ex/mo/ fails?  You're in
a risky situation because perl doesn't appear to issue any warnings (at
least not in the test I did) if you use a different filehandle to open
for writing a file that is already open for reading.

Your while loop would be better written as for (@files), but that's
another issue.

-- Jim


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

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


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