[22165] in Perl-Users-Digest
Perl-Users Digest, Issue: 4386 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 11 21:05:43 2003
Date: Sat, 11 Jan 2003 18:05:08 -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 Sat, 11 Jan 2003 Volume: 10 Number: 4386
Today's topics:
calculate regexp? <spam@oblomov.org>
Re: calculate regexp? <admin@-NOSPAM-2host.com>
Getting total rows in a column using DBI & mySQL.... (krakle)
Re: Getting total rows in a column using DBI & mySQL... (Tad McClellan)
Re: How does one determine why perl prog runs so slow?? <uri@stemsystems.com>
Re: How does one determine why perl prog runs so slow?? (Tony L. Svanstrom)
Re: How does one determine why perl prog runs so slow?? (Tad McClellan)
Re: How does one determine why perl prog runs so slow?? ctcgag@hotmail.com
Re: How does one determine why perl prog runs so slow?? <uri@stemsystems.com>
Re: How does one determine why perl prog runs so slow?? (Tony L. Svanstrom)
Re: how to print a hash (Tad McClellan)
Re: how to redirect STDIN to such place like /dev/null Andrew Lee
Re: how to redirect STDIN to such place like /dev/null <krahnj@acm.org>
Re: how to redirect STDIN to such place like /dev/null (Tad McClellan)
Re: Is it safe to return a reference to local or lexica Andrew Lee
Re: Is it safe to return a reference to local or lexica <mgjv@tradingpost.com.au>
Re: Matching entries in lists (h\)
Re: muli-spaced fields and split() (Tad McClellan)
Re: parsing a textarea field (newsman)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 12 Jan 2003 01:30:36 +0100
From: oblomov <spam@oblomov.org>
Subject: calculate regexp?
Message-Id: <20030112013036.5b43987e.spam@oblomov.org>
is there any software that calculates a regexp based possible matches?
example:
[string1].string2(string3)]
[string1] string2(string3)]
karl
------------------------------
Date: Sat, 11 Jan 2003 18:01:34 -0800
From: "2Host.com - Robert" <admin@-NOSPAM-2host.com>
Subject: Re: calculate regexp?
Message-Id: <3E20CC7E.F78CE98F@-NOSPAM-2host.com>
oblomov wrote:
>
> is there any software that calculates a regexp based possible matches?
>
> example:
>
> [string1].string2(string3)]
> [string1] string2(string3)]
>
> karl
I'm not sure what you mean. How many times there's a match for a regular
expression, or?
If you want to know how many times it was successful, you can do
something like:
my $count = 0;
$count += (/fieldtomatch/); # Modify to your needs, of course.
print $count;
If you meant something else, you'll have to elaborate.
--
Regards,
Robert McGregor - Email: admin@(remove)2host.com. Phone: 530-941-0690
Server admin, support & programing for shared & dedicated web servers
Secure, reliable hosting you expect and deserve! http://www.2host.com
------------------------------
Date: 11 Jan 2003 15:16:45 -0800
From: krakle@visto.com (krakle)
Subject: Getting total rows in a column using DBI & mySQL....
Message-Id: <237aaff8.0301111516.666abf17@posting.google.com>
Hello.
I'm writing a script and I need a feature to get the total number of
rows in a mySQL column usign DBI. I'm using DBI with the "mysqlPP"
driver and ActivePerl on WindowsXP Pro. I have 7 rows in my "userid"
column. When I use $sth->rows in my script it always returns 0. When I
use the SAME SQL statement via the mySQL monitor I get 7 rows which is
correct. I've looked at and tried many examples but it always returns
0. I'm very lost. here is the script I am using:
use strict;
use DBI;
my $dbhost = "localhost";
my $dbport = 3306;
my $dbname = "mydb";
my $dbtable = "users";
my $dbuser = "usern";
my $dbpass = "passw";
my $dbdriver = "mysqlPP";
my $dbh = DBI->connect("DBI:$dbdriver:$dbname:$dbhost:$dbport",
$dbuser, $dbpass) or die "Can't connect to database: $DBI::errstr\n";
my $sql = qq{ SELECT COUNT(*) FROM users; };
my $sth = $dbh->prepare($sql);
$sth->execute or die "Can't execute SQL statement: $sth->errstr\n";
print $sth->rows;
$sth->finish();
$dbh->disconnect();
The Database is created and working. The table is created and has 7
records. $sth->rows returns 0 everytime from the script. But when I
run the SQL statment from the command line I get 7.
------------------------------
Date: Sat, 11 Jan 2003 18:03:58 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Getting total rows in a column using DBI & mySQL....
Message-Id: <slrnb21c7d.118.tadmc@magna.augustmail.com>
Pinocchio <krakle@visto.com> wrote:
> I'm writing a script and I need a feature to get the total number of
> rows in a mySQL column usign DBI.
> When I use $sth->rows in my script it always returns 0.
You should read the documentation for the function that you are using:
Returns the number of rows affected by the last row affecting
command
...
Generally, you can only rely on a row count after a *non*-"SELECT"
"execute"
...
use of the "rows" method or $DBI::rows with "SELECT" statements
is not recommended.
> I'm very lost.
That can happen when you sign a contract without reading it.
> my $sql = qq{ SELECT COUNT(*) FROM users; };
That is not a "row affecting command".
> my $sth = $dbh->prepare($sql);
> $sth->execute or die "Can't execute SQL statement: $sth->errstr\n";
>
> print $sth->rows;
print $sth->fetchrow_array;
or slice out the first array element:
print( ($sth->fetchrow_array)[0] );
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 11 Jan 2003 23:06:14 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <x77kdbffru.fsf@mail.sysarch.com>
>>>>> "TLS" == Tony L Svanstrom <tony@svanstrom.com> writes:
TLS> Uri Guttman <uri@stemsystems.com> wrote:
>> >>>>> "DP" == Dick Penny <penny1482@attbi.com> writes:
DP> However, I have offered before, and I still offer, to help or
DP> write revisions to the standard doc junk that comes with Perl, at
DP> least AS Perl.
>>
>> so where are your changes? have you posted patches to p5p? this group is
>> not in control of the perl docs. we do have input to the FAQ (thanx to
>> bdf). so you can do whatever you want but whining about no one listening
>> is even less useful than the family's whine.
TLS> It's easy to know how it's done, but if you don't you might think that
TLS> people just aren't interested when you're saying that you're willing to
TLS> help...
TLS> Just picture it yourself; you think that someone is going to turn up
TLS> saying "sure, I'm incharge, just rewrite the txt-files and send them to
TLS> me", but instead you end up having to learn what the heck a patch and
TLS> cvs and god(s of your choice)knowswhat is.
then that is a gauge of your real interest to help. clpm is not directly
involved with maintaining the perl docs. joining p5p or talking to
activestate is the minimum you have to do. just whining "i can do
better" is not useful nor will anyone believe it until you show results.
i choose to help here and my results are known. penny has no track
record anywhere and so his word isn't worth much here nor in the area he
is concerned about which is the perl docs.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Sat, 11 Jan 2003 23:26:58 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <1fond29.4wl10ihsibduN%tony@svanstrom.com>
Uri Guttman <uri@stemsystems.com> wrote:
> i choose to help here and my results are known. penny has no track
> record anywhere and so his word isn't worth much here nor in the area he
> is concerned about which is the perl docs.
True, but it sounds like no one even told him where to go find any real
information about how to help out with the doc-writing; which is a
common "feature" of many open source-projects... people that know how to
do it won't tell others, because they think that if people can't find
out themselfs then they aren't good enough to be of any help.
In the long run that'll just hurt open source.
--
# Per scientiam ad libertatem! // Through knowledge towards freedom! #
# Genom kunskap mot frihet! =*= (c) 1999-2002 tony@svanstrom.com =*= #
perl -e'print$_{$_} for sort%_=`lynx -source svanstrom.com/t`'
------------------------------
Date: Sat, 11 Jan 2003 16:38:58 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <slrnb21782.sc.tadmc@magna.augustmail.com>
Dick Penny <penny1482@attbi.com> wrote:
> I TOTALLY agree with the 'abernathey family'
> response.
So long then.
> It is too bad, because when the Uri's and Tad's of the world choose to help,
> they have been a great help.
I choose to not help trolls, nor troll admirers.
> I encourage them to continue to do so.
That won't be happening for your posts anymore.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 12 Jan 2003 01:30:39 GMT
From: ctcgag@hotmail.com
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <20030111203039.640$9v@newsreader.com>
R.Mariotti@FinancialDataCorp.com (Bob Mariotti) wrote:
> Honestly! I HAVE searched this group, other perl sites, perlfaqs, etc
> and I cannot find anything that actually covers this topic.
You must be a rather incompetent searcher.
...
> Now - on the new OS version with Perl 5.8 the same program using the
> same data files and database took over FORTY EIGHT HOURS to complete.
>
> I ruled our a MySQL issue because if I comment out the MySQL access
> the run time is still incredibly slow.
>
> So, here's my question for the perl guru's that I could not find in
> the faqs or other resources:
>
> How does one go about determining what may be the cause of this
> unacceptable performance?
I think you were already on the right track. You can use a profiler,
but I often find them more annoying than effective.
Start by putting an exit command after any initialization but before the
start of the main loop. If that finishes quick, remove exit and put a
'next;' as the first statement in the loop. If this takes too long, it
must be reading the file that is the slow part. Otherwise, move the
'next;' to just after the pattern match. Still fast? Move it to just
before the mysql lookup, then just after it, etc. (It helps to take only a
random 1/100th of the normal input file, so each trial takes a minute
rather than an hour.)
> I researched the module Benchmark but that
> only measures time. Where should one start? Is this an issue that
> others have experienced (I'm sure) and what was done to overcome it?
Devel::DProf can tell you how much time each subroutine takes,
but if your subs are large (or you don't use any), that doesn't necessarily
narrow the search down much.
Devel::SmallProf will (attempt to) tell you how much time each line
takes, but it seems flaky to me (on 5.6).
Both of them will make your program run much, much slower. DProf
can also consume vast quanities of disk space. So for either of these
you will also want to trim the input file to much smaller testset.
> I will be eagerly awaiting any and all suggestions.
I'm eager to hear what slowed it down so much.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Sun, 12 Jan 2003 01:54:59 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <x73cnzf7yl.fsf@mail.sysarch.com>
>>>>> "TLS" == Tony L Svanstrom <tony@svanstrom.com> writes:
TLS> Uri Guttman <uri@stemsystems.com> wrote:
>> i choose to help here and my results are known. penny has no track
>> record anywhere and so his word isn't worth much here nor in the area he
>> is concerned about which is the perl docs.
TLS> True, but it sounds like no one even told him where to go find any real
TLS> information about how to help out with the doc-writing; which is a
TLS> common "feature" of many open source-projects... people that know how to
TLS> do it won't tell others, because they think that if people can't find
TLS> out themselfs then they aren't good enough to be of any help.
TLS> In the long run that'll just hurt open source.
i don't recall his offer but i may have missed it. but then it is very
easy to search the web to find who manages the perl docs. not having
done that is a bad sign. perl.org has all sorts of info on the perl
community. lists.perl.org has all the major mailing lists including
p5p. so i don't buy the answer that it is hard to find the right
place. most open source projects have a web site where you can find the
resources and people involved. now joining a project and contributing
can be a different matter.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Sun, 12 Jan 2003 02:00:03 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <1fonk8v.1nxx06d1dxulogN%tony@svanstrom.com>
Uri Guttman <uri@stemsystems.com> wrote:
> >>>>> "TLS" == Tony L Svanstrom <tony@svanstrom.com> writes:
>
> TLS> Uri Guttman <uri@stemsystems.com> wrote:
> >> i choose to help here and my results are known. penny has no track
> >> record anywhere and so his word isn't worth much here nor in the area he
> >> is concerned about which is the perl docs.
>
> TLS> True, but it sounds like no one even told him where to go find any
> TLS> real information about how to help out with the doc-writing; which
> TLS> is a common "feature" of many open source-projects... people that
> TLS> know how to do it won't tell others, because they think that if
> TLS> people can't find out themselfs then they aren't good enough to be
> TLS> of any help. In the long run that'll just hurt open source.
>
> i don't recall his offer but i may have missed it. but then it is very
> easy to search the web to find who manages the perl docs. not having
> done that is a bad sign. perl.org has all sorts of info on the perl
> community. lists.perl.org has all the major mailing lists including
> p5p. so i don't buy the answer that it is hard to find the right
> place. most open source projects have a web site where you can find the
> resources and people involved. now joining a project and contributing
> can be a different matter.
You are of course correct, but... lately I've really been in a "why
aren't people pulled in into open source more actively"- mood. =)
--
# Per scientiam ad libertatem! // Through knowledge towards freedom! #
# Genom kunskap mot frihet! =*= (c) 1999-2002 tony@svanstrom.com =*= #
perl -e'print$_{$_} for sort%_=`lynx -source svanstrom.com/t`'
------------------------------
Date: Sat, 11 Jan 2003 17:07:57 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: how to print a hash
Message-Id: <slrnb218ud.sc.tadmc@magna.augustmail.com>
Jim Marvel <semaj_levram@worldnet.att.net> wrote:
> while (@fetched_row = $sth->fetchrow_array) {
> $record_num = shift @fetched_row;
> $records{$record_num} = \@fetched_row;
> print OUTFILE "record num = $record_num\tfetched row =
> $records{$record_num}\n\n";
> }
> #how do I print the hash instead of printing "ARRAY(stuff)"
Did you happen to notice that the "stuff" was the same for every one?
By applying "Use Rule 1" from:
perldoc perlreftut
print "@array"; # pretend it is a plain array
print "@{}"; # replace the array _name_ with a block
print "@{$records{$record_num}}"; # fill the block with a ref to array
Once you get that fixed, you will discover that you have
yet another problem.
Every array will have the same contents!
Each will contain the values from the last row returned from
the query. This is because you took a reference to the _same_
array each time through the loop.
There are two ways to fix that problem:
1) use a new lexical array each time through the loop,
and then apply "Make Rule 1" (as you do in the code above):
while ( my @fetched_row = $sth->fetchrow_array) {
^^
^^ a fresh new array for each loop iteration
2) use a new anonymous array each time, copy the values
from your named array to the anon one ala "Make Rule 2":
$records{$record_num} = [ @fetched_row ];
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 11 Jan 2003 18:36:54 -0500
From: Andrew Lee
Subject: Re: how to redirect STDIN to such place like /dev/null ??
Message-Id: <2aa12vso04d3q6vid5npt5cfhngkiv7bmg@4ax.com>
On Sat, 11 Jan 2003 14:28:32 -0600, tadmc@augustmail.com (Tad
McClellan) wrote:
>Andrew Lee <AndrewLee> wrote:
>
>> Eeek. If you are looking for two newlines -- just look for that :
>>
>> while ( <STDIN> ) {
>> last if /\n\n/;
>> }
>
>
>That pattern can never match.
>
>The OP's program did not change the value of $/
Yep -- my error.
Not sure what I was thinking.
------------------------------
Date: Sun, 12 Jan 2003 00:09:01 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: how to redirect STDIN to such place like /dev/null ??
Message-Id: <3E20B17C.9B2F2360@acm.org>
Andrew, Lee wrote:
>
> On Sun, 12 Jan 2003 02:46:26 +0800, "oooooops" <oooooops@163.com>
> wrote:
>
> >#!/usr/bin/perl -w
> >
> >use strict;
> >
> >my $i;
> >open (DEST, ">>/home/test/testfile.dat")||die "$!";
> >$i=0;
> >OUTER: while (<STDIN>){
> > if ($_ eq "\n" && $i==1){
> ># close STDIN;
> > last OUTER;
> > }elsif($_ eq "\n" && $i==0){
> > $i=1;
> > }else{
> > $i=0;
> > }
> > print DEST $_;
> >}
> >close (DEST);
>
> Eeek. If you are looking for two newlines -- just look for that :
>
> while ( <STDIN> ) {
> last if /\n\n/;
> }
Unless the you change the value of the input record separator ($/) there
is no way that the diamond operator will store two consecutive newlines
in $_.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 11 Jan 2003 18:11:09 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: how to redirect STDIN to such place like /dev/null ??
Message-Id: <slrnb21ckt.168.tadmc@magna.augustmail.com>
Andrew Lee <AndrewLee> wrote:
> Yep -- my error.
Guess we're even then :-)
(though my mistake was worse than yours, so maybe you are a little ahead)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 11 Jan 2003 18:27:17 -0500
From: Andrew Lee
Subject: Re: Is it safe to return a reference to local or lexical data?
Message-Id: <a4912vg6qt7damk4771f011bdispnhabdc@4ax.com>
On Wed, 25 Dec 2002 00:11:54 +1100, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:
[snip]
>
>We could have referred to perldsc, perllol, and perlref, but I doubt
>very much that anyone with a serious question about how things work gets
>shouted down very much here. There are several levels of helpfulness,
>but very few people "shout down" others.
>
>I do hope we're not going to get into one of these "clp.misc is such an
>unhelpful and hostile place" discussions, because I'm thoroughly sick of
>those. The only thing they accomplish is that several people sharpen
>their score files.
I assure you I am not trying to make a point about the usefulness of
cplm.
My point is that code in a FAQ about references should demonstrate the
use of references and not generate a question about printing. I
suspect the code example was jotted down quickly without the
consideration that it might be confusing for some.
Documentation is too often obtuse (in general). Perl's documentation
is excellent and should be as clear as possible .... it often is --
but sometimes isn't.
------------------------------
Date: Sun, 12 Jan 2003 10:51:11 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Is it safe to return a reference to local or lexical data?
Message-Id: <slrnb21bff.2fv.mgjv@martien.heliotrope.home>
On Sat, 11 Jan 2003 18:27:17 -0500,
Andrew Lee <> wrote:
> On Wed, 25 Dec 2002 00:11:54 +1100, Martien Verbruggen
><mgjv@tradingpost.com.au> wrote:
>
> [snip]
[more snip]
> Documentation is too often obtuse (in general). Perl's documentation
> is excellent and should be as clear as possible .... it often is --
> but sometimes isn't.
Patches are always welcome :)
Martien
--
|
Martien Verbruggen | The Second Law of Thermodenial: In any closed
| mind the quantity of ignorance remains
| constant or increases.
------------------------------
Date: Sun, 12 Jan 2003 00:14:46 +0100
From: "Michael Peuser \(h\)" <post@mpeuser.de>
Subject: Re: Matching entries in lists
Message-Id: <avq8f7$45g$04$1@news.t-online.com>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> schrieb im Newsbeitrag
news:avpaej$pdk$1@mamenchi.zrz.TU-Berlin.DE...
> Michael Peuser \(h\) <post@mpeuser.de> wrote in comp.lang.perl.misc:
> > I like the idea of the above soulution very much. The importance to
consider
> > run time behaviour of Perl scripts is generally not very much
appreciated,
> > because Perl normally manipulates MB of data in a flash. It becomes
> > important when you shuffle around GB, or even just 100 MB through the
memory
> > for several times.
> >
> > The standard solution for the above problem would be not a hash but an
> > array, sorted according to telephone number and accessing it by binary
> > search. Be N the length of that list a*ld N would be the time needed,
'a'
> > beeing the time for accessing an array.
> Binary search should certainly be considered, but I wouldn't call it the
> standard solution. If anything, the standard solution for a prefix
problem
> is a tree structure, which could be implemented quite efficiently for
> this task since the alphabet ('0' .. '9') is short and compact.
Both have a lookup time of ld N, so it is mostly second choice, as hashes
and arrays are build in data structures in Perl and trees are not. Trees
also can prove even more usefull when you have an idear about the
distribution of the numbers to test.
One might also think of an unconventional implementation with 10-fold
branching; this is somewhat of a combination between tree and hash
access....
>
> > The above soulution takes h*M where M ist the mean length of a requested
>
> No, M is the mean number of digits that must be chopped off until it can
> be decided whether the number is in the table. This will be less than
> the length of the requested number in most cases.
True! Most (or all?) Numbers will match in the end. I thought of non
matching numbers and in that case there is no early indicator for it with
hashes.
> > telefon number and 'h' the time for a hash access, 'h' upto 10 times
slower
>
> Ten times? Benchmarks show the relation between 1:2 and 1:3, closer to
1:2.
> > than 'a' (though it depends on various circumstances, read the,man page
for
> > pre-allocating hash space, e.g.).
>
> Where does pre-allocation come in? The hash is fixed in the situation
> we're talking about.
I guessed from earlier experiences; 1:3 seems o.k. I am not sure how
effective the internal hash table is organized when you do not tune its
size (e.g. %table = 1000000)
>
> > So I should expect for 10 digit telephone numbers the clasical binary
search
> > to be faster up to a list of 2**20 = 1 Mio entries.
>
> It may or may not be faster. I don't think much can be said about the
> relationship unless we know more about the distribution of keys, the
> fixed keys in the lookup table as well as the numbers that will be
> queried.
True! Both methods are quite close. I even suspect that the actual
performance will be determined by the extra code necessary to organze number
stripping or index arithmetik....
Kindly Mike
------------------------------
Date: Sat, 11 Jan 2003 17:25:02 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: muli-spaced fields and split()
Message-Id: <slrnb219ue.sc.tadmc@magna.augustmail.com>
bad_knee <bl8n8r@yahoo.com> wrote:
>> Show us your code thus far. What do you want to extract from
>> your logs?
Who said that?
You should provide an attribution when you quote someone.
> It's at work right now. I believe tr is what I was looking for.
No it isn't.
> Andre menioned split() is "implicit".
There are 4 different ways of calling split(), as described
in perlfunc.pod.
When you call split() with no arguments, the default arguments
will be used. split() has _two_ defaults, a default pattern
and a default string to split up.
The third paragraph of (perldoc -f split) says what the
default string-to-split is.
The third paragraph also describes the default pattern.
> I think that means split()
> automatically ignores the extra spaces.
No, it means "that the delimiter (sic) may be longer than one character",
ie. _consecutive_ whitespace characters form a field separator.
> This is odd.
Not if you read the manual for the function that you are using.
> I was on
> Solaris coding the perl script, and noticed the problem with
> the extra spaces throwing my field index off, however on linux,
> this doesn't happen. I need to take a closer look at my code.
I think so.
Might it be that the split pattern you used was different
in the two different runs?
> The problem must lie elsewhere unless the two versions of perl
> I'm using are different.
It is likely cause by different versions of your Perl code,
split / /;
vs.
split; # or split ' ';
perhaps.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 11 Jan 2003 17:31:12 -0800
From: news@youplusme.com (newsman)
Subject: Re: parsing a textarea field
Message-Id: <81fbdcf7.0301111731.35b786e0@posting.google.com>
dmalhotr2001@yahoo.com (Dhruv) wrote in message news:<b6d0b0b.0301110102.3d243f23@posting.google.com>...
> Hi,
>
> My question is that If I have a textarea field
>
> i.e.
> -----
> hello
> how
> are
> you
> ----
>
> and I would like to take each word and dump into a database,
> extracting each bit by a newline character.
>
> For example
>
> hello, how, are, you would be different fields in the database.
>
> 1. How would I go about doing this?
> 2. Is there a tutorial(s) that would explain this or something
> similar?
>
> Thanks
>
> Dhruv
use CGI;
$query = new CGI;
$data = param('in_variable_name'); # what ever you called the passed variable
@lines = split /\n/ , $data;
------------------------------
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 4386
***************************************