[27101] in Perl-Users-Digest
Perl-Users Digest, Issue: 8982 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 22 11:05:50 2006
Date: Wed, 22 Feb 2006 08:05:05 -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 Wed, 22 Feb 2006 Volume: 10 Number: 8982
Today's topics:
DBD::CSV malfunction? <Mark.Fenbers@noaa.gov>
Re: DBD::CSV malfunction? <1usa@llenroc.ude.invalid>
Re: Reading Mac / Unix / DOS text files <january.weiner@gmail.com>
Re: Reading Mac / Unix / DOS text files <january.weiner@gmail.com>
Re: Reading Mac / Unix / DOS text files <1usa@llenroc.ude.invalid>
Re: save output to array <jurgenex@hotmail.com>
savely change permission and group on files <daleif@imf.au.dk>
Re: savely change permission and group on files (Anno Siegel)
Re: savely change permission and group on files <daleif@imf.au.dk>
Re: savely change permission and group on files <abaugher@esc.pike.il.us>
Re: savely change permission and group on files <jurgenex@hotmail.com>
Re: XS - Variable creation (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 22 Feb 2006 09:51:38 -0500
From: Mark <Mark.Fenbers@noaa.gov>
To: jeff@vpservices.com
Subject: DBD::CSV malfunction?
Message-Id: <43FC7A7A.8080908@noaa.gov>
On the DBD::CSV doc page at CPAN.org, I am referred to two links at the
end of it for further support. Both links give me a 404 page.
I'm running into a problem with CSV in that it is not pulling data from
a file. Below is my code, a "head" of my data (in the file
"data/location"), and the error message I get (the first one indicates a
possible secondary problem in that $sth->errstr is not set even though
an error is detected).
I have experience using DBI for other code involving databases such as
PostgreSQL and Informix, but this problem with CSV is perplexing me.
I've tried putting .csv suffix on my file, and replaced all semicolons
with commas, too. But none of this seems to matter.
Anyone have any ideas??
Mark
___________________________________________
#!/usr/bin/perl -w
use strict;
use DBI;
my $dbstr = 'DBI:CSV:f_dir=data';
my $dbh = DBI->connect($dbstr,undef,undef,{ChopBlanks => 1,PrintWarn =>
1,PrintError => 0}) or warn "Cannot connect to: $dbstr: " .
DBI->errstr;
my $sql = "SELECT * FROM location ORDER BY lid;";
my $sth = $dbh->prepare("$sql") or die "Cannot prepare SQL: $sql -- " .
$dbh->errstr;
if(defined($sth)) {
$sth->execute() or warn "Unable to execute on $dbstr: $sql -- "
. $sth->errstr; # this execute statement is line 13 ...
# ... that causes the error
}
exit;
__END__
[oper@na_dell7-tir scripts]$ head data/location
lid;county;coe;cpm;detail;elev;hdatum;hsa;hu;lat;lon;lremark;lrevise;name;network;rb;rfc;sbd;sn;state;waro;wfo;wsfo;type;des;det;post;stntype;tzone
06C;Unk;;;at;0.0;;LOT;;41.9844444444444;88.0980555555556;;;Chicago/Schaumburg;Unk;;Unk;;;IL;;LOT;;;;;1;;CST6CDT
07S;Unk;;;at;;;Unk;;47.9667;117.433;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
0A6;Unk;;;at;;;Unk;;35.2;81.15000000000002;;;;Unk;;SERFC;;;XX;;Unk;;;;;0;ASOS;EST5EDT
0V1;Unk;;;at;;;Unk;;43.7333;103.617;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
0Y7;Unk;;;at;;;Unk;;40.6333;93.90000000000001;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
0Z0;Unk;;;at;;;Unk;;66.0667;162.767;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
12N;Unk;;;at;;;Unk;;41.0167;74.7333;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
14G;Unk;;;at;0.0;;CLE;;41.33333333333334;83.16111111111111;;;Fremont;Unk;;OHRFC;;;OH;;CLE;;;;;1;;EST5EDT
[oper@na_dell7-tir scripts]$ ./testcase.pl
Use of uninitialized value in concatenation (.) or string at
./testcase.pl line 13.
Unable to execute on DBI:CSV:f_dir=data: SELECT * FROM location ORDER BY
lid; -- at ./testcase.pl line 13.
------------------------------
Date: Wed, 22 Feb 2006 15:13:08 +0000 (UTC)
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: DBD::CSV malfunction?
Message-Id: <Xns977267F4E221Casu1cornelledu@132.236.56.8>
Mark <Mark.Fenbers@noaa.gov> wrote in news:43FC7A7A.8080908@noaa.gov:
> On the DBD::CSV doc page at CPAN.org, I am referred to two links at
> the end of it for further support. Both links give me a 404 page.
>
> I'm running into a problem with CSV in that it is not pulling data
> from a file. Below is my code, a "head" of my data (in the file
> "data/location"), and the error message I get (the first one indicates
> a possible secondary problem in that $sth->errstr is not set even
> though an error is detected).
Mark, first off, I would like to thank you very much for reading and
following the posting guidelines, and making it easy for us to try and
help.
> my $dbstr = 'DBI:CSV:f_dir=data';
> my $dbh = DBI->connect($dbstr,undef,undef,{ChopBlanks => 1,PrintWarn
> =>
> 1,PrintError => 0}) or warn "Cannot connect to: $dbstr: " .
> DBI->errstr;
You might want to format things in a little nicer way:
my $dbh = DBI->connect($dbstr,
undef, undef, {
ChopBlanks => 1,
PrintWarn => 1,
PrintError => 0
}) or warn "Cannot connect to: $dbstr: " . DBI->errstr;
>
> my $sql = "SELECT * FROM location ORDER BY lid;";
This is the problem. I do not think you can use 'ORDER BY' with DBD::CSV.
Sinan
------------------------------
Date: Wed, 22 Feb 2006 09:00:55 +0100 (CET)
From: January Weiner <january.weiner@gmail.com>
Subject: Re: Reading Mac / Unix / DOS text files
Message-Id: <dth5nn$3ip$1@sagnix.uni-muenster.de>
A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
> You should use the codes for those characters rather than the escapes.
Hmmm, OK, and why?
> Here, an appropriate amount of whitespace, not using bareword
> filehandles, and using an appropriate variable name would have helped
> immensely with readability.
> while ( <$input> ) {
Sorry. I learned the rudimentaries of Perl some ten years ago, when, as
far as I can remember, bareword filehandles were something to be found
frequently in the code I learned Perl from. Thanks for the suggestions.
I should have written <STDIN> and everyone would be happy (unless, of
course, the modern style recommends something instead of the bareword
STDIN).
> > s/\r?\l?$// ; # is this correct anyway? will an end of line be
> > # recognized with a Mac file?
> This information is readily available by doing a cursory Google search.
> Are you that lazy?
I think that I am rather that stupid, because I did go through both, FAQ
and a dozen hits Google returned (not to mention Perl documentation on my
system), but I found mostly references to modifications of the
$INPUT_RECORD_SEPARATOR, which does not really do job for me. Do you think
I am really so eager to expose myself to ruddy remarks of Perl gurus by
asking a novice question? :-)
> s{ \012 | (?: \015\012? ) }{\n}x
> should convert any line ending convention to the one supported by your
> platform.
Thank you for giving me the answer nonetheless :-)
> > I would expect that there is some weird variable out there
> > (like the $/)
> $/ is not a weird variable. It is documented in perldoc perlvar.
Sorry. I know it is and I know the docs. Would you have been happier if I
had written "shorthand" instead of "weird"?
Thanks for your answer!
j.
--
------------------------------
Date: Wed, 22 Feb 2006 09:12:13 +0100 (CET)
From: January Weiner <january.weiner@gmail.com>
Subject: Re: Reading Mac / Unix / DOS text files
Message-Id: <dth6ct$3ip$2@sagnix.uni-muenster.de>
Rick Scott <rick@shadowspar.dyndns.org> wrote:
> Your filehandle `IF' collides with Perl's conditional `if' in the
> mental hash-bucket of the programmers who have to read your code.
That's an argument. I will refrain from using <IF> in public. It causes
too much stir and excites people.
> Given that it reduces the comprehensibility of your program and that
> you could have used any number of more legible identifiers, I'd call
> use of `IF' poor style, if not an outright error.
Why an error? (yeah, it can lead to errors, agree, but then, of course, a
collegue of mine says the same about using Perl)
> On the contrary -- I would posit that any coding practice that makes
> it easier to inadvertently introduce bugs into your program is a
> poor one. By using a bareword filehandle, you're essentially using
> a package variable (*IF). If some other piece of code in the same
> package namespace touches that bareword while you're using it to read
> from a file, your filehandle will get stomped and your code will break
> without you even having changed it. That's why it's a bad idea.
I think this depends a little on what you are using Perl for, and just
some basic common sense is sufficient to say when using shorthand is OK and
when it is a bad idea. I do use the <IF> construct in few-liners that do
not read more than one file. I do think it is important to define
variables if you are writing a larger piece of code. I do not understand
the whole stir about this issue.
> Pick up a copy of Damian Conway's "Perl Best Practices" -- he explains
> why this and about a thousand other `harmless style preferences' aren't
> harmless, aren't stylish, and definitely aren't preferable.
So what is the problem with whitespace? Why is while(<STDIN>) more harmful
than while ( <STDIN> ) ?
j.
--
------------------------------
Date: Wed, 22 Feb 2006 15:21:32 +0000 (UTC)
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Reading Mac / Unix / DOS text files
Message-Id: <Xns9772696145343asu1cornelledu@132.236.56.8>
January Weiner <january.weiner@gmail.com> wrote in
news:dth5nn$3ip$1@sagnix.uni-muenster.de:
> A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
>
>> You should use the codes for those characters rather than the
>> escapes.
>
> Hmmm, OK, and why?
Because ...
>> > s/\r?\l?$// ; # is this correct anyway? will an end of line be
it is easy to get confused (from perldoc perlre):
\l lowercase next char (think vi)
That is, \l is not linefeed.
In any case, these escapes could potentially mean different things on
different systems. Why not be very specific in what you really are
looking for?
>> This information is readily available by doing a cursory Google
>> search. Are you that lazy?
>
> I think that I am rather that stupid, because I did go through both,
> FAQ and a dozen hits Google returned
http://www.google.com/search?q=perl+eol
http://www.google.com/search?q=newline
In any case, I should probably have put a smiley there, because I had not
intended it to come across that harshly.
> Thanks for your answer!
You are welcome.
Sinan
------------------------------
Date: Wed, 22 Feb 2006 14:33:42 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: save output to array
Message-Id: <aD_Kf.1648$gh4.830@trnddc06>
a wrote:
> Actually, I need to look for the file path of the given file name.
> Do perl have support for this?
See perldoc File::Basename
jue
------------------------------
Date: Wed, 22 Feb 2006 13:10:51 +0100
From: Lars Madsen <daleif@imf.au.dk>
Subject: savely change permission and group on files
Message-Id: <43fc54b1$0$12109$ba624c82@nntp02.dk.telia.net>
Hi,
I have a small problem here. We have a special directory on our file
system (Linux) where a lot of people are writing to (mostly HTML pages,
no we do not have a CMS, this low tech is fine for now).
Now we also have some secretaries who can help edit these files. The
problems is of course permissions, secretary B need to be able to edit
the files owned by user A.
Solution: Put the necessary people in a special group and make sure that
the files are writable for that group. That's fine, but people tend to
forget setting permissions or changing groups, so I'd like to have a
cron job that goes through all files in a specific directory and set the
group and permissions on all files in this directory-tree.
That's easy to do, well sort of. The problem is of course that this cron
job has to run as root (or similar) and then we are vulnerable to user
input, as in file names such as 'file.html;rm -rf /'
So my question is this: how can one safely change the group and group
permissions in such a case as this. Or more generally how can one run
system commands safely on potentially dangerous data?
/daleif
------------------------------
Date: 22 Feb 2006 12:54:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: savely change permission and group on files
Message-Id: <dthmtm$om3$1@mamenchi.zrz.TU-Berlin.DE>
Lars Madsen <daleif@imf.au.dk> wrote in comp.lang.perl.misc:
> Hi,
>
> I have a small problem here. We have a special directory on our file
> system (Linux) where a lot of people are writing to (mostly HTML pages,
> no we do not have a CMS, this low tech is fine for now).
>
> Now we also have some secretaries who can help edit these files. The
> problems is of course permissions, secretary B need to be able to edit
> the files owned by user A.
>
> Solution: Put the necessary people in a special group and make sure that
> the files are writable for that group. That's fine, but people tend to
> forget setting permissions or changing groups, so I'd like to have a
> cron job that goes through all files in a specific directory and set the
> group and permissions on all files in this directory-tree.
>
> That's easy to do, well sort of. The problem is of course that this cron
> job has to run as root (or similar) and then we are vulnerable to user
> input, as in file names such as 'file.html;rm -rf /'
>
> So my question is this: how can one safely change the group and group
> permissions in such a case as this. Or more generally how can one run
> system commands safely on potentially dangerous data?
Firstly, a file name like that is only dangerous if you let a shell
interpret it. "chmod" by itself will fail, or change the permissions
if you managed to create a file of that name. So use the list form
of system(), which doesn't employ a shell. perldoc -f system.
Secondly, you don't need an external command at all to change the
file group. perldoc -f chown.
Thirdly, though this has nothing to do with Perl, you can set the group
of the enclosing directory to the common one and set its sgid bit. Under
Linux (and other BSD-derived systems) files and directories created in
that directory will be in the same group per default. man chmod.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Wed, 22 Feb 2006 15:05:02 +0100
From: Lars Madsen <daleif@imf.au.dk>
Subject: Re: savely change permission and group on files
Message-Id: <43fc6f70$0$6849$ba624c82@nntp02.dk.telia.net>
>
> Firstly, a file name like that is only dangerous if you let a shell
> interpret it. "chmod" by itself will fail, or change the permissions
> if you managed to create a file of that name. So use the list form
> of system(), which doesn't employ a shell. perldoc -f system.
>
ok
> Secondly, you don't need an external command at all to change the
> file group. perldoc -f chown.
>
I know
> Thirdly, though this has nothing to do with Perl, you can set the group
> of the enclosing directory to the common one and set its sgid bit. Under
> Linux (and other BSD-derived systems) files and directories created in
> that directory will be in the same group per default. man chmod.
>
hmm, never even thought of that
thanks
/daleif
------------------------------
Date: Wed, 22 Feb 2006 07:34:46 -0600
From: Aaron Baugher <abaugher@esc.pike.il.us>
Subject: Re: savely change permission and group on files
Message-Id: <86bqwz34ax.fsf@cail.baugher.pike.il.us>
Lars Madsen <daleif@imf.au.dk> writes:
> Solution: Put the necessary people in a special group and make sure
> that the files are writable for that group. That's fine, but people
> tend to forget setting permissions or changing groups, so I'd like
> to have a cron job that goes through all files in a specific
> directory and set the group and permissions on all files in this
> directory-tree.
Not really a perl problem:
#!/bin/sh
if cd /wherever; then
chgrp -R ourgroup .
chmod -R g+rw .
fi
--
Aaron -- aaron_baugher@yahoo.com
http://360.yahoo.com/aaron_baugher
------------------------------
Date: Wed, 22 Feb 2006 14:36:49 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: savely change permission and group on files
Message-Id: <5G_Kf.1649$gh4.12@trnddc06>
Lars Madsen wrote:
[...]
> Now we also have some secretaries who can help edit these files. The
> problems is of course permissions, secretary B need to be able to edit
> the files owned by user A.
>
> Solution: Put the necessary people in a special group and make sure
> that the files are writable for that group. That's fine, but people
> tend to forget setting permissions or changing groups,
Why not set the SetGUID bit on the directory?
> so I'd like to
> have a cron job that goes through all files in a specific directory
> and set the group and permissions on all files in this directory-tree.
[complicated proposal snipped]
jue
------------------------------
Date: 22 Feb 2006 08:25:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: XS - Variable creation
Message-Id: <dth74u$e1n$1@mamenchi.zrz.TU-Berlin.DE>
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote in comp.lang.perl.misc:
> [A complimentary Cc of this posting was sent to
> Anno Siegel
> <anno4000@lublin.zrz.tu-berlin.de>], who wrote in article
> <dtcffo$icp$1@mamenchi.zrz.TU-Berlin.DE>:
> > > BTW can someone explain me the difference in marking a SV as "not longer
> > > needed" by doing a
> > >
> > > sv_2mortal(mysv) and
> > > SvREFCNT_dec(mysv)?
> >
> > SvREFCNT_dec counts the refcount down immediately. If the sv had
> > a refcount of 1, it will be gone after the operation.
>
> > sv_2mortal arranges for a delayed SvREFCNT_dec. The sv will continue
> > to exist until the next call to FREETMPS. FREETMPS is usually called
> > implicitly at statement boundaries.
>
> Better make this "next call to FREETMPS upward in the call tree".
Thanks for the rectification.
The salient point is that most of the time an XS programmer doesn't call
FREETMPS explicitly but lets "the system" call it whenever it does.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
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 V10 Issue 8982
***************************************