[19515] in Perl-Users-Digest
Perl-Users Digest, Issue: 1710 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 7 14:05:39 2001
Date: Fri, 7 Sep 2001 11:05:09 -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: <999885909-v10-i1710@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 7 Sep 2001 Volume: 10 Number: 1710
Today's topics:
Re: [OT]++ Attribution of Past Postings <lmoran@wtsg.com>
Re: \n doesn't translate to %0A with s/(.)/uc(sprintf(" <mjcarman@home.com>
Re: ActivePerl says Out of Memory, but I'm not out of m (Jonadab the Unsightly One)
Re: ActivePerl says Out of Memory, but I'm not out of m (Jonadab the Unsightly One)
Re: AoH - sorry for the no subj <davidhilseenews@yahoo.com>
Re: Baiting Gozilla to obtain quality code for nothing! <peb@bms.umist.ac.uk>
Bugs in perl / perltootc? <marius@kjeldahl.net>
Re: Bugs in perl / perltootc? <joe+usenet@sunstarsys.com>
Re: Bugs in perl / perltootc? <tinamue@zedat.fu-berlin.de>
data structure to solve this puzzle..as it's Friday aft (mbower)
errorlevel > 255 possible? <Marius.Schaefer@bpanet.de>
Re: errorlevel > 255 possible? (Malcolm Dew-Jones)
Re: Generating a 'reversable' code... <dtweed@acm.org>
Re: Generating a 'reversable' code... <joe+usenet@sunstarsys.com>
Re: Generating a 'reversable' code... <dtweed@acm.org>
Getting DBD::CSV to write the collumn names as first li (Stan Brown)
Re: Getting DBD::CSV to write the collumn names as firs <jeff@vpservices.com>
Re: Getting DBD::CSV to write the collumn names as firs <jeff@vpservices.com>
Re: Getting DBD::CSV to write the collumn names as firs (Stan Brown)
Re: Godzilla Stomps Code Red <fty@mediapulse.com>
Re: HASH question <mjcarman@home.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 07 Sep 2001 13:22:33 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: [OT]++ Attribution of Past Postings
Message-Id: <l9vhpto0f602pdhdjancftn6jc9c7rl4v3@4ax.com>
On Thu, 30 Aug 2001 23:36:06 -0700, "Godzilla!"
<godzilla@stomp.stomp.tokyo> wrote wonderful things about sparkplugs:
>Joe Kline wrote:
SNIP
>Nervous about being labeled this vile racist you are, Frank?
>
FAQ writers we need a section on who the bleep Frank is!
>
>Godzilla!
------------------------------
Date: Fri, 07 Sep 2001 07:49:47 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: \n doesn't translate to %0A with s/(.)/uc(sprintf("%%%02x", ord($1)))/eg ?
Message-Id: <3B98C26B.D1DFE203@home.com>
Gildas PERROT wrote:
>
> I don't understand why "\r" is correctly translated to 0D and
> not "\n" to 0A.
> Here is my code :
>
> $texte = "BEGIN\r\n";
> $texte =~ s/(.)/uc(sprintf("%%%02x", ord($1)))/eg;
> print $texte;
>
> I have :
>
> %42%45%47%49%4E%0D
Because '.' doesn't match "\n". Add the /s option to your s/// to change
this. cf. the perlre manpage.
On a side note; remember that "\n" is somewhat magical. It's underlying
value (fo I/O) changes depending on your platform.
-mjc
------------------------------
Date: Fri, 07 Sep 2001 14:25:03 GMT
From: jonadab@bright.net (Jonadab the Unsightly One)
Subject: Re: ActivePerl says Out of Memory, but I'm not out of memory? Is this a limitation in the Perl build I have?
Message-Id: <3b98d5f4.83385535@news.bright.net>
Bob Walton <bwalton@rochester.rr.com> wrote:
> I fixed a couple of bugs in your program, and it now prints out "No
> solution found!" in about 1 second. The bug fixes were:
> Looks like the big one was in line 50 where you forgot to local
> $origloc.
Ah, yes. I forgot that local binds more tightly than a comma.
> Also, the winning string had a typo, which could be major. I
> changed all the local's to my's, but that probably doesn't matter much.
That does matter. If you changed every local to my,
some of the functions (trytoplay() and canplay() at
least) won't be able to function as intended. Unless
I badly misunderstand how my works.
I made $origloc, %stack, %cell, and %build local, and
that solved my memory problem. There are still bugs,
but I'll work on those.
- jonadab
------------------------------
Date: Fri, 07 Sep 2001 14:41:28 GMT
From: jonadab@bright.net (Jonadab the Unsightly One)
Subject: Re: ActivePerl says Out of Memory, but I'm not out of memory? Is this a limitation in the Perl build I have?
Message-Id: <3b98d01a.81886851@news.bright.net>
Michael Carman <mjcarman@home.com> wrote:
> Well, okay, but "post a short piece of code" doesn't mean "shorten by
> squeezing out all the whitespace." :)
No, no, I also removed all the generalities (like the
function that reads in a position from a file) and the
niceties (like the code that nicens up the solution
before printing it).
> > What it's doing is working out a solution to a FreeCell
> > position, by brute force of trying every possible move,
> > recursively.
>
> Ah. Are you trying to prove the belief that every game
> can be won? (via brute force, no less).
No. If I were trying to do that I'd produce a version
that lets users play the game and posts an identifier
for each game they successfully complete to a central
server or to a group someplace on usenet, monitoring
that server or group and trying to select games that
haven't been played yet. I'd sell[1] this version to
users by adding additional features, like the ability
to undo repeatedly. But I'm not interested in doing
that; if I wanted to prove or disprove the notion
that all positions are solveable, I'd probably try
to use mathematical induction.
The reason I wrote this thing is, my dad is for reasons
that are incomprehensible to me enthralled with FreeCell,
and he found a specific position that he thought surely
must be unbeatable, so he asked me to find a solution.
I had absolutely no interest in doing so myself, but
I figured getting a computer to do it would be a more
interesting exercise.
Since then, my dad solved the position in question
himself. But I figure he's going to come to me with
another one eventually. He's convinced that it
*can't* be possible to solve every position, and
further he's convinced that he's going to find
the unsolveable one. And no argument from math
is going to convince him of anything, one way or
another.
> Anyway, there are a helluva lot of permutations for
> playing out a game of Freecell.
Yes, I know that.
> What do you do when you follow a path to a dead end? As
> near as I can tell, $moves only grows.
If I have the code right, $moves should only grow
within one legal sequence of moves -- it should revert
to a previous state when a path fails and ceases to
recurse.
> > I come from a lisp background, so I was using local instead.
> > (I associate lexical scoping with C++ and other forms of evil.)
> > However, now that you mention it...
>
> Scoping is your friend. It may not save memory, but it
> makes programming much easier.
Maybe I don't understand my; my impression was that it
did C-style lexical scoping -- i.e., if foo() has a my
variable and calls bar(), bar() doesn't see the same
value that foo() sees. That would be bad; the whole
algorithm wouldn't work then, or I'd have to pass a
lot more parameters, or convert everything to one big
function. What I want lisp-style scoping, where every
function sees the dynamically scoped value set by foo()
until that iteration of foo() exits, at which point it
should revert to the previous value -- I was under the
impression that this is what local is for. That's my
understanding of what the 2nd ed. camel book says, for
example, in the glossary under "scope". But everyone
seems to be steering me in the other direction -- have
I totally misunderstood how my and local work?
> You're using all globals, and the param list you pass to workform() is
> matches what you unpack it into. All you're doing is copying stuff onto
> itself...
Ah, %stack should be local too, and %cell, and %build.
Why didn't I see that?...
Together with $origloc (other subthread), that cares
for my memory problem. The script is finishing now,
so I should be able to go back to debugging it in
the usual way.
Thanks, everyone!
[1] Convince them to use it, that is.
- jonadab
------------------------------
Date: Mon, 03 Sep 2001 04:17:02 GMT
From: "David Hilsee" <davidhilseenews@yahoo.com>
Subject: Re: AoH - sorry for the no subj
Message-Id: <2vDk7.58823$hT4.14381442@news1.rdc1.md.home.com>
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3B92F632.BFBA1755@stomp.stomp.tokyo...
> TuNNe|ing wrote:
>
> (snipped)
>
> I have elected to not comment on your code.
>
> > Tad, I always "use strict;" during development.
>
> Work towards an ability to write Perl programs
> without using strict. This will lead to your
> being a better programmer and will lead to an
> ability to write significantly more efficient
> scripts. Use of strict is mostly ok save for
> forcing you to write slower less efficient code,
> but it can become a very serious crutch, a right
> crutch with warnings being a left crutch.
>
> > Thanks for the _DATA_ idea.
>
> Use of _DATA_ works well if you know how to
> use this format correctly.
>
> However, there is a very serious problem with
> using this _DATA_ format no Perl 5 Cargo Cultists
> will mention; this would be sacrilege to mention
> any negative aspects of Perl 5 Cargo Cult Dogma.
>
> There have been times I have been yelled at by
> regulars here for not using _DATA_ in my test
> scripts when it should be obvious to them what
> will happen if used. These are times I do not
> use _DATA_ for a good reason, a good reason
> about which, most here have no clue.
>
> Give my test script a whirl.
>
>
> Godzilla! Queen Of Perl Heretics.
> --
>
> #!perl
>
> while (<DATA>)
> { print "\n\n$_\n\n"; }
>
> seek (DATA, 0, 0);
>
> while (<DATA>)
> { print $_; }
>
> __DATA__
> Godzilla Rocks And Rolls!
If you wanted to still use __DATA__, then why not
my $start = tell(DATA);
while (<DATA>) { print; }
print "*****************\n"
seek DATA, $start, 0;
while (<DATA>) { print; }
Of course, I tend to avoid DATA when seeking as well, but this is another
approach.
David Hilsee
------------------------------
Date: Fri, 07 Sep 2001 16:12:40 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Baiting Gozilla to obtain quality code for nothing!!
Message-Id: <3B98E3E8.45563C8B@bms.umist.ac.uk>
Helgi Briem wrote:
>
> On Thu, 06 Sep 2001 14:12:52 +0100, Paul Boardman
> <peb@bms.umist.ac.uk> wrote:
>
> >Matt Garrish wrote:
> >
> >> And all this time I thought he was Don King's hideous love child...
> >
> >What's all this 'he' business. If you'd all been reading as many of
> >Kiras posts as you imply I would have thought it obvious that *he* is a
> >*she*.
> >Godzilla! Queen Of Decimalatia.
>
> Lot's of guys call themselves "Queens".
I like that explanation. It might explain a few things...
Paul
------------------------------
Date: Fri, 07 Sep 2001 15:28:04 +0200
From: Marius Kjeldahl <marius@kjeldahl.net>
Subject: Bugs in perl / perltootc?
Message-Id: <3B98CB64.5040603@kjeldahl.net>
I've tried to use inheritence as described in Tom Christiansen tutorial
perltootc, but have come up short.
I am using the method described in perltootc (with code) where he talks
about:
"Not only are we now strict refs clean, using an eponymous
meta-object seems to make the code cleaner."
Using the same setup, I have an example which demonstrate the (to me)
unexpected behaviour:
I have a Super class (Super), with one subclass (Sub), where I store
some class data in each module. In the superclass it seems the data for
some reason is not defined.
I am expecting the following output:
class: Super
$VAR1 = bless( {
'SomeData' => \'abc'
}, 'Super' );
class: Sub
$VAR1 = bless( {
'SomeData' => \'def'
}, 'Sub' );
but I am getting:
class: Super
$VAR1 = bless( {
'SomeData' => \'abc'
}, 'Super' );
class: Sub
$VAR1 = bless( {
'SomeData' => \undef
}, 'Sub' );
I've attached the three source files below. Any help would be appreciated.
Thanks,
Marius K.
======Super.pm ==============
package Super;
use strict;
use warnings;
our %Super = (
SomeData => 'abc'
);
sub _classobj {
my $self = shift;
my $class = ref($self) || $self;
print STDERR "class: $class\n";
no strict "refs";
# get (hard) ref to eponymous meta-object
return \%$class;
}
sub new {
my $obclass = shift;
my $classobj = $obclass->_classobj();
bless my $self = {
SomeData => \$classobj->{SomeData}
} => (ref $obclass || $obclass);
return $self;
}
sub SomeData {
my $self = shift;
$self = $self->_classobj() unless ref $self;
my $dataref = $self->{SomeData};
$$dataref = shift if @_;
return $$dataref;
}
1;
======Sub.pm ==============
package Sub;
use Super;
@ISA = qw (Super);
use strict;
use warnings;
our %Sub = (
SomeData => 'def'
);
1;
====== main ==========
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Super;
use Sub;
my $test1 = Super::->new;
print STDERR Dumper ($test1);
my $test2 = Sub::->new;
print STDERR Dumper ($test2);
------------------------------
Date: 07 Sep 2001 11:09:03 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Bugs in perl / perltootc?
Message-Id: <m31yljghrk.fsf@mumonkan.sunstarsys.com>
Marius Kjeldahl <marius@kjeldahl.net> writes:
> I am expecting the following output:
>
> class: Super
> $VAR1 = bless( {
> 'SomeData' => \'abc'
> }, 'Super' );
> class: Sub
> $VAR1 = bless( {
> 'SomeData' => \'def'
> }, 'Sub' );
>
> but I am getting:
>
> class: Super
> $VAR1 = bless( {
> 'SomeData' => \'abc'
> }, 'Super' );
> class: Sub
> $VAR1 = bless( {
> 'SomeData' => \undef
> }, 'Sub' );
[...]
> sub _classobj {
> my $self = shift;
> my $class = ref($self) || $self;
> print STDERR "class: $class\n";
> no strict "refs";
> # get (hard) ref to eponymous meta-object
> return \%$class;
^^^^^^^^^^^^^^^
I don't know if this helps, but replacing that with:
return \% {$class . '::' . $class};
Personally, I don't care much for the approach to Class data TomC
is advancing in perltootc, but I might be in the minority there.
I'd rather write something like
{
my %foo = ( data => 1 );
sub class_data { \%foo }
}
and let subclasses override class_data() as they see fit. (although
technically I'm not sure whether or not that's legal Perl, it seems
to work ok, and is a documented idiom for creating "static" variables-
see perlsub's "Persistent Private Variables" for details).
--
Joe Schaefer "It is unbecoming for young men to utter maxims."
-- Aristotle
------------------------------
Date: 7 Sep 2001 15:09:55 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Bugs in perl / perltootc?
Message-Id: <9nao03$6bas5$2@fu-berlin.de>
Marius Kjeldahl <marius@kjeldahl.net> wrote:
> I've tried to use inheritence as described in Tom Christiansen tutorial
> perltootc, but have come up short.
> I am using the method described in perltootc (with code) where he talks
> about:
> "Not only are we now strict refs clean, using an eponymous
> meta-object seems to make the code cleaner."
> Using the same setup, I have an example which demonstrate the (to me)
> unexpected behaviour:
> I have a Super class (Super), with one subclass (Sub), where I store
> some class data in each module. In the superclass it seems the data for
> some reason is not defined.
[...]
> but I am getting:
> class: Super
> $VAR1 = bless( {
> 'SomeData' => \'abc'
> }, 'Super' );
> class: Sub
> $VAR1 = bless( {
> 'SomeData' => \undef
> }, 'Sub' );
> I've attached the three source files below. Any help would be appreciated.
> Thanks,
> Marius K.
> ======Super.pm ==============
> package Super;
> use strict;
> use warnings;
> our %Super = (
> SomeData => 'abc'
> );
> sub _classobj {
> my $self = shift;
> my $class = ref($self) || $self;
> print STDERR "class: $class\n";
> no strict "refs";
$class is "Super" or "Sub".
> # get (hard) ref to eponymous meta-object
> return \%$class;
you are trying to get %Super or %Sub. but %Sub is
not defined, because you're in the package Super.
try this:
$class = $class."::".$class;
return \%$class;
hth,
tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Fri, 07 Sep 2001 14:41:25 GMT
From: mbower@ibuk.bankgesellschaft.de (mbower)
Subject: data structure to solve this puzzle..as it's Friday afternoon !
Message-Id: <3b98dbfe.12501031@news>
Isaw this puzzle on a beer mat, and wondered how best to code + solve
this in Perl ?
I did it in VBA in no time, but trying to represent the pyramid is
confusing me...any ideas ?
The sum of each two adjacent squares gives the number above. Fill in
the blanks ....
i.e the numbers below 400, could be 200 +200 or 0 + 200 etc.......
400
xx xx
80 xx 120
xx xx xx xx
20 xx xx xx 40
------------------------------
Date: Fri, 07 Sep 2001 18:39:40 +0200
From: Marius =?iso-8859-1?Q?Sch=E4fer?= <Marius.Schaefer@bpanet.de>
Subject: errorlevel > 255 possible?
Message-Id: <3B98F84C.D6D4A77F@bpanet.de>
Hi,
is there a way to set an errorlevel > than 255 when exiting a script?
exit(500); # does not work of course :(
Thanks,
Marius
------------------------------
Date: 7 Sep 2001 10:44:22 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: errorlevel > 255 possible?
Message-Id: <3b990776@news.victoria.tc.ca>
Marius =?iso-8859-1?Q?Sch=E4fer?= (Marius.Schaefer@bpanet.de) wrote:
: Hi,
: is there a way to set an errorlevel > than 255 when exiting a script?
: exit(500); # does not work of course :(
On unix, child exit status is passed back in a fixed size, and one byte
(eight bits) is allocated to hold the exit status, (I forget what the rest
is for right now).
That's the reason for the limit. If you examine the meaning of the rest
of the returned data then there may be some way to force it to have
certain values, effectively allowing you to set more than 255 return
values, but that would be very kludgey, and sure to break somewhere along
the line.
Other systems do not have the same limits (they have different limits).
E.g. on VMS you get to return 4 bytes of data as the exit status, (minus
two bits which must/should correctly categorize the result type).
------------------------------
Date: Fri, 07 Sep 2001 13:06:16 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: Generating a 'reversable' code...
Message-Id: <3B98C4FA.3DC62F3F@acm.org>
Imran wrote:
> I want to take a number and generate a string (of like maybe 8 or 10
> characters... it could vary, but shouldn't get too big, i guess). and
> then in reverse, i want to be able to specify the string and generate
> the number back. And a given number or string would always generate
> the same result (back or forth).
>
> (basically trying to hide a numeric value from the user) There
> probably is a simple solution involving pack/unpack. but reading
> couple of books (Prog Perl, Perl Cook), i just can't seem to grasp the
> function.
The uuencode format in pack/unpack should do what you want. If you're
going to be passing this around in URIs, however, you might want something
that needs less escaping, like base64. Try this:
$number = 987654321;
print " Number: $number\n";
$code = pack ('u', $number);
print "uuencode: $code\n";
$code =~ tr| -_|A-Za-z0-9+/|; # convert to pseudo-base64 format
print " base64: $code\n";
$code =~ tr|A-Za-z0-9+/| -_|; # convert back to uuencoded format
print "uuencode: $code\n";
$newnum = unpack ('u', $code);
print " Newnum: $newnum\n";
-- Dave Tweed
------------------------------
Date: 07 Sep 2001 09:14:03 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Generating a 'reversable' code...
Message-Id: <m366avgn38.fsf@mumonkan.sunstarsys.com>
Imran <junkmail@nawebspam.com> writes:
> I want to take a number and generate a string (of like maybe 8 or 10
> characters... it could vary, but shouldn't get too big, i guess). and
> then in reverse, i want to be able to specify the string and generate
> the number back. And a given number or string would always generate
> the same result (back or forth).
>
> (basically trying to hide a numeric value from the user) There
> probably is a simple solution involving pack/unpack. but reading
> couple of books (Prog Perl, Perl Cook), i just can't seem to grasp the
> function.
You could try pack/unpack with the "u" template, but that's not a very
secure way to do it. If you want to ensure that the user can't
decipher the number from the string, take a look at the Crypt::*
modules on CPAN. ISTR a recent article on www.perl.com that discusses
symmetric cryptography with Perl- you might take a look at that as well.
--
Joe Schaefer "Everything that can be invented has been invented."
-- Charles H. Duell
------------------------------
Date: Fri, 07 Sep 2001 14:16:26 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: Generating a 'reversable' code...
Message-Id: <3B98D59E.CEAED61D@acm.org>
Imran wrote:
> Ooops, i forgot to say, that the string looks like random text, and
> the string made up of [a-zA-Z0-9]
OK, if you're going to insist on base62 instead of base64, then you
need something like this. Note that I'm assuming your numbers are
integers.
sub encode {
my @codes;
for my $n (@_) {
my @temp;
do {
push @temp, $n % 62;
$n = int ($n/62);
} while ($n);
my $code = pack ('C*', @temp);
$code =~ tr/\000-\075/a-zA-Z0-9/;
push @codes, $code;
}
@codes;
}
sub decode {
my @numbers;
for my $code (@_) {
$code =~ tr/a-zA-Z0-9/\000-\075/;
my @temp = reverse unpack ('C*', $code);
my $n = shift @temp;
for (@temp) {
$n = $n*62 + $_;
}
push @numbers, $n;
}
@numbers;
}
@nums = (0, 1, 62, 123456789, 987654321);
print join (', ', @nums), "\n";
@nums = encode (@nums);
print join (', ', @nums), "\n";
@nums = decode (@nums);
print join (', ', @nums), "\n";
If you want to obfuscate the strings a bit more than this, try XORing each
number with a large constant before encoding and after decoding.
-- Dave Tweed
------------------------------
Date: 7 Sep 2001 09:33:42 -0400
From: stanb@panix.com (Stan Brown)
Subject: Getting DBD::CSV to write the collumn names as first line of file
Message-Id: <9naibm$mhf$1@panix2.panix.com>
This is starnge. I grabed some example code from a previous script to
write a CSV file. I remember having a bit of fun getting DBD::CSV to _not_
write teh collumn names as the first line of that fiel.
Now I _want_ it to and it's not :-(
Here is what I am doing:
# All of this is for using the CSV module to write the output file
$dbho = DBI->connect("DBI:CSV:f_dir=$save_dir;",
, "csv_sep_char=,;csv_quote_char=;,csv_escape_char=;"
, "csv_eol=")
or die "Unable to connect: $DBI::errstr";
# Set CSV values the way Chris likes them
$dbho->{'csv_tables'}->{$save_filename} = {
'eol' => "\n",
'sep_char' => "\;",
'quote_char' => "\"",
'escape_char' => "\"",
'skip_first_row' => 0,
'col_names' => \@col_names };
$stho = $dbho->prepare("$insert_string");
foreach (@$records_array_ref)
{
$stho->execute ( @{$records_array_ref->[$i++]} );
}
But still no first row. What am I doing wrong here?
------------------------------
Date: Fri, 07 Sep 2001 08:41:48 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Getting DBD::CSV to write the collumn names as first line of file
Message-Id: <3B98EABC.AFA94E95@vpservices.com>
Stan Brown wrote:
>
> This is starnge. I grabed some example code from a previous script to
> write a CSV file. I remember having a bit of fun getting DBD::CSV to _not_
> write teh collumn names as the first line of that fiel.
>
> Now I _want_ it to and it's not :-(
>
> Here is what I am doing:
>
> # All of this is for using the CSV module to write the output file
> $dbho = DBI->connect("DBI:CSV:f_dir=$save_dir;",
...
> $dbho->{'csv_tables'}->{$save_filename} = {
...
> $stho = $dbho->prepare("$insert_string");
...
> foreach (@$records_array_ref)
> {
> $stho->execute ( @{$records_array_ref->[$i++]} );
> }
...
>
> But still no first row. What am I doing wrong here?
You haven't shown us any of the relevant code. The code that is
relevant is the code used to create the file in the first place. The
column names on the first line get put there when the file is created
(e.g. with a SQL CREATE statement), not when rows are inserted. If your
"skip_first_row" wasn't set to 0 when the file was created, setting it
to 0 later will make no difference.
--
Jeff
------------------------------
Date: Fri, 07 Sep 2001 08:54:53 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Getting DBD::CSV to write the collumn names as first line of file
Message-Id: <3B98EDCD.26E520FA@vpservices.com>
Stan Brown wrote:
>
> 'skip_first_row' => 0,
> 'col_names' => \@col_names };
In addition to my previous comment about the relevant code being the
code used to create the file, you have told your script here *twice* not
to use the first row as column names: 1) if you want the first row to
be a list of column names, then skip_first_row should be 1 (i.e. it will
skip the first row when it looks for data since it knows that the first
row is a list of column names, not a data row) so by telling it to set
skip_first_row to 0 you are telling it there are no column names on the
first row and 2) by supplying a list of column names you are again
telling the script not to look on the first row for column names since,
as the docs explicitly state:
you can supply an array ref of table names with the col_names
attribute.
In that case the attribute skip_first_row will be set to FALSE.
So you've set skip_first_row to FALSE twice in your script and that is
exactly the opposite of what you say you want.
--
Jeff
------------------------------
Date: 7 Sep 2001 12:34:52 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: Getting DBD::CSV to write the collumn names as first line of file
Message-Id: <9nasvc$seg$1@panix3.panix.com>
In <3B98EDCD.26E520FA@vpservices.com> Jeff Zucker <jeff@vpservices.com> writes:
>Stan Brown wrote:
>>
>> 'skip_first_row' => 0,
>> 'col_names' => \@col_names };
>In addition to my previous comment about the relevant code being the
>code used to create the file, you have told your script here *twice* not
>to use the first row as column names: 1) if you want the first row to
>be a list of column names, then skip_first_row should be 1 (i.e. it will
>skip the first row when it looks for data since it knows that the first
>row is a list of column names, not a data row) so by telling it to set
>skip_first_row to 0 you are telling it there are no column names on the
>first row and 2) by supplying a list of column names you are again
>telling the script not to look on the first row for column names since,
>as the docs explicitly state:
> you can supply an array ref of table names with the col_names
>attribute.
> In that case the attribute skip_first_row will be set to FALSE.
>So you've set skip_first_row to FALSE twice in your script and that is
>exactly the opposite of what you say you want.
OK, I think you hit the problem with the first reply..
Thnaks.
------------------------------
Date: Fri, 07 Sep 2001 18:02:45 GMT
From: "Jay Flaherty" <fty@mediapulse.com>
Subject: Re: Godzilla Stomps Code Red
Message-Id: <9Z7m7.236451$NK1.21631791@bin3.nnrp.aus1.giganews.com>
"Richard A. Evans" <EvR@compuserve.com> wrote in message
news:9mmojq$f2b$1@suaar1aa.prod.compuserve.com...
> From previous email:
>
> > It is true my abilities to research and read, my ingenious
> > Perl programming skills, my talents at writing efficient
> >and imaginative Perl scripts, are a serious threat to these
> > fragile masculine egos of weak-kneed men populating this
> > newsgroup and, adequately devastate this diseased ego of
> > The CLPM Troll.
>
> And from another:
>
> > What I think is of importance. What I think is I am moderately
> > perturbed by your second incident of slinging racial slurs at
> > me. Your first incident being a well remember one, an incident
> > so abhorrent and morally repugnant, it is unsurpassed by any
> > other racist events here on the internet. This first incident,
> > is, of course, your posting of near two pages of vile, vulgar
> > and vehement racial slurs, under your fake name, Joe Kline.
Uncanny how much he sounds like Ignatius J. Reilly from John Kennedy
Toole's "A Confederacy Of Dunces".
I wonder if Groanzilla has a "valve" problem as well ;-)
Jay
------------------------------
Date: Fri, 07 Sep 2001 09:17:54 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: HASH question
Message-Id: <3B98D712.A8814B13@home.com>
peter pilsl wrote:
>
> This is the advice of the real guru:
> "other people dont telling you the truth, they lie at you. I know the
> truth, but I wont tell you, cause you need to learn by finding out on
> your own"
"Do not meddle in the afairs of wizards, for they are subtle and quick
to anger." (JRRT) :)
> I recommended the Dumper-module to the OP ages ago and I recommended
> reading the perldoc and I posted a small codeexample for him.
> So whats your problem about it ??
>
> Was it wrong that I answered to the OP or was it wrong the
> way I answered.
That you answered at all! The regulars here have a monopoly on
responding to questions. Everyone else gets the scraps.
No, seriously, it's how you answered. It's important to keep your target
audience in mind when writing a response. More specifically:
If the OP doesn't know what "HASH(0x1cec120)" means, he's probably
pretty inexperienced in Perl. So There's a good chance that he doesn't
know how to find the vaguely named "Dumper-module." He may not even know
how to use a module.
Telling him
>>> You need to read more about anonymous structures and hashes
>>> and arrays.
is completely correct, but he probably doesn't know where to find that
information. At least point him to the right manpage.
Finally, your example was needlessly complex for someone just starting
with references and likely to cause confusion. (Nor do I see the point
of doing a recursive destruction. Clear the top level, let Perl handle
the rest.)
It's find to give answers, but try to give high quality ones. You should
always be prepared to receive criticism. Try not to take it personally
and be receptive to it. There's probably something to be learned. :)
-mjc
------------------------------
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.
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 V10 Issue 1710
***************************************