[11239] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4839 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 6 21:07:17 1999

Date: Sat, 6 Feb 99 18:00:20 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 6 Feb 1999     Volume: 8 Number: 4839

Today's topics:
    Re: ActivePerl on NT- HELP! <sigi@rueckenwind.org>
        DBI - Creating an array of results from a query <gary@onegoodidea.com>
        DBI <nathan@pentrel.com>
    Re: Dynamically Naming Array Variables <james@mauldin.nu>
        find where .pl was called from <bencas@bigfoot.com>
        Help - Why doesn't this work? <kraaikae@xs4all.nl>
    Re: Help - Why doesn't this work? (Alastair)
    Re: Help - Why doesn't this work? <gary@onegoodidea.com>
    Re: Help - Why doesn't this work? <ebohlman@netcom.com>
    Re: Help - Why doesn't this work? <palincss@his.com>
        help me <baj1@essrl.wustl.edu>
        installing cgi.pm win32/98?!? <bencas@bigfoot.com>
        Is there a Perl Gtk Tutorial? <dermot.musgrove@virgin.net>
    Re: passing info from one script to another using POST <ebohlman@netcom.com>
    Re: Perl5.005002 Broken on number passing? (Tad McClellan)
    Re: Program needs compactification <uri@home.sysarch.com>
        regex - matching acros lines (Eric Smith)
    Re: regex - matching acros lines <jcounts@voicenet.com>
    Re: Server Push in IE3/4 <allan@due.net>
    Re: submit information with #exec cgi="/cgi-local/busin <jcounts@voicenet.com>
        What Am I Doing Wrong Here? <jpass@rochester.rr.com>
    Re: What Am I Doing Wrong Here? (M.J.T. Guy)
    Re: What's happening with this hash? (Ronald J Kimball)
    Re: What's happening with this hash? (John Moreno)
    Re: Would love UNIX program that could read Excel binar (root)
    Re: Would love UNIX program that could read Excel binar <dermot.musgrove@virgin.net>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Sat, 6 Feb 1999 22:33:00 -0000
From: "sugus" <sigi@rueckenwind.org>
Subject: Re: ActivePerl on NT- HELP!
Message-Id: <79icq2$6jn$1@news4.muc.eurocyber.net>

Thanks for your hints!

Actually the night was long, I tried out don't know what, finally I tried
again to reinstall Perl (without uninstalling it before), and this time
there was no abort of the installing process, and now its running again. The
question is: how long? (it was running before, too, and two days later it
didn't anymore, but I hadn't changed anything on my system...)
So for the moment, everything's fine, the good thing is that now I've got to
know this newsgroup -
CU again!

Thanx again, by, sugus




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

Date: Sun, 7 Feb 1999 00:19:49 -0000
From: "Gary O'Keefe" <gary@onegoodidea.com>
Subject: DBI - Creating an array of results from a query
Message-Id: <79im7b$hlf$1@plug.news.pipex.net>

Dear all

I'm using the DBI interface for the first time and I'm experiencing some
difficulties extracting and storing an entire set of results from a query.
I've prepare'd and execute'd the query (that went off fine - all the
statements were set to die if there was any failure) and now I want to store
the results in an array called @results. Here's what I'm doing:

while ( @{ $results[++$#results] = \( $sth -> fetchrow_array ) } ) {}

and when I try to dereference the results from the array I get back that the
contents of the array are not references to arrays. I think what is
happening here is that all the items in the returned array are being
refrerenced, rather than the array as a whole. Any thoughts?

Cheers

Gary

ps I tried using fetchrow_arrayref but that brings back the same reference
each time, so all the rows are the same as the last one retrieved.




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

Date: Sun, 07 Feb 1999 00:36:53 +0000
From: Nathan Feger <nathan@pentrel.com>
Subject: DBI
Message-Id: <36BCE025.D31E0A3D@pentrel.com>

hi,

Where can I find a descent bit of information on DBI.  I cannot seem to
find a good listing of the capabilities of what is possible with DBI,
the site where you download it doesn't have a good reference. 

Perhaps someone could point me to another.


thanks

-nathan


-- 
Nathan Feger			e-mail:nathan@pentrel.com
Pentrel Internet		whois NF1024
http://www.pentrel.com		phone: 877.pentrel


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

Date: Sat, 06 Feb 1999 17:28:24 -0500
From: James Mauldin <james@mauldin.nu>
Subject: Re: Dynamically Naming Array Variables
Message-Id: <36BCC207.F7713459@mauldin.nu>

Use a hash of arrays.

push @{ $affiliates{$affiliate} }, $_;

Hash of arrays = %affiliates
Key = $affiliate
Value (an array) =  @{$affiliates {$affiliate }}

-- Jim


George H wrote:

> I am trying to dynamically give names to array variables but
> I have been stumped for a couple hours now.  The code is below.
>
> for $affiliate(@affiliates)
>         {
>         open(LOG, "$basedir/$affiliate/searchlog") or die "Could not open log.";
>         while (<LOG>)
>                 {
>                 chomp;
>                 push(@log,$_);
>                 push(@$affiliate,$_);  ###THIS IS MY PROBLEM
>                 }
>         close(LOG);
>         }
>
> Early in the program I grab the names of all the 'affiliates' and put them into an array called @affiliates (names like larry,
> bill, megan).  Each affiliate directory has a file called searchlog.  I open all those files one at a time and put it into @log ...
> but I also want to put larry stuff into @larry and the megan stuff into @megan ... you can see some code above that doesn't work.
> I tried some referencing and dereferencing stuff but that isn't working either.  I read the FAQ pages and my manuals ... no real
> example how to do this.  I am starting to think that this may be a problem with my approach or
> methodology.  Any ideas or guidance would be welcome.





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

Date: Sun, 7 Feb 1999 00:21:01 -0000
From: "el_pollo_diablo" <bencas@bigfoot.com>
Subject: find where .pl was called from
Message-Id: <79imbo$2jo$1@news5.svr.pol.co.uk>

Is there any way for a perl script to know where it has been called from?
(specifically called from a #exec SSI)?

Anyone?

Thanks mon,

--

Peace, Empathy, Desire, Mischeif and Gladness.
Ben




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

Date: Sat, 6 Feb 1999 23:56:58 +0100
From: "Egon Kraaikamp" <kraaikae@xs4all.nl>
Subject: Help - Why doesn't this work?
Message-Id: <79ii3u$ng9$1@news2.xs4all.nl>

Hi,

I'm trying to import a flat, character (#) delimited file into a
two-demensional array (records / field-values).
I've tried many configuration (array's and hashes) on my local Perl (Windows
NT)

Everytime I've uploaded the file to my internet server its fails to execute;
"Internal Server error".

The script:

    #!/usr/bin/perl
    print "Content-type: text/plain\n\n";

    $DBCat = ();
    open ( INPUT, "cat.db" );

    $i = 0;
    while ( $Line = <INPUT> )
    {
        chop $Line;
        @Record = split (/#/, $Line);
        push( @{$DBCat[$i++]}, @Record );
    }
    close INPUT;

(The cat.db file is a simple txt-file with "<value1>#<value2>#<value1>")
Everytime I try to store a record (or even a just a field value) it fails.

Thanks in advance for *any* help,
Egon Kraaikamp




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

Date: Sat, 06 Feb 1999 23:47:31 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Help - Why doesn't this work?
Message-Id: <slrn7bpl6j.1og.alastair@calliope.demon.co.uk>

Egon Kraaikamp <kraaikae@xs4all.nl> wrote:
>
>Everytime I've uploaded the file to my internet server its fails to execute;
>"Internal Server error".
>
>The script:
>
>    #!/usr/bin/perl
>    print "Content-type: text/plain\n\n";
>
>    $DBCat = ();
>    open ( INPUT, "cat.db" );

Perhaps your open failed?

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: Sun, 7 Feb 1999 00:06:45 -0000
From: "Gary O'Keefe" <gary@onegoodidea.com>
Subject: Re: Help - Why doesn't this work?
Message-Id: <79ilem$gtp$1@plug.news.pipex.net>


Egon Kraaikamp wrote in message <79ii3u$ng9$1@news2.xs4all.nl>...

[stuff deleted]

>    while ( $Line = <INPUT> )
>    {
>        chop $Line;
>        @Record = split (/#/, $Line);
>        push( @{$DBCat[$i++]}, @Record );
>    }
>    close INPUT;


while ( <INPUT> ) {
    chomp;
    @Record = split /#/;
    push (@DBCat, \@Record);
}
close INPUT;

which should create an array of references to the arrays formed from the
hash-delimited file.

Anyone who can spot any obvious mistakes, please feel free to slap me down.
I'm not even any good at perl (as you'll see in my own posting for help).

Gary




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

Date: Sun, 7 Feb 1999 00:59:27 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Help - Why doesn't this work?
Message-Id: <ebohlmanF6rEr3.Ao1@netcom.com>

Gary O'Keefe <gary@onegoodidea.com> wrote:
: while ( <INPUT> ) {
:     chomp;
:     @Record = split /#/;
:     push (@DBCat, \@Record);
: }
: close INPUT;

: which should create an array of references to the arrays formed from the
: hash-delimited file.

: Anyone who can spot any obvious mistakes, please feel free to slap me down.
: I'm not even any good at perl (as you'll see in my own posting for help).

<slap>This will fill @DBCat up with a bunch of references to the *same*
record, whose values will all be those of the last one read in.  Either
lexicalize @Record *within* the loop ("my @Record...") or copy its
contents before referencing it ("[@Record]" rather than
"\@Record").</slap>



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

Date: Sat, 06 Feb 1999 20:04:12 -0500
From: Steve Palincsar <palincss@his.com>
To: Egon Kraaikamp <kraaikae@xs4all.nl>
Subject: Re: Help - Why doesn't this work?
Message-Id: <36BCE68C.6A61F21C@his.com>

Egon Kraaikamp wrote:
> 
> Hi,
> 
> I'm trying to import a flat, character (#) delimited file into a
> two-demensional array (records / field-values).
> I've tried many configuration (array's and hashes) on my local Perl (Windows
> NT)
> 
> Everytime I've uploaded the file to my internet server its fails to execute;
> "Internal Server error".
>


Have you checked the server error log?

I just copied your script and ran perl -cw against it, and
got a curious error message:  

Value of <HANDLE> construct can be "0"; test with defined() at
snip line 65535.  

It's possible this error is causing a message which in turn is
giving you 
the "internal server error" message.

I also not a curiousity: you are assigning to a scalar an empty
list.
Don't you mean @DBCat = ();  which would be a common way of
initializing
an array?

And also, you really should test the success of the file open. 
That's
always a good idea.  Never know why you can't open a file...

> The script:
> 
>     #!/usr/bin/perl
>     print "Content-type: text/plain\n\n";
> 
>     $DBCat = ();
>     open ( INPUT, "cat.db" );
> 
>     $i = 0;
>     while ( $Line = <INPUT> )
>     {
>         chop $Line;
>         @Record = split (/#/, $Line);
>         push( @{$DBCat[$i++]}, @Record );
>     }
>     close INPUT;
> 
> (The cat.db file is a simple txt-file with "<value1>#<value2>#<value1>")
> Everytime I try to store a record (or even a just a field value) it fails.

I suspect this will fail if you just try to read the file line by
line
and print it, never mind the splitting, the complex data
structure, etc.
Have you tested it in a minimalist way like that?

> 
> Thanks in advance for *any* help,
> Egon Kraaikamp


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

Date: Sat, 06 Feb 1999 16:22:27 -0500
From: brian <baj1@essrl.wustl.edu>
Subject: help me
Message-Id: <36BCB293.874@essrl.wustl.edu>

i have a webpage that searches a database and shows the user a list
of entries that match the criteria searched for.  it used to work
but i seemed to have screwed it up and now it gives me a 'bad name'
error.  what does 'bad name' mean? the page is www.essrl.wustl.edu


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

Date: Sun, 7 Feb 1999 01:39:19 -0000
From: "el_pollo_diablo" <bencas@bigfoot.com>
Subject: installing cgi.pm win32/98?!?
Message-Id: <79ir05$5cu$1@news5.svr.pol.co.uk>

I'm using active perl and perl builder. I've just tried to install the
cgi.pm file but I receive this error:

Can't locate CGI.pm in @INC at script line 48.
BEGIN failed--compilation aborted at script line 48.

Whats going on?

I placed the cgi.pm in the lib and created a sub-directory called cgi and
then placed the other .pm's into it. Is this right?

HELP!!



---
Ben





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

Date: Sun, 07 Feb 1999 01:50:32 +0000
From: Dermot Musgrove <dermot.musgrove@virgin.net>
Subject: Is there a Perl Gtk Tutorial?
Message-Id: <36BCF168.164AACF4@virgin.net>

Hi, I have searched for a tutorial on Perl Gtk bindings with
no luck. I don't know Gtk in c mode and any help would be 
welcome.

TIA, Dermot



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

Date: Sun, 7 Feb 1999 00:47:43 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: passing info from one script to another using POST
Message-Id: <ebohlmanF6rE7J.9yC@netcom.com>

Alex Guberman <alex@digi-q.com> wrote:
: Would anyone know how to pass information from one Perl/CGI script to
: another using POST method.  Another words, the first script would get
: the fields, read it, manipulate them and then pass it on to the second
: script to read it like it was passed from an HTML form in the first
: place.

: I know about the LWP module, but I can't figure out how to make it do
: this and if it can do it at all.

Have you read through the LWP Cookbook that came with LWP?



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

Date: Sat, 6 Feb 1999 06:40:26 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Perl5.005002 Broken on number passing?
Message-Id: <q7dh97.4g.ln@magna.metronet.com>

Xeno Campanoli (xeno@bigger.aa.net) wrote:

: I've got the following:
: $n = 005.5;
: I then print
: print STDERR "trace $n\n";

: I get back:
: trace 55

: You can't tell me that this isn't broken.  


   Yes I can.

   That isn't broken.

   Try it with 008.8 instead and all will be revealed.

   ( See the "Scalar value constructors" section in the 
     'perldata.pod' man page
   )


: Larry, you've gotta fix this
: fast!!


   I don't think it will ever be changed.


: P.S., a quick fix is $n = "005.5" instead.


   $n is no longer a number, now it is a string.

   Hardly ever matters though since perl will auto-convert back
   and forth for you.

   A more equivalent fix is

      $n = 5.5;

   Then use (s)printf() to get whatever formatting you want for output.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 06 Feb 1999 18:19:35 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: Program needs compactification
Message-Id: <x7iudfm86w.fsf@home.sysarch.com>

>>>>> "MJTG" == M J T Guy <mjtg@cus.cam.ac.uk> writes:

  MJTG> I suspect you don't understand that [@F,,@F] is the same as [@F,@F].

you are right about the ,, and his code is still broken. for even length
@F, the same keys are generated. it works for odd length @F. so you need
to insert a '' for even @F and nothing for odd @F to ensure all words
are made into a key.

 perl -la0777ne 'print for keys %{{@F,("")x((@F&1)^1),@F}}'

that works but you will get a null word if @F is even. and it is very
ugly. maybe there is a better way to get a "" if @F is even.

this is slightly cleaner but ugly nonetheless.

perl -la0777ne 'print for keys %{{@F,(@F&1?():""),@F}}'


my previous solution is much more elegant:

perl -la0777ne '@a{@F}=();print for sort keys %a'

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 6 Feb 1999 22:09:09 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: regex - matching acros lines
Message-Id: <slrn7bpg99.k9e.eric@plum.fruitcom.com>

Hiya Perl

I've hit a block here:

%SH% one two three whatever and Partners 8 Rue Bellini, 75782 Paris Cedex
%16, Tel 33 1   more words and stuff and then     mpuserve.com. %EH% 

We need to arrange a copy of %IT%all%RO% the documentation%% relating to
Legal Action with a word %SH%rfrh hk%EH% may pass these on to him.  In his

I need my regex to match the string `%SH%' and any character following this
until it gets to the first occurance %EH%.  I need to remove both tags and
the intervening whatever. I can get this to happen when the tags appear on
the same line but not when on different lines like in para. two above.

tried this:

$_ =~ s/%SH%[\n.]*?%EH%//g; and $_ =~ s/%SH%[\n.]*?%EH%//s;

Cannot see why these do not work for me.

TIA for your help

ciao

Eric Smith 


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

Date: Sat, 6 Feb 1999 19:05:51 -0500
From: "John Counts" <jcounts@voicenet.com>
Subject: Re: regex - matching acros lines
Message-Id: <79ilr9$pp6$1@news1.fast.net>

It dosen't work because \n is the default record seperator in Perl.  There
normally won't be anything after \n.

I don't know how you're reading the file or whatever your input is, but Perl
defaults to reading in one line as one record.  This is controlled by a
input record separator $/  You can change the input record sepaprtor to read
paragraphs (or the whole file or whatever) into one record.  i.e $/ = "\n.
\n" (matches a period on a sepate line).  $/ = "" matches a blank line
between paragraphs  undef $/ reads in the whole file.

Eric Smith wrote in message ...
>Hiya Perl
>
>I've hit a block here:
>
>%SH% one two three whatever and Partners 8 Rue Bellini, 75782 Paris Cedex
>%16, Tel 33 1   more words and stuff and then     mpuserve.com. %EH%
>
>We need to arrange a copy of %IT%all%RO% the documentation%% relating to
>Legal Action with a word %SH%rfrh hk%EH% may pass these on to him.  In his
>
>I need my regex to match the string `%SH%' and any character following this
>until it gets to the first occurance %EH%.  I need to remove both tags and
>the intervening whatever. I can get this to happen when the tags appear on
>the same line but not when on different lines like in para. two above.
>
>tried this:
>
>$_ =~ s/%SH%[\n.]*?%EH%//g; and $_ =~ s/%SH%[\n.]*?%EH%//s;
>
>Cannot see why these do not work for me.
>
>TIA for your help
>
>ciao
>
>Eric Smith




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

Date: Sat, 6 Feb 1999 20:27:28 -0500
From: "Allan M. Due" <allan@due.net>
Subject: Re: Server Push in IE3/4
Message-Id: <b_5v2.664$L1.13398@nntp1.nac.net>

Justin M. Silver wrote in message <79flt2$j3m@netaxs.com>...
:Does anyone know if it is possible to do server push in IE. I know how to do
:it in Netscape, and have found documentation on how to do it with IE 2 for
:Mac and Win 3.1 (could anything be more useless?). If anyone knows, please
:tell me. also if you have a sample script it would be greatly appreciated.
:
:Thanks in advance,
:Justin


a) Yes this can be done
b)  Have you tested your script to see if it works with IE 3/4?  Empericism is
highly valued here.
c) I don't see anything Perlish about your question, that is generally
depreicated here.
d) See the documentation that comes with CGI.pm  for an example that uses
push.

HTH

AmD




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

Date: Sat, 6 Feb 1999 19:18:52 -0500
From: "John Counts" <jcounts@voicenet.com>
Subject: Re: submit information with #exec cgi="/cgi-local/businessnewsup.pl" command?
Message-Id: <79imjk$ql6$1@news1.fast.net>


el_pollo_diablo wrote in message <79i0f3$kg4$1@news7.svr.pol.co.uk>...
>Something like this:
>
>#exec cgi="/cgi-local/businessnewsup.pl $county='devon' $town='plymouth"
>$business='example'"

you're almost right #exec
cgi="/cgi-local/businessnewsup.pl?county=devon&town=plymouth&business=exampl
e"

just start your list of parameters with a question mark and separate each
with an & sign.  don't use quotes capitization is up to you.

>But then how do i catch  these variables in my newsup script?

Get a module called CGI.pm and look at the parameters method.  It's trivial
really.  You can do it without a module, but it's a lot more difficult and
error prone.







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

Date: Sat, 6 Feb 1999 18:00:29 -0500
From: "John Passaniti" <jpass@rochester.rr.com>
Subject: What Am I Doing Wrong Here?
Message-Id: <vR3v2.2195$Ba.3005@newsr1.twcny.rr.com>

The intent here was to create a hash of anonymous hashes, and then iterate
through the keys in sorted order:


$x{a}{b}{c} = 1;
$x{a}{b}{d} = 2;
$x{a}{c}{x} = 3;
$x{b}{a}{a} = 4;

foreach $first (sort keys %x) {
  foreach $second (sort keys $x{$first}) {
    foreach $third (sort keys $x{$first}{$second}) {
       print "$first $second $third = $x{$first}{$second}{$third}\n";
    }
  }
}

Perl complains on the second and third foreach that the argument to keys
must be a hash, not a hash element.  This confuses me.  My guess is that
context for "keys" is set by the dollar-sign of it's argument.

Can someone explain to me what I'm doing wrong, and a way to fix it?







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

Date: 6 Feb 1999 23:43:35 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: What Am I Doing Wrong Here?
Message-Id: <79ik37$2a7$1@pegasus.csx.cam.ac.uk>

In article <vR3v2.2195$Ba.3005@newsr1.twcny.rr.com>,
John Passaniti <jpass@rochester.rr.com> wrote:
>The intent here was to create a hash of anonymous hashes, and then iterate
>through the keys in sorted order:
>
>
>$x{a}{b}{c} = 1;
>$x{a}{b}{d} = 2;
>$x{a}{c}{x} = 3;
>$x{b}{a}{a} = 4;
>
>foreach $first (sort keys %x) {
>  foreach $second (sort keys $x{$first}) {
>    foreach $third (sort keys $x{$first}{$second}) {
>       print "$first $second $third = $x{$first}{$second}{$third}\n";
>    }
>  }
>}
>
>Perl complains on the second and third foreach that the argument to keys
>must be a hash, not a hash element.  This confuses me.  My guess is that
>context for "keys" is set by the dollar-sign of it's argument.

The argument to 'keys' must be a hash.   $x{$first} is a *reference*
to a hash.    You can fix this by dereferencing:

   foreach $second (sort keys %{$x{$first}}) {

perldoc perlref   explains this, tho' perhaps not entirely transparently.

If the thing after 'keys' doesn't start with a %, you're onto a loser.


Mike Guy


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

Date: Sat, 6 Feb 1999 15:04:30 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: What's happening with this hash?
Message-Id: <1dmt7oe.1ele1yc1cofly4N@bay2-345.quincy.ziplink.net>

John Moreno <phenix@interpath.com> wrote:

> M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:
> 
> > John Moreno <phenix@interpath.com> wrote:
> > >
> > >So, what I was trying to do should have been $$hash{$i}{'test'}++.
> > 
> > No.    First, that dereferences $hash rather than $hash{$i}.    You'd
> > want    ${$hash{$i}}{'test'}++.    But that's exactly the same as
> > 
> >         $hash{$i}->{'test'}++
> > 
> > which can be abbreviated to
> > 
> >         $hash{$i}{'test'}++
> > 
> > which is what you started with.
> 
> What can I say, I tested it and it works.  So either you've made a
> mistake or someone has finally added a true DWIM module to perl.

I believe you misunderstood the point MJT is making.

Note the very first thing MJT writes:

"...that dereferences $hash rather than $hash{$i}..."

The expression $$hash{$i}{'test'}++ uses the variable $hash, not the
variable %hash.


MJT assumes that you misunderstood the precedence of dereferencing, so
you probably wanted to write:

  ${$hash{$i}}{'test'}++

which uses the variable %hash, but is equivalent to what you started out
with.

It works because it's not what you really wanted to do.
It's very hard for Perl to DWYM when you don't know WYM.  ;-)


> > Your problem is elsewhere.    You want $hash{$i} to be a hash reference,
> > but you initialise it with
> 
> No, I want $hash{$i} to be a counter for something, and I want
> $$hash{$i}{'test'} to be a counter for something that happens to it.

Those two expressions refer to two entirely different variables, $hash
and %hash, which happen to share the same identifier.


If you want $hash{$i} to be a counter, and $hash{$i}->{'test'} to be
another counter, *you can't do that*.  $hash{$i} must be either a
reference or a counter; it can't be both.


> Like so:
> 
> $fruit{'apples'}++;
> $$fruit{'apples'}{'bad'}++;

  DB<1> $fruit{'apples'}++

  DB<2> $$fruit{'apples'}{'bad'}++

  DB<3> x %fruit
0  'apples'
1  1
  DB<4> x $fruit
0  HASH(0x2cc33c8)
   'apples' => HASH(0x2c0dc18)
      'bad' => 1
  DB<5>

The first line added the key 'apples' to the hash %fruit, and assigned
it a value of 1.

The second line autovivified the scalar $fruit as a reference to an
anonymous hash.  It added the key 'apples' to that hash, and
autovivified the associated value as a reference to an anonymous hash.
It added the key 'bad' to that hash, and assigned it a value of 1.


The same thing could be done as:

  $fruit{'apples'}++;
  $fruit2{'apples'}{'bad'}++;


In fact, if you added:

  $fruit = \%fruit2;

before your version, it would be exactly the same thing.


> $fruit{'oranges'}++;
> $$fruit{'oranges'}{'bad'}++;
> 
> I'm not *quite sure why this works, but it does (and I suspect that it's
> not the most memory friendly way of doing it, but I have a very small
> data set so I don't particularly care about that).
> 
> *I think it's giving me a hash with the name of the key, which is what I
> thought I was doing in the first place.

You have one named hash, %fruit, and two anonymous hashes.  There are no
hashes with the name of the key, whatever that means.  :-)


I think what you really want to do is something like this:

$fruit{'apples'}{'total'}++;
$fruit{'apples'}{'bad'}++;

where your main counter is stored in the second-level hash with the
secondary counters.


Or you could do this:

$fruit{'apples'}[0]++;
$fruit{'apples'}[1]{'bad'}++;

where the main counter is the first element in an anonymous array, and
the second element is a reference to the hash of secondary counters.

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 6 Feb 1999 16:26:57 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: What's happening with this hash?
Message-Id: <1dmt940.10gjvr3obkm8sN@roxboro0-023.dyn.interpath.net>

Ronald J Kimball <rjk@linguist.dartmouth.edu> wrote:

> John Moreno <phenix@interpath.com> wrote:
> 
> > M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:
> > 
> > > John Moreno <phenix@interpath.com> wrote:
> > > >
> > > >So, what I was trying to do should have been $$hash{$i}{'test'}++.
[...]
> If you want $hash{$i} to be a counter, and $hash{$i}->{'test'} to be
> another counter, *you can't do that*.  $hash{$i} must be either a
> reference or a counter; it can't be both.
[...]
> > *I think it's giving me a hash with the name of the key, which is what I
> > thought I was doing in the first place.
> 
> You have one named hash, %fruit, and two anonymous hashes.  There are no
> hashes with the name of the key, whatever that means.  :-)


I've got a hash with keys from 1 to 10, I thought I was creating hashes
with names like %1, %2, %3 and so forth with the 

$hash{$i}{'test'}++

each hash only having only one element.

With $$hash{$i}{'test'}++ I seem to be getting result I expected, but
obviously not in the way I intended.

I believe I understand it better now -- the $$hash is creating a
variable named $hash and putting a reference to a anonymous hash in it?
The value of each key in that hash is yet another hash -- each with a
key of 'test' and whatever value I put into it.

I could get the same end results of that script if I dropped the
{'test'} completely and just used $$hash{$i} to hold the end value.

-- 
John Moreno


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

Date: Sat, 6 Feb 1999 20:58:29 GMT
From: root@nowhere.uucp (root)
Subject: Re: Would love UNIX program that could read Excel binary file...
Message-Id: <F6r3LH.1GK@nowhere.uucp>

Don't know if this is what you want or not, but if you want to run
the whole thing from your end, you could just buy StarOffice (if it's
available for your platform) and convert it in StarOffice from Excel to 
dBase or whatever.

(I think they have some kind of VBA-like macro language, so it might even be possible
to automate the process)

I agree that parsing out the file format would probably be a nightmare -
if you want to check into it though I'm pretty sure the specs are
available from the MS website. Who knows, maybe there's an easy way to get
what you want - MS is known for doing things in a user-friendly way :-).

Cheers.


wsherrin (wsherrin@eccms1.dearborn.ford.com) wrote:
: Hi techical friends -

: Been surfing for a couple of days, but no luck...

: Does anyone know of a FREE Magical Perl module or
: package that could take an Excel Binary (BIFF) file
: that has been ftp'd up to a UNIX (Solaris 2.5.1) Server, and
: read the elements of the spreadsheet's cells that will
: then eventually be sent to Oracle (v. 7.1.6).

: The closest thing we have found so far is the
: OLE-Storage module ver. 381.  This "thingy" is on
: many websites, newsgroups, etc.  The source code
: is actually pretty good.  It only provides a way to read
: the header info, however. And even then, I can't
: seem to get it to work in tests...

: If you are still reading this note, and want to know
: the skinny of "why in the world do you want to do that?":

: We have 48 end-user sites with many different browser
: versions (NS 3 and 4; IE 3 and 4).  There cannot be
: any Software distribution solution (that is, we can't use
: ODBC because of Legacy client server applications
: that exist, etc., etc.)  Our end-users have these fairly
: complex Excel Templates (multiple worksheets,
: 200 columns, sums, possibly formulas, maybe 100s of
: rows) that need to get to our Oracle database.  These
: are living and breathing documents, so training the users
: to do a save as .csv is not ideal, and would have to be done
: for each worksheet within the template.  Then they would
: have to upload through the web page, etc.  (painful, huh?).
: After watching a Plugin demo, I certainly would be
: excited about that type of solution, but we are under
: enormous time constraints, and we would still need to
: have all of those different browsers and users get the
: plugin DLL.  The two possibilities right now, if we can't
: get UNIX executable (technically doesn't have to be
: Perl, but that is what the rest of our Application is written
: in - i.e. we could use Java) to do the Excel read, is to
: have a VB button in template that would parse out
: file to text and ftp it in format we could parse out in
: perl... or (backup solution#2) get an NT partition on our
: WEB site so we can have access to all the Microsoft
: products once the template is uploaded.

: It's kinda messy... but fun.  Anyway, thoughts and ideas
: would be very welcome.

: Thanks,

: B I L
: wsherrin@ford.com
: 734-266-8585

:               
: William A. Sherrin        Southfield, MI 48075    
: IBM GLOBAL SERVICES       18000 West Nine Mile
: Road                               I/T Architect             Tel
: 248-552-6707        
:                           Fax 248-552-5669



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

Date: Sun, 07 Feb 1999 01:48:29 +0000
From: Dermot Musgrove <dermot.musgrove@virgin.net>
Subject: Re: Would love UNIX program that could read Excel binary file...
Message-Id: <36BCF0ED.16894156@virgin.net>

> : Does anyone know of a FREE Magical Perl module or
> : package that could take an Excel Binary (BIFF) file
> : that has been ftp'd up to a UNIX (Solaris 2.5.1) Server, and
> : read the elements of the spreadsheet's cells that will
> : then eventually be sent to Oracle (v. 7.1.6).
> 
snip

Hi, I haven't tried it myself but I did see some package called
laola (dist file is laola013.zip). It may not be what you want.

HTH, Dermot



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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 4839
**************************************

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