[30594] in Perl-Users-Digest
Perl-Users Digest, Issue: 1837 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 4 21:09:45 2008
Date: Thu, 4 Sep 2008 18: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 Thu, 4 Sep 2008 Volume: 11 Number: 1837
Today's topics:
Re: "Selling" Perl (i.e. getting the boss to let me ins <tzz@lifelogs.com>
Re: "Selling" Perl (i.e. getting the boss to let me ins <d a v i d . e v e r s o n @ h p . c o m>
ANNOUNCE: Text-CSV_XS 0.54 <h.merijn@xs4all.nl>
Re: Compile vs mod_perl vs perl <yankeeinexile@gmail.com>
Re: How to check the size of each files that are being (fidokomik\)
How to read/write this data. <justin.0809@purestblue.com>
Re: How to read/write this data. <john@castleamber.com>
Re: How to read/write this data. <cartercc@gmail.com>
Re: How to read/write this data. <glennj@ncf.ca>
Re: How to read/write this data. <cartercc@gmail.com>
Re: How to read/write this data. <tadmc@seesig.invalid>
Search a file backgoodoo@gmail.com
Re: Search a file <pinkmeat@preshweb.co.uk>
Re: Search a file <mritty@gmail.com>
Re: Search a file <jurgenex@hotmail.com>
Re: Search a file backgoodoo@gmail.com
Re: Search a file <spamtrap@dot-app.org>
Re: Search a file <jurgenex@hotmail.com>
Re: Search a file <1usa@llenroc.ude.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 04 Sep 2008 09:07:36 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: "Selling" Perl (i.e. getting the boss to let me install it)
Message-Id: <86sksgc8d3.fsf@lifelogs.com>
On Thu, 04 Sep 2008 02:02:56 +0200 nntpman68 <news1234@free.fr> wrote:
n> If you don't write servers and if you don't execute / eval anything
n> downloaded from unknown / external net works you're rather safe.
I've often mentioned here and elsewhere that treating configurations as
code is a sure way to subvert security. Configuration should only be
logical data, not code to be executed, or else you end up with an easy
attack vector as soon as the program's configuration can be modified.
Specifically, programs should use any combination of YAML, JSON,
AppConfig, XML, and Getopt (as fits the purpose and environment). None
of those are as easy as a simple do("file.conf") but they are much more
robust.
Ted
------------------------------
Date: Thu, 4 Sep 2008 15:42:36 -0700
From: "Dave Everson" <d a v i d . e v e r s o n @ h p . c o m>
Subject: Re: "Selling" Perl (i.e. getting the boss to let me install it)
Message-Id: <g9po98$2nc$1@usenet01.boi.hp.com>
OK -- maybe a little. But I would not care to work in a place that won't
allow me to install recognized useful tools on my system. It is certainly
management's call as to what makes it into production environments but
developers should rightly be able to manage their own environments. In some
shops you can't install VI. Those aren't serious development organizations
and I would stay away.
--
Dave Everson
------------------------------
Date: Thu, 4 Sep 2008 07:50:34 GMT
From: "H.Merijn" <h.merijn@xs4all.nl>
Subject: ANNOUNCE: Text-CSV_XS 0.54
Message-Id: <K6oB6q.x0J@zorch.sf-bay.org>
file: $CPAN/authors/id/H/HM/HMBRAND/Text-CSV_XS-0.54.tgz
size: 90923 bytes
md5: d490c1d8f37386b980abfdd53a96705b
2008-09-04 0.54 - H.Merijn Brand <h.m.brand@xs4all.nl>
* IO failure in print () was not propagated (ilmari, RT#38960)
2008-09-01 0.53 - H.Merijn Brand <h.m.brand@xs4all.nl>
* SvUPGRADE is a safer choice than sv_upgrade (Lubomir Rintel,
RT#38890)
* bring docs in sync with reality for msg 2023
* Default eol for print is $\
* examples/csv-check should default to CSV , not to ;
* Tests for SetDiag (0)
* Tests for error 2030
* Code cleanup (Devel::Cover++)
------------------------------
Date: 04 Sep 2008 09:48:52 -0500
From: Lawrence Statton <yankeeinexile@gmail.com>
Subject: Re: Compile vs mod_perl vs perl
Message-Id: <87fxogvuej.fsf@hummer.cluon.com>
Peter Scott <Peter@PSDT.com> writes:
>
> That suggests that Persistent Perl (http://daemoninc.com/PersistentPerl/)
> would be a good idea, but it hasn't been updated in ages. Anyone know of
> a successor?
>
If it ain't broke, why fix it?
------------------------------
Date: Fri, 5 Sep 2008 02:59:47 +0200
From: "Petr Vileta \(fidokomik\)" <stoupa@practisoft.cz>
Subject: Re: How to check the size of each files that are being uploaded
Message-Id: <g9q0k6$lks$1@adenine.netfront.net>
tower.grv@gmail.com wrote:
>> Partial solution is to use javascript to check file sizes before
>> user click on Send button. But be sure to warn users which have
>> javascript disabled in browser. It is very simple:
>>
>> <body>
>> <noscript>
>> <div style="border: 2px solid red">You have not javascript enabled,
>> please enable it.</div>
>> </noscript>
>> --
> I tried to get file size with javascrip but i found that it is
> imposiblem. Browsers don't allow this operation.
> Do you know how to do this?
I did not test it but I found something
http://www.jguru.com/faq/view.jsp?EID=330134
http://forums.digitalpoint.com/showthread.php?t=137411
http://bytes.com/forum/thread460516.html
The magic words for Google are "get file size javascript" :-)
Maybe some of that can help you.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail.
Send me your mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>
-- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
------------------------------
Date: Thu, 04 Sep 2008 14:45:28 -0000
From: Justin C <justin.0809@purestblue.com>
Subject: How to read/write this data.
Message-Id: <339a.48bff488.29038@zem>
I have ten Excel files which I read with Spreadsheet::ParseExcel. Each
file has only one worksheet. The worksheets are 6 columns by
$sheet->MaxRow (ie, I don't know, but perl can find out). Each sheet is
divided into sections of identically structured data, an empty line
divides the sections.
I want to access the data, so it can be output identically, but in a
different format (I can't do straight read/write because I need to do
some calculations on line numbers for page-break purposes before I
output). My intention was to read it all into a hash whose keys would be
the file name, and data would be a hash, whose keys would be a section
number, and data would be a hash.... etc all the way down to cell
contents.
I end up with something like this:
$data{$file}{$section}{$row}{$col}{data} = $cell->{Val}
$data{$file}{$section}{$row}{$col}{format} = $cell->{Format}
I have a hash, $deity knows what's in it! I can't figure out how to
work through it. For example, I need to know how many sections there are
in each file, and how many rows in each section. For the very bottom end
of the processing I need to iterate over the data and format of each
column of each row in each section.
I'm hopelessly lost!
Looking at some docs, I find that what I have (or should have) is:
a hash of file names containing
an array of sections containing
an array of rows containing
an array of columns containing
a hash of value/format data
I've been looking at the chapter 4.7 of Programming Perl, data structure
code examples. There is a "composition of more elaborate records"
section, but I can't translate that to what I have, my brain is just not
getting it.
Maybe I should ask something simple to start with: How do I get the
number of sections that are in, say, file number 2 ($file == 2)?
Actually, I'm not even certain I've got the hash right.
Pointers to reading matter, explanations, suggestions, anything (even a
gun and a bullet) will be gratefully received.
Justin.
--
Justin C, by the sea.
------------------------------
Date: 4 Sep 2008 16:21:29 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: How to read/write this data.
Message-Id: <Xns9B0F738AC1285castleamber@130.133.1.4>
Justin C <justin.0809@purestblue.com> wrote:
> $data{$file}{$section}{$row}{$col}{data} = $cell->{Val}
> $data{$file}{$section}{$row}{$col}{format} = $cell->{Format}
>
> I have a hash, $deity knows what's in it! I can't figure out how to
> work through it.
use Data::Dumper;
print Dumper $data;
(or use YAML)
> For example, I need to know how many sections there are
> in each file
my $number_of_sections = keys %{ $data{ $file } }
$data{ $file } contains a reference to a hash of sections.
[..]
> Looking at some docs, I find that what I have (or should have) is:
> a hash of file names containing
> an array of sections containing
> an array of rows containing
> an array of columns containing
> a hash of value/format data
You have a hash of hash of .. etc.
What you describe is:
$data{ $file }[ $section ][ $row ][ $col ]{
data => $cell->{ Val },
format => $cell->{ Format },
};
> Pointers to reading matter, explanations,
{} = hash
[] = array
Use Data Dumper to examine your data structure(s).
Remeber that if you're doing stuff with a section, you can make your
code more readable as follows:
my $current_section = [];
$current_section->[ $row ][ $col ]{ data } ...
$data{ $file }[ $section ] = $current_section;
--
John http://johnbokma.com/ - Hacking & Hiking in Mexico
Perl help in exchange for a gift:
http://johnbokma.com/perl/help-in-exchange-for-a-gift.html
------------------------------
Date: Thu, 4 Sep 2008 11:15:25 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: How to read/write this data.
Message-Id: <90853646-406d-4941-90bc-646ba7428875@z11g2000prl.googlegroups.com>
On Sep 4, 10:45=A0am, Justin C <justin.0...@purestblue.com> wrote:
> I end up with something like this:
>
> $data{$file}{$section}{$row}{$col}{data} =3D $cell->{Val}
> $data{$file}{$section}{$row}{$col}{format} =3D $cell->{Format}
You can iterate through a complex structure of hashes like this:
foreach my $file (sort keys %data)
{ print "\n$file\t"; #sanity check
foreach my $section (sort keys %{$data{$file}})
{ print "$section\t"; #sanity check
foreach my $row (sort keys %{$data{$file{$section}}})
{ print "$row\t"; #sanity check
foreach my $col (sort keys %
{$data{$file{$section{$row}}}})
{ print "$col\t"; #sanity check
print "\nDATA: $data{$file}{$section}{$row}{$col}";
}
}
}
}
The little book about Perl Objects, References, and Modules (Schwartz)
is good.
CC
------------------------------
Date: 4 Sep 2008 18:59:04 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: How to read/write this data.
Message-Id: <slrngc0bvq.651.glennj@smeagol.ncf.ca>
At 2008-09-04 02:15PM, "cartercc" wrote:
> On Sep 4, 10:45 am, Justin C <justin.0...@purestblue.com> wrote:
> > I end up with something like this:
> >
> > $data{$file}{$section}{$row}{$col}{data} = $cell->{Val}
> > $data{$file}{$section}{$row}{$col}{format} = $cell->{Format}
>
> You can iterate through a complex structure of hashes like this:
>
> foreach my $file (sort keys %data)
> { print "\n$file\t"; #sanity check
> foreach my $section (sort keys %{$data{$file}})
> { print "$section\t"; #sanity check
> foreach my $row (sort keys %{$data{$file{$section}}})
Mind your braces: should be:
foreach my $row (sort keys %{ $data{$file}{$section} })
> { print "$row\t"; #sanity check
> foreach my $col (sort keys %{$data{$file{$section{$row}}}})
should be:
foreach my $col (sort keys %{ $data{$file}{$section}{$row} })
> { print "$col\t"; #sanity check
> print "\nDATA: $data{$file}{$section}{$row}{$col}";
That will print something like "DATA: HASH(0x100d8b08)". You need
another layer to iterate over the keys of %$col:
my $ref = $data{$file}{$section}{$row}{$col};
while (my ($key, $val) = each %$ref) {
print "'$key' => '$val'\n";
}
I too frequently use Data::Dumper with $Data::Dumper::Indent--;
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
------------------------------
Date: Thu, 4 Sep 2008 12:42:09 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: How to read/write this data.
Message-Id: <d11f874b-cd05-4396-bbc4-c67ea90ca794@a2g2000prm.googlegroups.com>
On Sep 4, 2:59=A0pm, Glenn Jackman <gle...@ncf.ca> wrote:
> Mind your braces: should be:
> =A0 =A0 =A0 =A0 =A0 =A0foreach my $row (sort keys %{ $data{$file}{$sectio=
n} })
Yeah. I bashed this out from memory. Normally it would take me several
tries to get it right -- I always have problems with the braces but
it's not too hard to correct as long as you understand how the
references work.
CC
------------------------------
Date: Thu, 4 Sep 2008 18:37:08 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: How to read/write this data.
Message-Id: <slrngc0s94.jfm.tadmc@tadmc30.sbcglobal.net>
Justin C <justin.0809@purestblue.com> wrote:
> I end up with something like this:
>
> $data{$file}{$section}{$row}{$col}{data} = $cell->{Val}
> I have a hash, $deity knows what's in it! I can't figure out how to
> work through it.
See
perldoc perlreftut
then apply "Use Rule 1", which I like to do in 3 steps.
> For example, I need to know how many sections there are
> in each file,
1) pretend it is a plain old hash, using the scalar value of keys():
my $section_count = keys %hash;
2) replace the hash name with a block:
my $section_count = keys %{ };
3) fill in the block with something that returns the right
kind of reference (to a hash in this case):
my $section_count = keys %{ $data{$file} };
> Looking at some docs, I find that what I have (or should have) is:
> a hash of file names containing
> an array of sections containing
> an array of rows containing
> an array of columns containing
> a hash of value/format data
> Maybe I should ask something simple to start with: How do I get the
> number of sections that are in, say, file number 2 ($file == 2)?
my $section_count = keys %{ $data{2} };
> Actually, I'm not even certain I've got the hash right.
It surely does not match your word description...
> Pointers to reading matter,
perlreftut dude.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Thu, 4 Sep 2008 10:42:44 -0700 (PDT)
From: backgoodoo@gmail.com
Subject: Search a file
Message-Id: <3a2e7cd8-2e2d-4632-8631-780bc41547e0@q5g2000prf.googlegroups.com>
Hello
Does anyone know how to find out whether a file exists or not?
TIA
------------------------------
Date: Thu, 04 Sep 2008 19:07:20 +0100
From: David Precious <pinkmeat@preshweb.co.uk>
Subject: Re: Search a file
Message-Id: <UtVvk.148896$6s4.24142@newsfe14.ams2>
backgoodoo@gmail.com wrote:
> Hello
>
> Does anyone know how to find out whether a file exists or not?
if (-f $filename) {
# $filename is a file which exists
}
Full list of tests:
http://perldoc.perl.org/functions/-X.html
A couple of seconds Googling probably would have found you the answer.
Cheers
David Precious
------------------------------
Date: Thu, 4 Sep 2008 11:08:11 -0700 (PDT)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Search a file
Message-Id: <02bba549-1791-4851-b8e6-ae4ae77ada80@25g2000prz.googlegroups.com>
On Sep 4, 1:42=A0pm, backgoo...@gmail.com wrote:
> Does anyone know how to find out whether a file exists or not?
if (-e 'file.txt') {
print "file.txt exists\n";
} else {
print "file.txt does not exist\n";
}
------------------------------
Date: Thu, 04 Sep 2008 18:09:09 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Search a file
Message-Id: <6u80c45ul83r7p8knefieien9u885s3fcs@4ax.com>
backgoodoo@gmail.com wrote:
>Does anyone know how to find out whether a file exists or not?
perldoc -f -e
jue
------------------------------
Date: Thu, 4 Sep 2008 12:53:34 -0700 (PDT)
From: backgoodoo@gmail.com
Subject: Re: Search a file
Message-Id: <8e4ae12c-3235-4112-a476-2104557c2936@p31g2000prf.googlegroups.com>
On Sep 4, 2:07=A0pm, David Precious <pinkm...@preshweb.co.uk> wrote:
> backgoo...@gmail.com wrote:
> > Hello
>
> > Does anyone know how to find out whether a file exists or not?
>
> if (-f $filename) {
> =A0 =A0 =A0# $filename is a file which exists
>
> }
>
> Full list of tests:http://perldoc.perl.org/functions/-X.html
>
> A couple of seconds Googling probably would have found you the answer.
>
> Cheers
>
> David Precious
Let me clarify my question again.
I want to search a file I do not know where it is but know its name
such as "text.exe".
So I want to check whether or not it is under c:\program file and sub
folders.
TIA
------------------------------
Date: Thu, 04 Sep 2008 16:19:00 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Search a file
Message-Id: <m1fxofll57.fsf@dot-app.org>
backgoodoo@gmail.com writes:
> Let me clarify my question again.
Not that it matters, but this seems more like an entirely different
question than a clarification of the original. :-)
> I want to search a file I do not know where it is but know its name
> such as "text.exe".
Have a look at the File::Find module.
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Thu, 04 Sep 2008 20:22:53 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Search a file
Message-Id: <2og0c416o5i24060kd1f9gs6pp4025o415@4ax.com>
backgoodoo@gmail.com wrote:
>> backgoo...@gmail.com wrote:
>> > Does anyone know how to find out whether a file exists or not?
>
>I want to search a file I do not know where it is but know its name
>such as "text.exe".
Don't you think those two requirements are quite different?
Anyway, the File::Find module has functions to search for the location
of a given file.
jue
------------------------------
Date: Thu, 04 Sep 2008 20:28:46 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Search a file
Message-Id: <Xns9B0FA7A30B4CCasu1cornelledu@127.0.0.1>
backgoodoo@gmail.com wrote in news:8e4ae12c-3235-4112-a476-2104557c2936
@p31g2000prf.googlegroups.com:
> On Sep 4, 2:07 pm, David Precious <pinkm...@preshweb.co.uk> wrote:
>> backgoo...@gmail.com wrote:
>> > Hello
>>
>> > Does anyone know how to find out whether a file exists or not?
>>
>> if (-f $filename) {
>> # $filename is a file which exists
>>
>> }
>>
>> Full list of tests:http://perldoc.perl.org/functions/-X.html
...
> Let me clarify my question again.
You did not ask a clear question to begin with and this is the first
time you are clarifying the question, so the 'again' above is not
necessary
> I want to search a file I do not know where it is but know its name
> such as "text.exe".
> So I want to check whether or not it is under c:\program file and sub
> folders.
perldoc File::Find
I also like:
http://search.cpan.org/~texmec/File-Find-Iterator-0.4/
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use File::Find::Iterator;
use File::Spec::Functions qw( canonpath );
my $find = File::Find::Iterator->create(
dir => [ $ENV{TEMP} ],
filter => sub { /t\.pl\z/ },
);
while ( my $found = $find->next ) {
print "$found\n";
}
__END__
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
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 1837
***************************************