[18988] in Perl-Users-Digest
Perl-Users Digest, Issue: 1183 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 24 14:05:42 2001
Date: Sun, 24 Jun 2001 11:05:11 -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: <993405911-v10-i1183@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 24 Jun 2001 Volume: 10 Number: 1183
Today's topics:
Re: how can i compile a perl program (Tad McClellan)
Re: how can i compile a perl program <patelnavin@icenet.net>
Re: how can i compile a perl program <patelnavin@icenet.net>
Re: how can i compile a perl program <flavell@mail.cern.ch>
Re: Merging two scripts (Rolf Krahl)
Re: Merging two scripts cd001@mybc.com
Package : Why so ? <Francis.Derive@wanadoo.fr>
Re: passing variables the 'right' way <patelnavin@icenet.net>
Re: passing variables the 'right' way (Tad McClellan)
Re: passing variables the 'right' way (Rolf Krahl)
Re: passing variables the 'right' way (Tramm Hudson)
Re: passing variables the 'right' way (Mark Jason Dominus)
Re: Possible to split GIF or JPG into 12 images? <addi@umich.edu>
Re: Regular Expressions == How to use grep ? (Tad McClellan)
Re: Regular Expressions == How to use grep ? <ronh@iainc.com>
Re: require 'question' (Rolf Krahl)
some one help me Can't locate object method "connect" v <surajsid@sharbatlyvillage.com.sa>
Re: what would be better? (lots of files vs 1 file) (Tad McClellan)
Re: what would be better? (lots of files vs 1 file) <bowman@montana.com>
Re: what would be better? (lots of files vs 1 file) <bwalton@rochester.rr.com>
Re: Why does this split not work? (Zur Aougav)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 24 Jun 2001 08:29:53 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: how can i compile a perl program
Message-Id: <slrn9jbna1.bkb.tadmc@tadmc26.august.net>
Suraj Siddique <surajsid@sharbatlyvillage.com.sa> wrote:
>how can i compile a perl program to make an excecutable
^^^^^^^
perldoc -q compile
"How can I compile my Perl program into byte code or C?"
You are expected to check the Perl FAQ *before* posting to
the Perl newsgroup.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 24 Jun 2001 18:57:59 +0530
From: "Aman Patel" <patelnavin@icenet.net>
Subject: Re: how can i compile a perl program
Message-Id: <9h4prq$bucn1$1@ID-93885.news.dfncis.de>
perl program is not compiled, its interpreted, although not recommended, if
you want to lookup on how to make a parse tree(byte code) out of a perl
file, type the following on your command prompt:
$ perldoc -q "how can i compile my perl program"
make sure the quotes are there, and yeah if you have windoze, and
ActiveState's perl installed, you can still use the above command.
Or simply lookup perlfaq3 (man perlfaq3), and find your way through.
"Suraj Siddique" <surajsid@sharbatlyvillage.com.sa> wrote in message
news:993386227.563610@news...
> how can i compile a perl program to make an excecutable
>
>
------------------------------
Date: Sun, 24 Jun 2001 19:32:00 +0530
From: "Aman Patel" <patelnavin@icenet.net>
Subject: Re: how can i compile a perl program
Message-Id: <9h4rrt$c07rq$1@ID-93885.news.dfncis.de>
> You are expected to check the Perl FAQ *before* posting to
> the Perl newsgroup.
Yeah, RTM (boy i always wanted to say that).
------------------------------
Date: Sun, 24 Jun 2001 16:11:02 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: how can i compile a perl program
Message-Id: <Pine.LNX.4.30.0106241609130.21022-100000@lxplus013.cern.ch>
On Sun, 24 Jun 2001, Aman Patel jeopardized:
> perl program is not compiled, its interpreted,
Methinks the hon Usenaut is over-simplifying.
------------------------------
Date: 24 Jun 2001 13:08:35 GMT
From: rolf.krahl@gmx.net (Rolf Krahl)
Subject: Re: Merging two scripts
Message-Id: <9h4ooj$2sa$4@rotkraut.de>
In article <3b35cc5e.20906676@news.telus.net>,
cd001@telus.net (cd) writes:
>
> I have a script which emails out two messages using information from a
> form. The emails go out in HTML format to two different email
> addresses and it works really well...
>
> I have another script which works well creating and maintaining a flat
> database. I would like to have the information entered in the form go
> to the email script and to be entered into the database as well....
>
> Is there any way to do this? Do I merge the scripts? Call one from the
> other? Forget this idea all together?
Its impossible to answer your question without knowing your scripts.
(And posting the scripts wouldn't help either, because analyzing the
scripts on how the merge could be done, would mean to actually do the
work of merging, and this is to you to do it.) There is no easy
answer on how such a merge can be done, that will do the best thing in
all cases.
Most often, the easiest approach is to write an entirely new script,
but reusing fragments of code from your old scripts where its
appropriate. That means reconsidering the new task step by step and
when it turns out, that some particular step was already implemented
by one of old scripts, just copy the code fragment and adapt it to the
new script where necessary.
--
Rolf Krahl <rolf.krahl@gmx.net>
------------------------------
Date: Sun, 24 Jun 2001 17:20:11 GMT
From: cd001@mybc.com
Subject: Re: Merging two scripts
Message-Id: <3b3621e4.761139@news.telus.net>
On 24 Jun 2001 13:08:35 GMT, rolf.krahl@gmx.net (Rolf Krahl) wrote:
..
>>
>> Is there any way to do this? Do I merge the scripts? Call one from the
>> other? Forget this idea all together?
>
>Its impossible to answer your question without knowing your scripts.
>(And posting the scripts wouldn't help either, because analyzing the
>scripts on how the merge could be done, would mean to actually do the
>work of merging, and this is to you to do it.) There is no easy
>answer on how such a merge can be done, that will do the best thing in
>all cases.
>
>Most often, the easiest approach is to write an entirely new script,
>but reusing fragments of code from your old scripts where its
>appropriate. That means reconsidering the new task step by step and
>when it turns out, that some particular step was already implemented
>by one of old scripts, just copy the code fragment and adapt it to the
>new script where necessary.
Thank you for your reply.
I have considered that approach, but I am hesitant since I am a
relative neophyte to programming... Perl is the only language I have
played with and, at best, I have managed to change minor parameters on
already existing scripts....
I will plunge on. Thanks again..
------------------------------
Date: 24 Jun 2001 20:02:03 +0200
From: "Francis Derive" <Francis.Derive@wanadoo.fr>
Subject: Package : Why so ?
Message-Id: <B75BF7C1-4AD2E@80.9.51.148>
Bonjour !
I wanted to group related functions in one package and I was surprised to
see that I needed to have at least one assignment so that it works - if
not, the package cannot be recognized from the "calling" file.
package my-package;
my fonc_1 {
...
}
...
my fonc_n {
...
}
# end of file.
This does not work, unless an assignment like this one, left from results
printing, is introduced :
( $,,$\) = (" ", "n);
Why so ? Can I do better ?
Merci d'avance.
Francis.
------------------------------
Date: Sun, 24 Jun 2001 18:53:37 +0530
From: "Aman Patel" <patelnavin@icenet.net>
Subject: Re: passing variables the 'right' way
Message-Id: <9h4pjk$c46vd$1@ID-93885.news.dfncis.de>
thanks jakob, that was really helpfull, thats why sometimes if i try to
access, $_ in a subroutine, it doesnt turn up, i have to do a $_[0] in order
for it to work.
And yeah, my program is full of stupid my $var = shift. i guess i have to
change them all!!! ahh what a pain.
Thanks for the info!
"Jakob Schmidt" <sumus@aut.dk> wrote in message
news:m2ithmnl2s.fsf@pocketlife.dk...
> "Aman Patel" <patelnavin@icenet.net> writes:
>
> > my $var = slurp_a_file; #loads a big file,
> > pass_subroutine( \$var );
>
> Yes, that will pass a reference into the sub (in $_[ 0 ]), which is much
> like passing a pointer in C(\+\+)?
>
> > if i am right about the above code, how do we accept references in the
> > subroutine i.e.
>
> As I said, $_[ 0 ] contains the reference, so ${ $_[ 0 ] } will give you
> the value ($ as dereference operator - much like * in C).
>
> But actually you may not need to go through all this if the issue is
> passing by reference to avoid copying large chunks of data. Perl passes
> parameters by reference by default. If you say
>
> mysub( $hugedata );
>
> then in mysub(), $_[ 0 ] is actually a reference (much like reference
> parameters in C++ but _not_ like what's called a (hard) reference in Perl
> (references in Perl are similar to pointers in C) to $hugedata. That
> is you can alter $hugedata by altering $_[ 0 ]. You can say that
> $_[ 0 ] is an alias for $hugedata.
>
> As the idiom goes, we often make it seem like passing by value by saying
>
> sub mysub {
> my ( $data ) = @_;
> }
>
> or the generally slightly stupid my $data = shift;
>
> Here we _assign_ the value of $_[ 0 ] to $data, and so copy the data (from
> eg. $hugedata).
>
> You don't _have_ to do that, if you're passing huge data around in
parameters.
>
> The main reason for my ( $param ) = @_; is usually clarity and the only
> sane reason for my $param = shift; is if you wanna alter @_ in order
> to pass the rest of it to say map() og grep() or something. This is
> be common in methods, where $_[ 0 ] will always be the object/class.
>
> > sub pass_subroutine {
> > my $var = shift; #will this work if someone does
> > ass_subroutine( \$your_var ) ???
> > }
> >
> > well will it work? or some special syntax is needed?
>
> I've no idea, what the problem would be? Why don't you just try?
>
> --
> Jakob
------------------------------
Date: Sun, 24 Jun 2001 08:41:27 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: passing variables the 'right' way
Message-Id: <slrn9jbnvn.blt.tadmc@tadmc26.august.net>
Aman Patel <patelnavin@icenet.net> wrote:
>thanks jakob, that was really helpfull, thats why sometimes if i try to
>access, $_ in a subroutine, it doesnt turn up, i have to do a $_[0] in order
>for it to work.
$_ and $_[0] are completely different variables. They have nothing
to do with each other, despite have similar-looking names.
$_ is a scalar variable that stands by itself.
$_[0] is a scalar variable that is an element in the array named @_.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 24 Jun 2001 13:25:57 GMT
From: rolf.krahl@gmx.net (Rolf Krahl)
Subject: Re: passing variables the 'right' way
Message-Id: <9h4pp5$2sa$5@rotkraut.de>
In article <9h42rq$c2bnl$1@id-93885.news.dfncis.de>,
"Aman Patel" <patelnavin@icenet.net> writes:
>
> how can we do the same thing in perl?? is it like this:
>
> my $var = slurp_a_file; #loads a big file,
> pass_subroutine( \$var );
It is.
> if i am right about the above code, how do we accept references in the
> subroutine i.e.
> sub pass_subroutine {
> my $var = shift; #will this work if someone does
> #pass_subroutine( \$your_var ) ???
> }
>
> well will it work? or some special syntax is needed?
Yes, it will.
But then, you must be aware, that $var in pass_subroutine() does not
contain the content of your file, but the reference to a variable,
that contains the file content. So in the subroutine, you must do
something like
| if ($$var =~ /^Foomagic/) { ...
to check whether the file starts with "Foomagic". Mind the double '$'
in the example.
--
Rolf Krahl <rolf.krahl@gmx.net>
------------------------------
Date: 24 Jun 2001 14:17:23 GMT
From: hudson@swcp.com (Tramm Hudson)
Subject: Re: passing variables the 'right' way
Message-Id: <9h4spj$2l0$1@sloth.swcp.com>
[ Posted and cc'd to cited author ]
Aman Patel <patelnavin@icenet.net> wrote:
> char *large_variable = LOAD_A_FILE();
> pass_function( &large_variable );
> //this only passes the address, not the 20 >MB of data...
Actually, just calling pass_function(large_variable) would pass the
starting address of the data. In your example, you are passing in the
address of the variable large_variable, which results in a pointer to
the pointer being passed. You could only pass the entire data block if
you did something like:
struct wasteful_t {
char large_variable[ 20<<10 ];
} waste;
LOAD_A_FILE( waste.large_variable );
pass_function( waste );
since arrays are not passed by value unless wrapped in structures.
The LOAD_A_FILE function would only receive the address of
waste.large_variable[0], not the whole array. The pass_function,
however, would receive a copy of the entire structure which
would include a copy of the whole array.
> how can we do the same thing in perl?? is it like this:
>
> my $var = slurp_a_file; #loads a big file,
> pass_subroutine( \$var );
This will pass a reference to $var, as expected. But part of the
Perl magic is that all variables are passed by reference. So,
pass_subroutine($var) also passes a reference to $var. However,
if your subroutine does this:
pass_subroutine( $var );
sub pass_subroutine {
my $arg = shift;
...
Then you have copied the contents of $var into $arg and no longer are
dealing with the alias to $var. Since this is the standard idiom for
accepting parameters, the aliases are very seldom observed and many
programmers do not realize that all arguments are passed by reference.
If you want to continue to operate on the alias to $var, you can
either use $_[0] or create an named alias with for:
pass_subroutine( $var );
sub pass_subroutine {
for my $arg ($_[0]) {
# $arg is an alias for $var
...
}
You could also monkey with the symbol table, but that would start the
symbolic reference debates. Cue reference to:
http://perl.plover.com/varvarname.html
Tramm
--
o hudson@swcp.com hudson@turbolabs.com O___|
/|\ http://www.swcp.com/~hudson/ H 505.323.38.81 /\ \_
<< KC5RNF @ N5YYF.NM.AMPR.ORG W 505.986.60.75 \ \/\_\
0 U \_ |
------------------------------
Date: Sun, 24 Jun 2001 17:53:55 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: passing variables the 'right' way
Message-Id: <3b362917.4d1b$2d1@news.op.net>
Since several of the other followups seemed to totally miss the point
here, I thought I would post a short version:
In article <9h42rq$c2bnl$1@ID-93885.news.dfncis.de>,
Aman Patel <patelnavin@icenet.net> wrote:
>how can we do the same thing in perl??
This is done automatically in Perl for scalars. When you write
foo($x)
Perl internally passes a pointer to the value of $x.
There is no benefit to passing foo(\$x) instead.
For very large arrays or hashes, there may be a speed benefit, since
foo(@a)
foo(%h)
pass a very long list of scalars. foo(\@a) and foo(\%h) may be faster.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Sun, 24 Jun 2001 14:35:25 GMT
From: Arnar M Hrafnkelsson <addi@umich.edu>
Subject: Re: Possible to split GIF or JPG into 12 images?
Message-Id: <m3sngqosm6.fsf@steypa.ast.is>
dragnet@internalysis.com (Marc Bissonnette) writes:
> Hello all;
>
> I am wondering if it is possible to use Perl to split an image into 9 (or
> whatever number you wanted) separate images? I.e. if you had image.jpg
> which was (apologies for bad ASCII art)
>
> --------
> | |
> | 1.jpg|
> | |
> --------
>
> to split it into:
>
> -------------------
> |1.jpg|2.jpg|3.jpg|
> |-----|-----|-----|
> |4.jpg|5.jpg|6.jpg|
> |-----|-----|-----|
> |7.jpg|8.jpg|9.jpg|
> -------------------
If you have the Imager module (which you can get of CPAN) installed this
splits it up into 9 subblocks (might skip the last column/row of image):
#!/usr/bin/perl -w
use Imager;
$img = Imager->new();
$img->read(file=>"foo.jpg") or die $img->errstr();
$xstep = int( $img->getwidth()/3 );
$ystep = int( $img->getheight()/3 );
for $ino (1..9) {
my $gridx = ($ino-1)%3;
my $gridy = int($ino-1)/3;
my $cut = $img->crop(left => $gridx*$xstep,
top => $gridy*$ystep,
width => $xstep,
height => $ystep);
$cut->write(file=>"foo_$ino.jpg");
}
The module can also handle other formats than jpeg if you need them.
-- Arnar
------------------------------
Date: Sun, 24 Jun 2001 08:23:10 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regular Expressions == How to use grep ?
Message-Id: <slrn9jbmte.bkb.tadmc@tadmc26.august.net>
Minh Van Le <mvanle@dingoblue.net.au> wrote:
>i need clarity on what is meant by Regular Expressions.
It is more accurate to call it "pattern matching", particularly in
a Perl context, as Perl's regular expressions are no longer strictly
"regular". (memory is disallowed in the definition of "regular",
Perl's memory parenthesis break the "no memory" rule).
The term "regular expression" is borrowed from language theory,
also part of "set theory" from straight mathematics.
"regular expressions" correspond to "regular grammars". That is,
a regular expression can be written that will accept strings
that are in a regular language.
"regular grammars" are the simpliest of the 4 classifications of
languages in the "Chomsky hierarchy". Most full-up programming
languages for instance are in the "next" level up, known as
"context free grammars".
>would i be wrong in saying that regular expressions is some pseudo code,
Yes, you would be wrong. It is real code. It runs. It does what
it is supposed to do. No "pseudo" there.
>or way of thinking,
It helps in getting regular expressions to work if you think
the "right way".
In other words, thinking like a finite state automata helps
with getting pattern matching to do What You Want.
See "How Regexes Work" for more info on regexs as state machines:
http://www.plover.com/~mjd/perl/Regex/
>or some adopted standard ?
Only a defacto standard, aside from POSIX, I think.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 24 Jun 2001 15:02:09 GMT
From: "Ron Hartikka" <ronh@iainc.com>
Subject: Re: Regular Expressions == How to use grep ?
Message-Id: <RhnZ6.13438$s25.216305@typhoon.mw.mediaone.net>
A regular expression is a "word" in a _language_ that you use to describe
strings.
The book tells you what re's are, how to use them, and how programs,
including Perl, process them.
Yes, the book talks about how to use (any) grep (including Perl's grep)
which stands for Global Regular Expression Print, according to the book.
% grep b.g filename
The period (.) means 'any single character' in the regular expression
language.
In the regular expression language, "b.g" describes any and every string
that:
starts with any sequence of characters whatsoever - including 'no
characters'
contains a 'b'
followed by any single character
followed by a 'g'
and ends with any sequence of characters whatsoever - including 'no
characters'
Hope this helps you. The book will help you with re's, grep and perl, though
it is not ideal for beginners - I don't know what is.
Tips that may help you:
1) learn the meta characters (The period or dot (.) is the first one.)
2) learn to translate a regular expression to every day words as above
3) get a file you are familiar with and play with grep on it
4) read and re-read several descriptions of re's
"Minh Van Le" <mvanle@dingoblue.net.au> wrote in message
news:20010624.224402.1069755936.2205@dingoblue.net.au...
> i need clarity on what is meant by Regular Expressions. if i bought a book
> on regular expressions, eg. Mastering Regular Expressions by Oreilly &
> Assc., i won't be expecting the equivalent content of "how to use grep"
> would i ?
>
> would i be wrong in saying that regular expressions is some pseudo code,
> or way of thinking, or some adopted standard ?
------------------------------
Date: 24 Jun 2001 13:37:05 GMT
From: rolf.krahl@gmx.net (Rolf Krahl)
Subject: Re: require 'question'
Message-Id: <9h4qe1$2sa$6@rotkraut.de>
In article <9h49ro$bsopc$1@id-93885.news.dfncis.de>,
"Aman Patel" <patelnavin@icenet.net> writes:
> I saw this in the documentation: (perlfunc::require)
>
> Otherwise, demands that a library file be included if it hasn't
> already been included.
>
> Ok does this mean, that if i do this:
>
> &req_1;
> &req_2;
>
> sub req_1 {
> require "this_file";
> }
> sub req_2 {
> require "this_file";
> }
>
> will this_file to be loaded twice ????
No, it will not, since the second require does not load the file, that
have already been loaded.
Consider the following example:
| nuomi-> echo 'print "foo!\n";' > /tmp/foo.pl
| nuomi-> perl /tmp/foo.pl
| foo!
| nuomi-> perl -w
| &req_1;
| &req_2;
| &req_1;
|
| sub req_1 {
| print "Bar 1\n";
| require "/tmp/foo.pl";
| }
|
| sub req_2 {
| print "Bar 2\n";
| require "/tmp/foo.pl";
| }
that will produce this output:
| Bar 1
| foo!
| Bar 2
| Bar 1
Mind, that "foo!" is only printed once from within the first call of
req_1.
--
Rolf Krahl <rolf.krahl@gmx.net>
------------------------------
Date: Sun, 24 Jun 2001 14:24:27 +0300
From: "Suraj Siddique" <surajsid@sharbatlyvillage.com.sa>
Subject: some one help me Can't locate object method "connect" via package "DBI".
Message-Id: <993388103.29085@news>
how can i solve this while i compile with perlcc
mail to surajsid@tri.net.sa
------------------------------
Date: Sun, 24 Jun 2001 08:35:42 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: what would be better? (lots of files vs 1 file)
Message-Id: <slrn9jbnku.bkb.tadmc@tadmc26.august.net>
Aman Patel <patelnavin@icenet.net> wrote:
>I am designing a flat file DB system for maintaing members and their related
>information.
>
>What do you think?
>1) Should there be 1 file which contains all records of the members, which
>requires opening and parsing of the whole file, even if i want to load a
>single record. But there is only 1 file.
If you maintain an index into the file, then it does _not_ require
parsing the whole file when querying, only when indexing.
If you use a Real Database, the DB will do the indexing for you.
>2) Should there be millions of files
Many file systems will barf with that many files in a single
directory, and just listing the files will be a performance dog.
>which contain different records of
>members, load only the file that you want the member details for. (my
>choice). [There is a drawback here to, the filesystem should be handle the
>lot of files with ease, with equally fast IO on the lotaa files].
>
>let me know what you guys think.
I think you should use a Real Database (eg. mySQL) if you are going
to really have millions of records to query against.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 24 Jun 2001 09:10:36 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: what would be better? (lots of files vs 1 file)
Message-Id: <%mnZ6.119$d43.1898@newsfeed.slurp.net>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrn9jbnku.bkb.tadmc@tadmc26.august.net...
>
> Many file systems will barf with that many files in a single
> directory, and just listing the files will be a performance dog.
more than a performance dog, 'ls' will fail completely on Linux, AIX4, and
other *nices. 'rm' will also fail, unless you go up a step and rm -rf the
entire directory, or do rm's on wildcarded filenames to limit the set to be
removed.
as you said to the OP, trying to grow your own database, unless you are
studying databases, is a stupid exercise when there are so many well
designed, working ones available for a download.
------------------------------
Date: Sun, 24 Jun 2001 17:18:07 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: what would be better? (lots of files vs 1 file)
Message-Id: <3B361E48.7432F94A@rochester.rr.com>
Aman Patel wrote:
>
> I am designing a flat file DB system for maintaing members and their related
> information.
>
> What do you think?
> 1) Should there be 1 file which contains all records of the members, which
> requires opening and parsing of the whole file, even if i want to load a
> single record. But there is only 1 file.
> 2) Should there be millions of files which contain different records of
> members, load only the file that you want the member details for. (my
> choice). [There is a drawback here to, the filesystem should be handle the
> lot of files with ease, with equally fast IO on the lotaa files].
...
Another alternative that would probably work well for you would be a
hash tied to a dbm-type file (DB_File, gdbm, ndbm, etc). See perldoc -f
dbmopen. This will permit lots of data (millions of keys) to be
efficiently stored and retrieved via a keys. For simple applications
(like those which could be addressed by a "flat file"), it is simple to
learn and use. For more complicated situations (involving several flat
files with relationships), it is no substitute for a full-blown
database. A few caveats: dbm-style tied hashes are typically not
binary-portable from one computer to another; if more than one process
accesses the data simultaneously, you will need to establish your own
locking protocol (of course, that is true with a flat file too); and
only strings (no references) can be stored (but see the MLDBM module for
ways around that).
--
Bob Walton
------------------------------
Date: 24 Jun 2001 06:51:50 -0700
From: aougav@hotmail.com (Zur Aougav)
Subject: Re: Why does this split not work?
Message-Id: <bccc87cc.0106240551.48018ea8@posting.google.com>
tuxy <nospam@cfl.rr.com> wrote in message news:<3B2F8801.3473B055@cfl.rr.com>...
> I'm trying to split a pretty large buffer (>1000 lines) into sections
> based on a line that looks like
>
> NAME Jane Doe
>
> The file is a series of name-values like
>
> NAME Jane Doe
> AGE 21
> ADDRESS Anytown USA
> !
> NAME John Smith
> .
> .
>
>
>
> so I'm using something like
>
> my @people=split /^\s*NAME\s+/m,$buf;
>
> and I'm getting very odd results. It consistently fails with this
> message:
>
> Use of uninitialized value in split at datax.pm line 447, <IN> line
> 21 (#1)
> ...
> By the way, the resultant array is one element which contains the entire
> buffer, even though there are many lines that meet the regex criteria.
> ...
Can we try something else?
How do you get $buf? $buf has all the file into it? You say "the
resultant array is one element...", so I can assume all data in $buf.
But how? If each "line" ends with different chars and you use chomp...
you end up exactly as you said: one element which contrains the entire
buffer.
You can try
open(INPUT,"<yourfile") || die;
my $buf;
while(<INPUT>) {
chomp($_); # just a test. Clear ends of "line"
$buf .= $_ . "\n"; # if you don't add "\n", you end up with
1 element!
}
close(INPUT);
Please post your result here. Thanks,
Zur
------------------------------
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 1183
***************************************