[30914] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2159 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 26 16:10:10 2009

Date: Mon, 26 Jan 2009 13:09:16 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 26 Jan 2009     Volume: 11 Number: 2159

Today's topics:
    Re: Help: Odd Output <tadmc@seesig.invalid>
    Re: Help: Odd Output <someone@example.com>
    Re: Help: Process text block <tadmc@seesig.invalid>
    Re: Help: Process text block <someone@example.com>
    Re: inputting the ephemerides <hjp-usenet2@hjp.at>
    Re: inputting the ephemerides <hjp-usenet2@hjp.at>
    Re: inputting the ephemerides <larry@example.invalid>
    Re: inputting the ephemerides <larry@example.invalid>
    Re: inputting the ephemerides <jurgenex@hotmail.com>
    Re: inputting the ephemerides sln@netherlands.com
    Re: inputting the ephemerides <jimsgibson@gmail.com>
    Re: inputting the ephemerides <jimsgibson@gmail.com>
        problems making zip with Archive::Zip <mcardeiro@yahoo.com>
    Re: problems making zip with Archive::Zip <thepoet_nospam@arcor.de>
    Re: problems making zip with Archive::Zip <mcardeiro@yahoo.com>
        There is no such thing as Circular Lists (was: FAQ 4.47 sln@netherlands.com
        tracking scope of a variable? <bugbear@trim_papermule.co.uk_trim>
        Update for difference of two arrays (was:  FAQ 4.43 How sln@netherlands.com
        Vista x64 + DBD::Pg driver <psynowiec@WYTNIJTOop.pl>
        Which is faster - hash or array lookup <burner+usenet@imf.au.dk>
    Re: Which is faster - hash or array lookup <bugbear@trim_papermule.co.uk_trim>
    Re: Which is faster - hash or array lookup <fawaka@gmail.com>
    Re: Which is faster - hash or array lookup <burner+usenet@imf.au.dk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 26 Jan 2009 04:58:30 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Help: Odd Output
Message-Id: <slrngnr5qm.ifu.tadmc@tadmc30.sbcglobal.net>

Amy Lee <openlinuxsource@gmail.com> wrote:

> open my $LOCATION, '<', "$location";
                          ^         ^
                          ^         ^

You should not quote lone variables:

    perldoc -q vars

        What's wrong with always quoting "$vars"?


You should always, yes *always*, check the return value from open():

    open my $LOCATION, '<', $location or die "could not open '$location' $!";


>   my $raw_seq_id = (split /\s+/)[0];
>   my $mature_start = (split /\s+/)[1];
>   my $mature_end = (split /\s+/)[2];


    my($raw_seq_id, $mature_start, $mature_end) = split /\s+/;


>   open my $CT, '<', "$raw_seq_id"."\.ct";


    open my $CT, '<', "$raw_seq_id.ct" or die ...;


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Mon, 26 Jan 2009 10:58:27 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: Help: Odd Output
Message-Id: <oJnfl.21$8O.2@newsfe06.iad>

Amy Lee wrote:
> Hello,
> 
> I wrote a script to check the location. Here's my codes.
> 
> #!/usr/bin/perl -w
> 
> use warnings;
> use strict;
> 
> my $location = $ARGV[0];
> open my $LOCATION, '<', "$location";
> 
> my @stack;
> while (<$LOCATION>)
> {
>   chomp;
>   my $raw_seq_id = (split /\s+/)[0];
>   my $mature_start = (split /\s+/)[1];
>   my $mature_end = (split /\s+/)[2];
>   my $mature_id = (split /_/, $raw_seq_id)[3];
>   my $i;
>   my $num = 0;
>   open my $CT, '<', "$raw_seq_id"."\.ct";
>   while (<$CT>)
>   {
>     if ((?dG? ... /dG/) && (!/dG/))
>     {
>       push @stack, (split /\s+/)[4];
>     }
>   }
>   for ($i = $mature_start - 1;$i < $mature_end;$i++)
>   {
>     if ($stack[$i] == 0)
>     {
>       $num = $num + 1;
>     }
>     else
>     {
>       next;
>     }
>   }
>   if ($num <= 2)
>   {
>     print "$raw_seq_id $num\n";
>   }
>   else
>   {
>     next;
>   }
> }


You can simplify that a bit to:

#!/usr/bin/perl
use warnings;
use strict;

@ARGV == 1 or die "Usage: $0 FILENAME\n";

my $location = $ARGV[ 0 ];
open my $LOCATION, '<', $location or die "Cannot open '$location' $!";

while ( <$LOCATION> ) {
     my ( $raw_seq_id, $mature_start, $mature_end ) = split;
     my $mature_id = ( split /_/, $raw_seq_id )[ 3 ];

     open my $CT, '<', "$raw_seq_id.ct" or die "Cannot open 
'$raw_seq_id.ct' $!";

     my @stack;
     while ( <$CT> ) {
         if ( ?dG? ... /dG/ and !/dG/ ) {
             push @stack, ( split )[ 4 ];
             next;
             }
         last if @stack;
         }

     if ( 2 > grep $_ == 0, @stack[ $mature_start - 1 .. $mature_end - 1 
] ) {
         print "$raw_seq_id $num\n";
         }
     }

__END__




John
-- 
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov


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

Date: Mon, 26 Jan 2009 05:03:32 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Help: Process text block
Message-Id: <slrngnr644.ifu.tadmc@tadmc30.sbcglobal.net>

Amy Lee <openlinuxsource@gmail.com> wrote:
> On Sun, 25 Jan 2009 12:09:12 -0800, John W. Krahn wrote:

[ snip a full quote ]

>> John
> Thank you sir. 


DO NOT QUOTE ENTIRE ARTICLES!!

This is seen as rude, and I'm sure you do not want to be seen
as rude, so please stop doing that.

If you have a question about 5 lines of code, then quote only
those 5 lines of code, not the entire program that the lines appear in.


>   if (?dG? ... /dG/ && !/dG/)

> Still failed. So I don't know why it could happen, however if I change if
> loop into if ((?dG? ... /dG/) && (!/dG/)) that could be available. So what
> I wanna ask is the reason for such situations.


Precedence.


    perldoc perlop


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Mon, 26 Jan 2009 08:30:02 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: Help: Process text block
Message-Id: <eylfl.24132$B01.16930@newsfe13.iad>

Amy Lee wrote:
> On Sun, 25 Jan 2009 12:09:12 -0800, John W. Krahn wrote:
> 
>> Amy Lee wrote:
>>> On Mon, 26 Jan 2009 01:41:02 +0800, Amy Lee wrote:
>>>
>>>> On Sun, 25 Jan 2009 08:14:00 -0800, John W. Krahn wrote:
>>>>
>>>>> Amy Lee wrote:
>>>>>> I have many files fill with following contents.
>> [ *SNIP* ]
>>
>>>>>> The text block is from "dG" to the next "dG". And further I just process
>>>>>> the first block. So that's following contents.
>> [ *SNIP* ]
>>
>>>>>> I don't know how to write such condition to do that. I used "while" loop
>>>>>> to do that but still failed. So could anyone show me some points?
>> [ *SNIP* ]
>>
>>>>> " | perl -ne'print if ?dG? ... /dG/ and ! /dG/'
>> [ *SNIP* ]
>>
>>>> Thank you very much, anyway, how to write this into codes? Especially ?dG?
>>>> ... /dG/ part.
>> $ perl -MO=Deparse -ne'print if ?dG? ... /dG/ and ! /dG/'
>> LINE: while (defined($_ = <ARGV>)) {
>>      print $_ if ?dG? ... /dG/ and not /dG/;
>> }
>> -e syntax OK
>>
>>
>> Or:
>>
>> while ( <FILEHANDLE> ) {
>>      if ( ?dG? ... /dG/ ) {
>>          print unless /dG/;
>>          }
>>      }
>>
>>
>>> And furthermore, could you explain the codes? I didn't understand it
>>> clearly. Thank you very much.
>> ?dG? only matches the first time it is found while /dG/ will match every 
>> time it is found.  '...' is the flip-flop operator.  The expression is 
>> false until the left operand is true and then it is true until the right 
>> operand is true when it becomes false again.  So it matches the first 
>> line that contains 'dG' until the next line that contains 'dG' and then 
>> quits looking.  And once it has found the correct line(s), you don't 
>> want to print the line that contains 'dG', just the other lines.
>
> Thank you sir. However, when I use such following codes.
> 
> while (<>)
> {
>   if (?dG? ... /dG/ && !/dG/)
>   {
>     print;
>   }
> } 
> Still failed. So I don't know why it could happen, however if I change if
> loop into if ((?dG? ... /dG/) && (!/dG/)) that could be available. So what
> I wanna ask is the reason for such situations.

The reason I used 'and' instead of '&&' is exactly because of the high 
precedence of '&&' which, as you say, doesn't work unless you use 
parentheses.  If you are going to change the code I posted you have to 
expect different results sometimes.



John
-- 
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov


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

Date: Mon, 26 Jan 2009 10:13:45 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: inputting the ephemerides
Message-Id: <slrngnqvma.t9g.hjp-usenet2@hrunkner.hjp.at>

On 2009-01-26 00:02, Larry Gates <larry@example.invalid> wrote:
>   my @s = split / /, $line;
[...]
>
> So now I want to take the second element of s and hit it with
>
> s2 = s/h/ /;
>
> , but I can't figure out how to deal with these perl arrays like I'm
> accustomed to with C or fortran.

Neither in C nor in Fortran do you access the second element of an array
named "s" with "s2". In C it's "s[1]" and in Fortran it's "s(2)".  I was
going to suggest you should read perldoc perldata, but I see in a
different message that you're reading the Perl bible in church, so I'm
suggesting you read the chapter about arrays in the camel book instead.
I'm sure it explains in detail how to access array elements.

	hp


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

Date: Mon, 26 Jan 2009 10:17:06 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: inputting the ephemerides
Message-Id: <slrngnqvsi.t9g.hjp-usenet2@hrunkner.hjp.at>

On 2009-01-26 00:16, Larry Gates <larry@example.invalid> wrote:
> I bought a Harbison and Steele from someone off the net, and the
> s.o.b. sends me a 1985 version, older than K&R 1.

K&R 1 was published in 1978, IIRC (the German translation is from 1983).

	hp


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

Date: Mon, 26 Jan 2009 13:10:45 -0700
From: Larry Gates <larry@example.invalid>
Subject: Re: inputting the ephemerides
Message-Id: <92rvjd07s127.8n99bu1fdl1v$.dlg@40tude.net>

On Mon, 26 Jan 2009 10:13:45 +0100, Peter J. Holzer wrote:

> On 2009-01-26 00:02, Larry Gates <larry@example.invalid> wrote:
>>   my @s = split / /, $line;
> [...]
>>
>> So now I want to take the second element of s and hit it with
>>
>> s2 = s/h/ /;
>>
>> , but I can't figure out how to deal with these perl arrays like I'm
>> accustomed to with C or fortran.
> 
> Neither in C nor in Fortran do you access the second element of an array
> named "s" with "s2". In C it's "s[1]" and in Fortran it's "s(2)".  I was
> going to suggest you should read perldoc perldata, but I see in a
> different message that you're reading the Perl bible in church, so I'm
> suggesting you read the chapter about arrays in the camel book instead.
> I'm sure it explains in detail how to access array elements.
> 
> 	hp

Thanks, peter, this puts me back on track.  Perldoc perldata *and* the
camel book were both helpful.  When I'm confused, sometimes the thing I
post is my last and weakest try at doing something.  I did use the correct
$s[2] formulation that one would imagine from a child language of C, but
there was nothing there to look at.

Page 119 of the camel book has a section on looping for folks whose
background is C or Java, and the next page shows the equivalent perl idiom.

The good news is that I am splitting in a predictable, usable way.  The bad
news is that I've got 23 fields instead of the ten that I want:

   use strict;
   use warnings;


   my $filename = 'eph6.txt';
   my $filename2 = 'outfile1.txt';
   open(my $fh, '<', $filename) or die "cannot open $filename: $!";
   open(my $gh, $filename2) or die "cannot open $filename2: $!";

   while (my $line = <$fh>) {
   $line =~ s/\t/   /g;
   $line =~ s/ER/ /g;
   $line =~ s/°/ /g;
   }
   close($fh);

  seek($gh,0,0);

   while (my $line = <$gh>) {

   my @s = split / /, $line;

   for my $i (0..22) {
   print STDOUT  "s $i is $s[$i]\n";
  }
   }
   close($gh);
# perl reg8.pl


C:\MinGW\source> perl reg8.pl
s 0 is Sun
s 1 is
s 2 is
s 3 is 19h
s 4 is 43m
s 5 is 51s
s 6 is
s 7 is
s 8 is -21
s 9 is
s 10 is 17.8'
s 11 is
s 12 is
s 13 is 0.984
s 14 is
s 15 is
s 16 is -35.020
s 17 is
s 18 is
s 19 is 87.148
s 20 is
s 21 is
s 22 is Set
 ...
s 0 is Pluto
s 1 is
s 2 is
s 3 is 18h
s 4 is 6m
s 5 is 40s
s 6 is
s 7 is
s 8 is -17
s 9 is
s 10 is 44.9'
s 11 is
s 12 is
s 13 is 32.485
s 14 is
s 15 is
s 16 is -52.833
s 17 is
s 18 is
s 19 is 108.052
s 20 is
s 21 is
s 22 is Set

C:\MinGW\source>

Can I make a better split to include fields with only digits or characters?
-- 
larry gates

Almost nothing in the design of Perl 6 is there for a single purpose.
    -- Larry Wall in <20050504165510.GB7407@wall.org>


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

Date: Mon, 26 Jan 2009 13:22:10 -0700
From: Larry Gates <larry@example.invalid>
Subject: Re: inputting the ephemerides
Message-Id: <13qnd1bnaizem$.1d5whz1xodhll.dlg@40tude.net>

On Mon, 26 Jan 2009 10:17:06 +0100, Peter J. Holzer wrote:

> On 2009-01-26 00:16, Larry Gates <larry@example.invalid> wrote:
>> I bought a Harbison and Steele from someone off the net, and the
>> s.o.b. sends me a 1985 version, older than K&R 1.
> 
> K&R 1 was published in 1978, IIRC (the German translation is from 1983).
> 
> 	hp

Ok.  I've got the 2te Ausgabe of _Programmerieren in C_ from 1990.  It only
gives dates from the original Ami versions: 1988, 1978.

I do remember that C was very much the hot topic when I was in Germany from
85-87.  I hadn't heard of it in the states.

The H&S from '85 is completely unusable for my purposes.  I've been burning
books based on lack of relevance to C.  That one won't survive the heating
season.
-- 
larry gates

I don't think it's worth washing hogs over.
             -- Larry Wall in <199710060253.TAA09723@wall.org>


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

Date: Mon, 26 Jan 2009 12:35:38 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: inputting the ephemerides
Message-Id: <177sn4h5802ctsbmjln24p33sn3nubker2@4ax.com>

Larry Gates <larry@example.invalid> wrote:
>   while (my $line = <$fh>) {
>   $line =~ s/\t/   /g;
>   $line =~ s/ER/ /g;
>   $line =~ s/°/ /g;
>   }

What is the section above supposed to do?
It reads a line from a file into memory, alters the line, and then
happily throws it away by reading the next line without doing anything
with that altered line. This is a giant NOOP. Why are you doing that?

>  seek($gh,0,0);
>
>   while (my $line = <$gh>) {
>   my @s = split / /, $line;
[...]
>C:\MinGW\source> perl reg8.pl
>s 0 is Sun
>s 1 is
>s 2 is
>s 3 is 19h
>s 4 is 43m
>s 5 is 51s
>s 6 is
>s 7 is

[...]
>Can I make a better split to include fields with only digits or characters?

Apparently your original string contains consecutive sequences of space
characters. Your RE will split between each individual space, thus
creating numerous empty result strings.
If you don't want that then instead of splitting at a single space use
the whole consecutive sequence of space characters as the item to split
the original string at.

jue


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

Date: Mon, 26 Jan 2009 20:37:43 GMT
From: sln@netherlands.com
Subject: Re: inputting the ephemerides
Message-Id: <dk7sn4tg0pbu7l2umnigpmvbnq4bhba6gs@4ax.com>

On Mon, 26 Jan 2009 13:22:10 -0700, Larry Gates <larry@example.invalid> wrote:

>On Mon, 26 Jan 2009 10:17:06 +0100, Peter J. Holzer wrote:
>
>> On 2009-01-26 00:16, Larry Gates <larry@example.invalid> wrote:
>>> I bought a Harbison and Steele from someone off the net, and the
>>> s.o.b. sends me a 1985 version, older than K&R 1.
>> 
>> K&R 1 was published in 1978, IIRC (the German translation is from 1983).
>> 
>> 	hp
>
>Ok.  I've got the 2te Ausgabe of _Programmerieren in C_ from 1990.  It only
>gives dates from the original Ami versions: 1988, 1978.
>
>I do remember that C was very much the hot topic when I was in Germany from
>85-87.  I hadn't heard of it in the states.
>

I used to program in Bcpl (aka B) before C. Was too young to remember A.

sln


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

Date: Mon, 26 Jan 2009 13:03:39 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: inputting the ephemerides
Message-Id: <260120091303392355%jimsgibson@gmail.com>

In article <92rvjd07s127.8n99bu1fdl1v$.dlg@40tude.net>, Larry Gates
<larry@example.invalid> wrote:

> On Mon, 26 Jan 2009 10:13:45 +0100, Peter J. Holzer wrote:
> 
> > On 2009-01-26 00:02, Larry Gates <larry@example.invalid> wrote:
> >>   my @s = split / /, $line;
> > [...]
> >>
> >> So now I want to take the second element of s and hit it with
> >>
> >> s2 = s/h/ /;
> >>
> >> , but I can't figure out how to deal with these perl arrays like I'm
> >> accustomed to with C or fortran.
> > 
> > Neither in C nor in Fortran do you access the second element of an array
> > named "s" with "s2". In C it's "s[1]" and in Fortran it's "s(2)".  I was
> > going to suggest you should read perldoc perldata, but I see in a
> > different message that you're reading the Perl bible in church, so I'm
> > suggesting you read the chapter about arrays in the camel book instead.
> > I'm sure it explains in detail how to access array elements.
> > 
> >   hp
> 
> Thanks, peter, this puts me back on track.  Perldoc perldata *and* the
> camel book were both helpful.  When I'm confused, sometimes the thing I
> post is my last and weakest try at doing something.  I did use the correct
> $s[2] formulation that one would imagine from a child language of C, but
> there was nothing there to look at.
> 
> Page 119 of the camel book has a section on looping for folks whose
> background is C or Java, and the next page shows the equivalent perl idiom.
> 
> The good news is that I am splitting in a predictable, usable way.  The bad
> news is that I've got 23 fields instead of the ten that I want:
> 
>    use strict;
>    use warnings;
> 
> 
>    my $filename = 'eph6.txt';
>    my $filename2 = 'outfile1.txt';
>    open(my $fh, '<', $filename) or die "cannot open $filename: $!";
>    open(my $gh, $filename2) or die "cannot open $filename2: $!";
> 
>    while (my $line = <$fh>) {
>    $line =~ s/\t/   /g;
>    $line =~ s/ER/ /g;
>    $line =~ s/°/ /g;
>    }
>    close($fh);
> 
>   seek($gh,0,0);
> 
>    while (my $line = <$gh>) {
> 
>    my @s = split / /, $line;
> 
>    for my $i (0..22) {
>    print STDOUT  "s $i is $s[$i]\n";
>   }
>    }
>    close($gh);
> # perl reg8.pl

> C:\MinGW\source>
> 
> Can I make a better split to include fields with only digits or characters?

Change your split line to:

  my @s = split ' ', $line;

See 'perldoc -f split:

       As a special case, specifying a PATTERN of space (' ') will
       split on white space just as "split" with no arguments does.
       Thus, "split(' ')" can be used to emulate awk's default
       behavior, whereas "split(/ /)" will give you as many null
       initial fields as there are leading spaces.  A "split" on
       "/\s+/" is like a "split(' ')" except that any leading
       whitespace produces a null first field.  A "split" with no
       arguments really does a "split(' ', $_)" internally.

And

  my @s = split(/\s+/,$line) 

also works in your case, but will give you a leading empty field if
$line begins with spaces.

-- 
Jim Gibson


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

Date: Mon, 26 Jan 2009 13:05:40 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: inputting the ephemerides
Message-Id: <260120091305409642%jimsgibson@gmail.com>

In article <vxt888htljiu.so0hoyxtchkb$.dlg@40tude.net>, Larry Gates
<larry@example.invalid> wrote:


> I've got 2 questions:
> 
> q1) How do I loop over @s and print them out with a delimiter to see if I
> have what I think I have?  One response is, "how many times do we have to
> tell you this?"  I think the answer is at least 3; I can't figure it out
> and have tried serially.

print join(',',@s), "\n";

> 
> q2)  How do I write to $gh and replace thw entire file, even if there are
> fewer characters in the replacer?

Open another file for writing and write the modified lines to that
file. When you are all done, you can rename the new file to the name of
the old file, thereby deleting the old file, or you can just use the
new file instead.

-- 
Jim Gibson


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

Date: Mon, 26 Jan 2009 11:30:27 -0800 (PST)
From: "mcardeiro@yahoo.com" <mcardeiro@yahoo.com>
Subject: problems making zip with Archive::Zip
Message-Id: <dca89042-ac0b-4493-aa39-c130e8889b59@g1g2000pra.googlegroups.com>

Hi,

I am having problems making a simple zip file using Archive::Zip.

I basically want to take some files and make a zip archive that can be
read by windoze.

Heres my code:
     use Archive::Zip qw(:ERROR_CODES :CONSTANTS);

     my $zip = Archive::Zip->new();
     $zip->addFile('/home/eastmail/p.pdf');
     $zip->writeToFileNamed( '/home/eastmail/oBoy.zip' );


when I run the script I get no errors and  file '/home/eastmail/
oBoy.zip'  is created but when I try to open on windows I get an error
that it is not a valid zip.

anybody have experience making zips in perl (the documentation on this
module is not so great).

Mike Cardeiro


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

Date: Mon, 26 Jan 2009 20:57:59 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: problems making zip with Archive::Zip
Message-Id: <497e1581$0$30230$9b4e6d93@newsspool1.arcor-online.net>

mcardeiro@yahoo.com schrieb:
  I am having problems making a simple zip file using Archive::Zip.
> 
> I basically want to take some files and make a zip archive that can be
> read by windoze.
> 
> Heres my code:
>      use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
> 
>      my $zip = Archive::Zip->new();
>      $zip->addFile('/home/eastmail/p.pdf');
>      $zip->writeToFileNamed( '/home/eastmail/oBoy.zip' );
> 
> 
> when I run the script I get no errors and  file '/home/eastmail/
> oBoy.zip'  is created but when I try to open on windows I get an error
> that it is not a valid zip.
> 
> anybody have experience making zips in perl (the documentation on this
> module is not so great).


"when I try to open on windows" is a rather inprecise description,
but I take a stab and guess you are talking of the Windows Explorer
built-in "Zip compressed folder". If that's the case, you are
likely having issues with unix file names and absolute paths.
Try to use relative path names (either as first argument to addFile
or by passing a second, relative name to it) and see if that fixes
your problem.

-Chris


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

Date: Mon, 26 Jan 2009 12:07:36 -0800 (PST)
From: "mcardeiro@yahoo.com" <mcardeiro@yahoo.com>
Subject: Re: problems making zip with Archive::Zip
Message-Id: <befd7530-933a-40c2-a7b7-55a940249c7b@g39g2000pri.googlegroups.com>

On Jan 26, 2:57=A0pm, Christian Winter <thepoet_nos...@arcor.de> wrote:

> "when I try to open on windows" is a rather inprecise description,
> but I take a stab and guess you are talking of the Windows Explorer
> built-in "Zip compressed folder". If that's the case, you are
> likely having issues with unix file names and absolute paths.


You ROCK...I have been agonizing over this off and on for days...thank
you chris!


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

Date: Mon, 26 Jan 2009 20:31:37 GMT
From: sln@netherlands.com
Subject: There is no such thing as Circular Lists (was: FAQ 4.47 How do I handle circular lists?)
Message-Id: <hj6sn49nm0eugiu202hpa0n3n2f6pga87j@4ax.com>

On Mon, 26 Jan 2009 12:03:01 -0800, PerlFAQ Server <brian@stonehenge.com> wrote:

[snip FAQ pre-self cudos]
>
>4.47: How do I handle circular lists?
>
>   
> 
>    (contributed by brian d foy)
>
>    If you want to cycle through an array endlessy, you can increment the
>    index modulo the number of elements in the array:
>
>            my @array = qw( a b c );
>            my $i = 0;
>
>            while( 1 ) {
>                    print $array[ $i++ % @array ], "\n";
>                    last if $i > 20;
>                    }
>
This is total dog foaming at the mouth drivel !!!
Is MODULO the key to ring-buffers ?  Don't make me laff !

>    You can also use "Tie::Cycle" to use a scalar that always has the next
>    element of the circular array:
>
>            use Tie::Cycle;
>
>            tie my $cycle, 'Tie::Cycle', [ qw( FFFFFF 000000 FFFF00 ) ];
>
>            print $cycle; # FFFFFF
>            print $cycle; # 000000
>            print $cycle; # FFFF00
>
More drivel !  There is no Circular List Neo, there is no Circular list !!

>    The "Array::Iterator::Circular" creates an iterator object for circular
>    arrays:
>
>            use Array::Iterator::Circular;
>
>            my $color_iterator = Array::Iterator::Circular->new(
>                    qw(red green blue orange)
>                    );
>
>            foreach ( 1 .. 20 ) {
>                    print $color_iterator->next, "\n";
>                    }
>
>
>

[snip FAQ post-self cudos]

There is no such thing as 'Circular Lists', just as there is no such thing as
'Circular Stacks'.

There are lists, stacks, arrays, elements, nodes, linked-lists...
But there is no such thing as a 'Circular List'.

There is something called a 'Ring Buffer', a fixed buffer that has a head and a tail,
not to be confused with an expanding stack or linked-list.

At least get your head out of your ass FAQ workers.

sln





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

Date: Mon, 26 Jan 2009 13:28:22 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: tracking scope of a variable?
Message-Id: <XJidnVHSJZbqJ-DUnZ2dnUVZ8tLinZ2d@posted.plusnet>

I'm presently having a "bit of an issue" with a variable,
which is declared, and exported in various interesting ways.

While I have no doubt I will eventually find the problem
and fix it, and even understand the fix, I would like to ask:

Is there a way to print out all the declarations
and references to a variable?

In particular I would like a routine to
dump all declarations of a named variable e.g. "flooble".

I would ideally like to see a list, including
all block scoped variable called "flooble", and
all module scoped variable (A::flooble, B::flooble).

Further, when I use a variable
($flooble = "test", or print "$flooble") I would
like to see a list of all the declarations
that this variable has (often multiple, due to exports).

My apologies for the vaguness and errors in this request,
but if I knew enough to write this up really
well, I probably wouldn't need to :-)

   BugBear


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

Date: Mon, 26 Jan 2009 19:06:46 GMT
From: sln@netherlands.com
Subject: Update for difference of two arrays (was:  FAQ 4.43 How do I compute the difference of two arrays?  How do I compute the intersection of two arrays?)
Message-Id: <m11sn4l1v1bnfqc71unn6l9asjoi8f12jp@4ax.com>

On Mon, 26 Jan 2009 00:03:02 -0800, PerlFAQ Server <brian@stonehenge.com> wrote:

>This is an excerpt from the latest version perlfaq4.pod, which
>comes with the standard Perl distribution. These postings aim to 
>reduce the number of repeated questions as well as allow the community
>to review and update the answers. The latest version of the complete
>perlfaq is at http://faq.perl.org .
>
>--------------------------------------------------------------------
>
>4.43: How do I compute the difference of two arrays?  How do I compute the intersection of two arrays?
>
>    Use a hash. Here's code to do both and more. It assumes that each
>    element is unique in a given array:
^^^
Of course it assumes each element is unique in a given array. I breaks if its not (ie: dups).

>
>            @union = @intersection = @difference = ();
>            %count = ();
>            foreach $element (@array1, @array2) { $count{$element}++ }
>            foreach $element (keys %count) {
>                    push @union, $element;
>                    push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element;
>                    }
>
>    Note that this is the *symmetric difference*, that is, all elements in
>    either A or in B but not in both. Think of it as an xor operation.
>
^^^
What in the hell does this mean?

I'm so tired of seeing this flawwed logic. Can't we just fix this once and for all
FAQ workers ???

This is the real solution, read carefully:

------------------------------------------------------
@union = @intersection = @difference = ();
%count = ();
foreach $element (@array1) { $count{$element} = 1 }
foreach $element (@array2) { $count{$element} |= 2 }
foreach $element (keys %count) {
     push @union, $element;
     push @{ $count{$element} == 3 ? \@intersection : \@difference }, $element;
}
-------------------------------------------------------

This fixes the "unique element" major, major drawback. Imagine the assumption that
there are no duplicates in an array ? What the hell is that ???

The bitwise OR is just as fast as increment. If its one extra assembly step,
so what ?  It mitigates in-array dup's.

The other fallicy in this FAQ is the @difference array. Different than what
exactly ?  Each other ?  What the hell does that tell you ???  Nothing !!!

The proof is below. I challenge anybody to make the argument for this standing
FAQ -> NOT TO BE CHANGED/FIXED once and for all !!!

sln

---------------------------------------------------------
use strict;
use warnings;

my @array1 = (1,3,3,1,5,5,7,9,100,200,300,100);
my @array2 = (0,2,4,6,2,6,0,8,100,200,300);

my ($element,%count,@union,@intersection,@difference);

@union = @intersection = @difference = ();
foreach $element (@array1) { $count{$element} = 1 }
foreach $element (@array2) { $count{$element} |= 2 }
foreach $element (keys %count) {
     push @union, $element;
     push @{ $count{$element} == 3 ? \@intersection : \@difference }, $element;
}

@union        = sort {$a<=>$b} @union;
@intersection = sort {$a<=>$b} @intersection;
@difference   = sort {$a<=>$b} @difference;

print "\n";
print "Array1       = @array1\n";
print "Array2       = @array2\n";
print "union        = @union\n";
print "intersection = @intersection\n";
print "difference   = @difference\n";

__END__

Output:
c:\temp>perl jjj.pl

Array1       = 1 3 3 1 5 5 7 9 100 200 300 100
Array2       = 0 2 4 6 2 6 0 8 100 200 300
union        = 0 1 2 3 4 5 6 7 8 9 100 200 300
intersection = 100 200 300
difference   = 0 1 2 3 4 5 6 7 8 9

c:\temp>





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

Date: Mon, 26 Jan 2009 20:11:45 +0100
From: mysiar <psynowiec@WYTNIJTOop.pl>
Subject: Vista x64 + DBD::Pg driver
Message-Id: <gll1th$htm$1@news.onet.pl>

Hi
does anybody have this driver working ?
If so could share "prescription" how to run it ?

Regards
Piotr


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

Date: Mon, 26 Jan 2009 14:03:03 +0100
From: Rasmus Villemoes <burner+usenet@imf.au.dk>
Subject: Which is faster - hash or array lookup
Message-Id: <u0lpria6wzc.fsf@orc04.imf.au.dk>

Hi

In a program I'm writing, I will need to access the 53130 different
5-element subsets of 0..24 many many times. So I thought I would
generate each of these subsets once and for all, using a canonical
enumeration scheme, and save the result in a global hash or array
(Concretely, I have generated a file containing lines of the form
"0:0,1,2,3,4", "1:0,1,2,3,5" etc., which I then read and parse at the
start of the program, that is, I generate an anonymous array
[0,1,2,3,4], and then I store a reference to this in $combs{0} or
$combs[0].)

Now the question is, should I store these in an array or a hash,
if I want to access a random entry as fast as possible? 

-- 
Rasmus Villemoes
<http://rasmusvillemoes.dk/>


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

Date: Mon, 26 Jan 2009 14:05:36 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Which is faster - hash or array lookup
Message-Id: <hLmdnVcfe72tXuDUnZ2dnUVZ8jKdnZ2d@posted.plusnet>

Rasmus Villemoes wrote:
> Hi
> 
> In a program I'm writing, I will need to access the 53130 different
> 5-element subsets of 0..24 many many times. 

Are you sure there isn't a better algorithm for your
(unstated) purpose?

   BugBear


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

Date: 26 Jan 2009 14:08:13 GMT
From: Leon Timmermans <fawaka@gmail.com>
Subject: Re: Which is faster - hash or array lookup
Message-Id: <497dc3cd$0$193$e4fe514c@news.xs4all.nl>

On Mon, 26 Jan 2009 14:03:03 +0100, Rasmus Villemoes wrote:

> Now the question is, should I store these in an array or a hash, if I
> want to access a random entry as fast as possible?

Arrays are the simpler datastructure and thus faster. The question is a 
bit odd though: you should just use what makes most sense (a hash indexed 
by hashes usually doesn't make sense).

Regards,

Leon Timmermans


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

Date: Mon, 26 Jan 2009 16:02:15 +0100
From: Rasmus Villemoes <burner+usenet@imf.au.dk>
Subject: Re: Which is faster - hash or array lookup
Message-Id: <u0lab9e6rgo.fsf@orc04.imf.au.dk>

bugbear <bugbear@trim_papermule.co.uk_trim> writes:

> Rasmus Villemoes wrote:
>> Hi
>> In a program I'm writing, I will need to access the 53130 different
>> 5-element subsets of 0..24 many many times.
>
> Are you sure there isn't a better algorithm for your (unstated)
> purpose?

Well, that depends. I am suite sure that perl is not The Right Tool
for my overall purpose, but what I am trying to do probably does
involve accessing each of these combinations by number (or some other
key). I have decided to use perl for this pet project to help me learn
some more perl.

The project concerns a little game which is played on a 5x5
board. Each player has 5 pieces, and additionally there is a common
piece used by both players. Only one piece can occupy a square at any
time, so the positions of either player's pieces at any time is
exactly a 5-subset of 0..24. If I use a canonical numbering of these
5-subsets, I can describe the state of the game using 5 bytes (2*2
bytes to describe numbers in the range 0..53129, and 1 byte to
indicate the position of the common piece along with information on
whose turn it is). For any given state, a move from that state can be
described by 3 bytes (encoding the new positions of the player's
pieces and the common piece). But in order to compute which moves are
possible from a given state, I need the positions of the 11 pieces on
the board. It may not be smart to store anonymous arrays containing
the 5-subsets. Another possibility is to use a bitstring with exactly
5 1's. That would probably save a lot of memory, and may be faster to
use (I will often need to ask "in state $x, is there a piece on square
number $n". I guess vec() can answer that question if I use
bitstrings, whereas traversing an array looking for $n is slow).

Of course, I could skip the huge constant table, but then I would
either have to describe each state using more data, or compute the
occupied/empty squares each time.

-- 
Rasmus Villemoes
<http://rasmusvillemoes.dk/>


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

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


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