[30408] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1651 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 17 14:09:46 2008

Date: Tue, 17 Jun 2008 11:09:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 17 Jun 2008     Volume: 11 Number: 1651

Today's topics:
        ANNOUNCE: Text::CSV_XS 0.51 <h.m.brand@xs4all.nl>
        current directory, practical problem <cartercc@gmail.com>
    Re: current directory, practical problem <ben@morrow.me.uk>
    Re: Help with Hash of Hashes <simon.chao@fmr.com>
    Re: Help with Hash of Hashes <bugbear@trim_papermule.co.uk_trim>
    Re: Help with Hash of Hashes <cartercc@gmail.com>
    Re: Help with Hash of Hashes <simon.chao@fmr.com>
    Re: Help with Hash of Hashes <kncbram@mapson.hawaii.rr.com>
    Re: Help with Hash of Hashes <kncbram@mapson.hawaii.rr.com>
    Re: Help with Hash of Hashes <kncbram@mapson.hawaii.rr.com>
    Re: Help with Hash of Hashes <simon.chao@fmr.com>
    Re: Is there an include for perl? <simon.chao@fmr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 17 Jun 2008 16:43:21 GMT
From: "H.Merijn Brand" <h.m.brand@xs4all.nl>
Subject: ANNOUNCE: Text::CSV_XS 0.51
Message-Id: <K2M9K1.svH@zorch.sf-bay.org>

The following report has been written by the PAUSE namespace indexer.
Please contact modules@perl.org if there are any open questions.
  Id: mldistwatch.pm 1033 2008-06-16 21:28:24Z k

               User: HMBRAND (H.Merijn Brand)
  Distribution file: Text-CSV_XS-0.51.tgz
    Number of files: 34
         *.pm files: 1
             README: Text-CSV_XS-0.51/README
           META.yml: Text-CSV_XS-0.51/META.yml
  META-driven index: yes
  Timestamp of file: Tue Jun 17 15:32:05 2008 UTC
   Time of this run: Tue Jun 17 15:33:36 2008 UTC

2008-06-17  0.51 - H.Merijn Brand   <h.m.brand@xs4all.nl>

        * Allow UTF8 even without binary => 1
        * Fixed a few pod typo's
        * Lifted the max of 255 for bind_columns

2008-06-04  0.50 - H.Merijn Brand   <h.m.brand@xs4all.nl>

        * Skip a few tests in automated testing, as they confuse
          reports. This is important for the automated sites that
          mark modules as fail if it is not an obvious full PASS
        * 0.46 caused the last still open RT bug to be closed!
        * Tested on 5.11.0, 5.10.0, 5.8.8, 5.6.2, and 5.005_04,
          Strawberry and Cygwin

2008-06-04  0.46 - H.Merijn Brand   <h.m.brand@xs4all.nl>

        * In examples add die on failed close calls
        * Use Test::MinimumVersion (not distributed)
        * Added option -F to examples/csv2xls
        * More source code cleanup
        * Nailed the UTF8 issues for parsing
        * Nailed the UTF8 issues for combining

Highlights ...

       Unicode (UTF8)

       On parsing (both for "getline ()" and "parse ()"), if the source is
       marked being UTF8, then parsing that source will mark all fields  that
       are marked binary will also be marked UTF8.

       On combining ("print ()" and "combine ()"), if any of the combining
       fields was marked UTF8, the resulting string will be marked UTF8.

       binary
           If this attribute is TRUE, you may use binary characters in  quoted
           fields, including line feeds, carriage returns and NULL bytes.  (The
           latter must be escaped as ""0".) By default this feature is off.

           If a string is marked UTF8, binary will be turned on  automatically
           when binary characters other than CR or NL are encountered. Note
           that a simple string like "\x{00a0}" might still be binary, but  not
           marked UTF8, so setting "{ binary =" 1 }> is still a wise  option.

Enjoy, Have FUN! H.Merijn




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

Date: Tue, 17 Jun 2008 06:42:05 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: current directory, practical problem
Message-Id: <675afc98-4569-43a5-8554-7e2b0c9990e4@d1g2000hsg.googlegroups.com>

I know that Perl has a notion of the current directory, and that this
notion can be changed.

I wrote a script a couple of years ago that generates about a dozen
files, deleting some and moving others to various directories. Since
that time, others have modified it in various ways, unfortunately
without following through the dependencies. Late last week, the script
stopped working, and I was invited to fix it. I was able to compare
the script that I released with the current script and make it work.
In the process, I was requested to generate an additional file, to be
placed in the script directory. The script now generates the file, but
places it into another directory.

Neither
open RESULTS, ">results.txt";  nor
open RESULTS, ">./results.txt";
work, and I don't want to hard code the directory path because the
script gets moved from machine to machine and the path differs. (I use
a config file which initializes the relative paths of where to put the
files.)

The script is now 15 pages long and quite frankly I don't want to go
through it line by line -- I simply don't have the time. Any pointers
on how to fix this? Other than hard coding the absolute path? (I just
did this, and it works for now, until it's run on another server.)

Thanks, CC.


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

Date: Tue, 17 Jun 2008 15:57:16 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: current directory, practical problem
Message-Id: <cvvki5-32l2.ln1@osiris.mauzo.dyndns.org>


Quoth cartercc <cartercc@gmail.com>:
> I know that Perl has a notion of the current directory, and that this
> notion can be changed.
> 
> I wrote a script a couple of years ago that generates about a dozen
> files, deleting some and moving others to various directories. Since
> that time, others have modified it in various ways, unfortunately
> without following through the dependencies. Late last week, the script
> stopped working, and I was invited to fix it. I was able to compare
> the script that I released with the current script and make it work.
> In the process, I was requested to generate an additional file, to be
> placed in the script directory. The script now generates the file, but
> places it into another directory.

So you don't want the current working directory, you want the directory
the script is in. Use FindBin.

Ben

-- 
I've seen things you people wouldn't believe: attack ships on fire off
the shoulder of Orion; I watched C-beams glitter in the dark near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die.                                                   ben@morrow.me.uk


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

Date: Tue, 17 Jun 2008 06:48:42 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Help with Hash of Hashes
Message-Id: <932067de-bf87-4924-a705-0b285ae98d56@s50g2000hsb.googlegroups.com>

On Jun 17, 12:25=A0am, Kevin Brammer <kncb...@mapson.hawaii.rr.com>
wrote:
> I'm trying to write what I thought would be a simple script for work. =A0I=

> =A0 can visualize the data structure I need in my head, but coding it is
> another story. =A0Basically, I'm parsing a text file which is the output
> of a web query. =A0The format is basically:
>
> 00-00AAAA
> =A0 - string,0,0,0,0,0
> =A0 - string,0,0,0,0,0
>
> The thing is, each "item" (the 00-00AAAA) can have 0-4 entries below it,
> semi-csv formatted, default value of "0".
>
> My data structure in my head was a hash of hashes:
>
> %HoH =3D ( =A0item =3D> {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 entry1 =3D> "0",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 entry2 =3D> "0",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 entry3 =3D> "0",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 );
>
> Problem is, I would like it to be dynamic enough to pull the "item" from
> the file and not have to "declare" the name ahead of time. =A0I'm using
> strict, and am careful about data input and validation. =A0So, in this
> case I would have:
>
> %HoH =3D ( "00-00AAAA" =3D> {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 entry1 =3D> "string,0,0,0,0,0",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 entry2 =3D> "string,0,0,0,0,0",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 entry3 =3D> "0",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ....
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 );
>
> I was able to do it using a %HoH =3D (); and then just building the hash
> as I went along, but is that "correct"?

Here's a quick stab at a solution--not elegant by any means...also, i
added an "entry0" for every key, so even if the data doesn't have an
entry, the "item" will still show up in the hash.

#!/usr/bin/perl

use strict; use warnings;
use Data::Dumper;

my %h;
my $last_key;
my $entry_no;
while ( <DATA> ) {
    chomp;
    if ( /^(\S+)/ ) {
        $last_key =3D $1;
        $entry_no =3D 0;
        $h{$last_key}{"entry$entry_no"} =3D 0;
    }
    else {
        my ( $val ) =3D /.+?\-\s(.*)$/;
        if ( $last_key ) {
            $entry_no++;
            $h{$last_key}{"entry$entry_no"} =3D $val;
        }
    }

}

print Dumper( \%h ), "\n";

__DATA__
00-00AAAA
  - string,0,0,0,0,0
  - string,0,0,0,0,0
1-A
  - blah,0
2-B
3-C
  - C,1
  - C,2
  - C,3



> ./hoh.pl
$VAR1 =3D {
          '1-A' =3D> {
                     'entry0' =3D> 0,
                     'entry1' =3D> 'blah,0'
                   },
          '2-B' =3D> {
                     'entry0' =3D> 0
                   },
          '00-00AAAA' =3D> {
                           'entry2' =3D> 'string,0,0,0,0,0',
                           'entry0' =3D> 0,
                           'entry1' =3D> 'string,0,0,0,0,0'
                         },
          '3-C' =3D> {
                     'entry2' =3D> 'C,2',
                     'entry0' =3D> 0,
                     'entry3' =3D> 'C,3',
                     'entry1' =3D> 'C,1'
                   }
        };



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

Date: Tue, 17 Jun 2008 14:56:16 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Help with Hash of Hashes
Message-Id: <wZqdnZfnX7QcX8rVRVnyuAA@posted.plusnet>

Kevin Brammer wrote:
> 
> I'm trying to write what I thought would be a simple script for work.  I 
>  can visualize the data structure I need in my head, but coding it is 
> another story.  Basically, I'm parsing a text file which is the output 
> of a web query.  The format is basically:
> 
> 00-00AAAA
>  - string,0,0,0,0,0
>  - string,0,0,0,0,0
> 
> The thing is, each "item" (the 00-00AAAA) can have 0-4 entries below it, 
> semi-csv formatted, default value of "0".
> 
> My data structure in my head was a hash of hashes:
> 
> %HoH = (  item => {
>         entry1 => "0",
>         entry2 => "0",
>         entry3 => "0",
>         }
>     );

Surely you want a hash of arrays?

%HoA = {  item => [
           "0",
         "0",
         "0",
         ]
     };

   BugBear


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

Date: Tue, 17 Jun 2008 07:18:23 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: Help with Hash of Hashes
Message-Id: <65b83989-317f-48c4-aebc-8254da3c8672@x35g2000hsb.googlegroups.com>

On Jun 17, 12:25 am, Kevin Brammer <kncb...@mapson.hawaii.rr.com>
wrote:
> I'm trying to write what I thought would be a simple script for work.  I
>   can visualize the data structure I need in my head, but coding it is
> another story.  Basically, I'm parsing a text file which is the output
> of a web query.  The format is basically:
>
> 00-00AAAA
>   - string,0,0,0,0,0
>   - string,0,0,0,0,0

I solved an identical probelm with a hash array references. My file
contained open seats in course sections, like this:
BIO-1101 ZA1:20 ZA2:20 ZA3:20
ENG-1101 ZA1:25 ZA2:25

To write, I created a hash of courses (like BIO-1101) with a value
comprised of a reference to an array, and then pushed each section to
the array for each hash.

To read, I iterated through the hash created the courses, then split
the array elements on the colon, then iterated through that, like
this:

my ($crs, $sec)
foreach $crs (sort keys %open_seats)
  foreach $sec (sort keys %{open_seats{$crs}})
      print "$crs $sec $open_seats{$crs}{$sec}\n"

The data structure looks like this:
BIO-1101 => [ZA1:20, ZA2:20, ZA3:30]

CC


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

Date: Tue, 17 Jun 2008 07:54:17 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Help with Hash of Hashes
Message-Id: <ff7f0ccf-4cf2-4042-89a9-63a76624d68e@d45g2000hsc.googlegroups.com>

On Jun 17, 12:25=A0am, Kevin Brammer <kncb...@mapson.hawaii.rr.com>
wrote:
> I'm trying to write what I thought would be a simple script for work. =A0I=

> =A0 can visualize the data structure I need in my head, but coding it is
> another story. =A0Basically, I'm parsing a text file which is the output
> of a web query. =A0The format is basically:
>
> 00-00AAAA
> =A0 - string,0,0,0,0,0
> =A0 - string,0,0,0,0,0
>
> The thing is, each "item" (the 00-00AAAA) can have 0-4 entries below it,
> semi-csv formatted, default value of "0".
>
> My data structure in my head was a hash of hashes:
>
> %HoH =3D ( =A0item =3D> {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 entry1 =3D> "0",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 entry2 =3D> "0",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 entry3 =3D> "0",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 );
>
> Problem is, I would like it to be dynamic enough to pull the "item" from
> the file and not have to "declare" the name ahead of time. =A0I'm using
> strict, and am careful about data input and validation. =A0So, in this
> case I would have:
>
> %HoH =3D ( "00-00AAAA" =3D> {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 entry1 =3D> "string,0,0,0,0,0",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 entry2 =3D> "string,0,0,0,0,0",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 entry3 =3D> "0",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ....
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 );
>
> I was able to do it using a %HoH =3D (); and then just building the hash
> as I went along, but is that "correct"?

For the record, I agree with bugbear that a more appropriate data
structure would be a hash of arrays.


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

Date: Tue, 17 Jun 2008 05:48:58 -1000
From: Kevin Brammer <kncbram@mapson.hawaii.rr.com>
To: nolo contendere <simon.chao@fmr.com>
Subject: Re: Help with Hash of Hashes
Message-Id: <4857DCEA.3080307@mapson.hawaii.rr.com>

nolo contendere wrote:

 > [snip]
> For the record, I agree with bugbear that a more appropriate data
> structure would be a hash of arrays.

Thanks for the replies everyone.

The only problem with a hash of arrays is I need to be able to lookup 
the values by name.  For example, I need to be able to pull 00-00AAAA, 
entry2 ($HoH{$item}{$entry})  independently.  I suppose I could go 
searching through the array for the particular hash item, but it just 
seems more efficient to call it.

Kevin


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

Date: Tue, 17 Jun 2008 05:49:05 -1000
From: Kevin Brammer <kncbram@mapson.hawaii.rr.com>
To: nolo contendere <simon.chao@fmr.com>
Subject: Re: Help with Hash of Hashes
Message-Id: <4857DCF1.3020904@mapson.hawaii.rr.com>

nolo contendere wrote:

 > [snip]
> For the record, I agree with bugbear that a more appropriate data
> structure would be a hash of arrays.

Thanks for the replies everyone.

The only problem with a hash of arrays is I need to be able to lookup 
the values by name.  For example, I need to be able to pull 00-00AAAA, 
entry2 ($HoH{$item}{$entry})  independently.  I suppose I could go 
searching through the array for the particular hash item, but it just 
seems more efficient to call it.

Kevin


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

Date: Tue, 17 Jun 2008 05:49:14 -1000
From: Kevin Brammer <kncbram@mapson.hawaii.rr.com>
Subject: Re: Help with Hash of Hashes
Message-Id: <4857dbe4$0$4087$4c368faf@roadrunner.com>

nolo contendere wrote:

 > [snip]
> For the record, I agree with bugbear that a more appropriate data
> structure would be a hash of arrays.

Thanks for the replies everyone.

The only problem with a hash of arrays is I need to be able to lookup 
the values by name.  For example, I need to be able to pull 00-00AAAA, 
entry2 ($HoH{$item}{$entry})  independently.  I suppose I could go 
searching through the array for the particular hash item, but it just 
seems more efficient to call it.

Kevin


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

Date: Tue, 17 Jun 2008 08:56:54 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Help with Hash of Hashes
Message-Id: <3dbf5679-2339-4086-8a44-c4e7b184f582@25g2000hsx.googlegroups.com>

On Jun 17, 11:49=A0am, Kevin Brammer <kncb...@mapson.hawaii.rr.com>
wrote:
> nolo contendere wrote:
>
> =A0> [snip]
>
> > For the record, I agree with bugbear that a more appropriate data
> > structure would be a hash of arrays.
>
> Thanks for the replies everyone.
>
> The only problem with a hash of arrays is I need to be able to lookup
> the values by name. =A0For example, I need to be able to pull 00-00AAAA,
> entry2 ($HoH{$item}{$entry}) =A0independently. =A0I suppose I could go
> searching through the array for the particular hash item, but it just
> seems more efficient to call it.
>

Right, but you're artificially creating the "entry0", "entry1"...key
in your hash. So you are doing more work than you need since that
could more easily be the array index.


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

Date: Tue, 17 Jun 2008 06:11:23 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Is there an include for perl?
Message-Id: <ba0de362-2c6e-41ae-818e-4c8175fc9aa7@b1g2000hsg.googlegroups.com>

On Jun 16, 5:36=A0pm, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
> On 2008-06-16 18:18, nolo contendere <simon.c...@fmr.com> wrote:
>
> > On Jun 16, 2:07=A0pm, Bill H <b...@ts1000.us> wrote:
> >> On Jun 16, 1:19=A0pm, J=FCrgen Exner <jurge...@hotmail.com> wrote:
>
> >> > Bill H <b...@ts1000.us> wrote:
> >> > >I am looking for an include for perl. I know about require, use etc
> >> > >and use them, but I have a program that is getting large and would
> >> > >like to put some of the code into their own files and just use a
> >> > >include "filename" where the code I pulled belongs and have nothing
> >> > >else done to that included code other than it being inserted when th=
e
> >> > >program is run.
>
> >> > Are you looking for do()?
>
> More likely for eval.
>
> >> Hi Jurgen. I looked at do() and it didn't seem to fit what I want.
>
> > How does do() not fit what you want?
>
> Probably in exactly the same way as require and use don't fit, as the
> visibility of variables is the same in all three cases.
>

Ahh, I missed the OP's mention of variable scope. Ben's suggestion
would solve that issue.


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 1651
***************************************


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