[30178] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1421 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 4 14:09:49 2008

Date: Fri, 4 Apr 2008 11:09:06 -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           Fri, 4 Apr 2008     Volume: 11 Number: 1421

Today's topics:
    Re: binding parameters (timestamp) with DBD::Sybase <parv_@yahooWhereElse.com>
    Re: Create two-dimensional Array from string <pjfalbe@gmail.com>
    Re: Create two-dimensional Array from string <tzz@lifelogs.com>
    Re: Creating a 'load simulator' by calling Perl Program <glex_no-spam@qwest-spam-no.invalid>
    Re: Creating a 'load simulator' by calling Perl Program <pgodfrin@gmail.com>
        FTP problem slinges@gmail.com
    Re: FTP problem <smallpond@juno.com>
    Re: Is substr only way of getting nth character of stri <clarjon1@null.wikimedia.gmail.invalid.com>
    Re: mismatch between Perl 5.6 and Perl 5.8 in printing  <tzz@lifelogs.com>
    Re: New errors of export image format <glex_no-spam@qwest-spam-no.invalid>
        separating substitutions from an embedded perl in a ksh tazommers@yahoo.com
    Re: separating substitutions from an embedded perl in a <source@netcom.com>
    Re: separating substitutions from an embedded perl in a tazommers@yahoo.com
    Re: Spelling suggestions for common words - ispell, etc <tzz@lifelogs.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 04 Apr 2008 10:27:54 GMT
From: parv <parv_@yahooWhereElse.com>
Subject: Re: binding parameters (timestamp) with DBD::Sybase
Message-Id: <slrnfvc0ps.8lk.parv_@holstein.holy.cow>

in message <ft0trj$iou$1@news.acm.uiuc.edu>,
wrote Sharif Islam ...

> Thanks. But it seems now the datatype is getting set to VARCHAR:
>
> DBD::Sybase::st execute failed: Server message number=257 severity=16
> state=3 line=0 server=MSSQL procedure=MY_STORED_PROC text=Implicit
> conversion from data type char to timestamp is not allowed. Use the
> CONVERT function to run this query. at myscript.pl line 34.

Seems like the problem is with the stored procedure (either in
accepting the parameter or in the query sent to db) as the error
message is coming from the database server.


  - parv

-- 



------------------------------

Date: Fri, 4 Apr 2008 06:32:58 -0700 (PDT)
From: "pjfalbe@gmail.com" <pjfalbe@gmail.com>
Subject: Re: Create two-dimensional Array from string
Message-Id: <287d4280-d4b0-4e37-a7f7-2f138280b382@m3g2000hsc.googlegroups.com>

On Apr 3, 10:49 am, jjcass...@gmail.com wrote:
> On Apr 2, 1:21 pm, "pjfa...@gmail.com" <pjfa...@gmail.com> wrote:
>
> > I'm looking for the most efficient way to create a two dimensional
> > array from strings such as
>
> > MULTISET{ROW(1     ,'  3667 ','WARREN    ','OH'),ROW(2     ,'  2948
> > ','SHAKER HTS','OH')}
>
> > In this case MULTISET is a collection of rows from a DB.  What I want
> > todo is efficiently
> > transform into a 2-dimensional array,  where each row is an array.
> > And then collect those arrays
> > into 1 array of arrays.  I'm currently doing this but not very
> > efficiently.  Any help would be appreciated.
>
> Let Perl parse it for you. You can *eval* it.
>
> use Data::Dumper;
>
> sub ROW (@) { return [ @_ ]; }
>
> sub MULTISET (&) { return [ sort { $a->[0] <=> $b->[0] } shift()-
>
> >() ];  }
>
> # observe:
> my $multi_set = eval <<END_EVAL1;
> MULTISET{ROW(1     ,'  3667 ','WARREN    ','OH'),ROW(2     ,'
> 2948','SHAKER HTS','OH')}
> END_EVAL1
>
> print Dumper( $multi_set ), "\n";
>
> You could even define the two functions as below if you simply wanted
> the first field for ordering.
>

This works great!  Much better than all the sed'ing and splitting I
was doing.  For reference I'm doing a query like

select customer, multiset(select count(*), city, state
                             from orders A
                            where A.customer = orders.customer
                              and A.order_date = orders.order_date
                            group by 2,3)
  from orders
 where order_date = today;


With your transform I can now take the field returned from the
multiset and write to WriteExcel spreadsheet very easily.



------------------------------

Date: Fri, 04 Apr 2008 10:52:18 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Create two-dimensional Array from string
Message-Id: <86od8pd3d9.fsf@lifelogs.com>

On Fri, 4 Apr 2008 06:32:58 -0700 (PDT) "pjfalbe@gmail.com" <pjfalbe@gmail.com> wrote: 

pc> On Apr 3, 10:49 am, jjcass...@gmail.com wrote:
>> On Apr 2, 1:21 pm, "pjfa...@gmail.com" <pjfa...@gmail.com> wrote:
>> 
>> > I'm looking for the most efficient way to create a two dimensional
>> > array from strings such as
>> 
>> > MULTISET{ROW(1     ,'  3667 ','WARREN    ','OH'),ROW(2     ,'  2948
>> > ','SHAKER HTS','OH')}
>> 
>> > In this case MULTISET is a collection of rows from a DB.  What I want
>> > todo is efficiently
>> > transform into a 2-dimensional array,  where each row is an array.
>> > And then collect those arrays
>> > into 1 array of arrays.  I'm currently doing this but not very
>> > efficiently.  Any help would be appreciated.
>> 
>> Let Perl parse it for you. You can *eval* it.
>> 
>> use Data::Dumper;
>> 
>> sub ROW (@) { return [ @_ ]; }
>> 
>> sub MULTISET (&) { return [ sort { $a->[0] <=> $b->[0] } shift()-
>> 
>> >() ];  }
>> 
>> # observe:
>> my $multi_set = eval <<END_EVAL1;
>> MULTISET{ROW(1     ,'  3667 ','WARREN    ','OH'),ROW(2     ,'
>> 2948','SHAKER HTS','OH')}
>> END_EVAL1
>> 
>> print Dumper( $multi_set ), "\n";
>> 
>> You could even define the two functions as below if you simply wanted
>> the first field for ordering.
>> 

pc> This works great!  Much better than all the sed'ing and splitting I
pc> was doing.  For reference I'm doing a query like

pc> select customer, multiset(select count(*), city, state
pc>                              from orders A
pc>                             where A.customer = orders.customer
pc>                               and A.order_date = orders.order_date
pc>                             group by 2,3)
pc>   from orders
pc>  where order_date = today;

pc> With your transform I can now take the field returned from the
pc> multiset and write to WriteExcel spreadsheet very easily.

(checking it's not April 1)

Good god, you're going to use a custom parser instead of the nice DBI
interface I suggested?

my $array = $dbh->selectall_arrayref('your select statement goes here');

Even worse, it's a hacked-up eval-based parser that will fail miserably
if you look at it sideways, and performance is going to be miserable...
The parser is clever, but you should really consider submitting to
thedailywtf.com if you actually use it.

Ted


------------------------------

Date: Fri, 04 Apr 2008 11:19:27 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Creating a 'load simulator' by calling Perl Programs - or  Forking?
Message-Id: <47f6550f$0$89877$815e3792@news.qwest.net>

sheinrich@my-deja.com wrote:
[...]
> a module that I've written couple of months ago was for that very
> purpose.
> Basically your script will have to instantiate an PreforkAgent, tell
> it how many children to beget (degree of parallelization) and provide
> it with a couple of callbacks as means of communication.

Hu.. sounds pretty much like Parallel::ForkManager.


------------------------------

Date: Fri, 4 Apr 2008 06:15:55 -0700 (PDT)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: Creating a 'load simulator' by calling Perl Programs - or  Forking?
Message-Id: <d630ff0c-096f-4c14-accf-3994bd9257ca@i36g2000prf.googlegroups.com>

On Apr 4, 1:44 am, sheinr...@my-deja.com wrote:
> On Apr 4, 6:12 am, pgodfrin <pgodf...@gmail.com> wrote:
>
>
>
> > On Apr 3, 4:22 pm, xhos...@gmail.com wrote:
>
> > > pgodfrin <pgodf...@gmail.com> wrote:
>
> > > ...
>
> > > > Question #1: What is the proper way to execute the perl programs?
>
> > > You gave two examples, sequentially and in parallel.  Which one is
> > > appropriate depends on what kind of load you want to simulate, which in
> > > turn depends on why are you are doing the simulation.
>
> > > > Question #2: Is there a way to echo to the screen that the wait() is
> > > > happening and provide some indication of progress?
>
> > > > To clarify this question, I had originally tried:
> > > >   do {$x=wait; print ".";} until $x==-1;
>
> > > > Thinking I would get a period printed during the loop. (silly me -
> > > > wait only comes back when a child process dies...).
>
> > > So you do get a period printed, once per child-exit.  This is what I would
> > > want to do, anyway, but I seem to be in a philosophical minority in this
> > > regard (I hate progress indicators that merely indicate that the system
> > > clock is ticking, and nothing about the actual progress of the actual
> > > program.)  I'm not sure what you originally thought it might do instead.
> > > Periods to be printed as fast as Perl possible can print them?
>
> > > > Of course if this is much to complicated a way to so a simulated load,
> > > > then so be it - just a plain old fork and wait works fine... And I
> > > > could always remove the /dev/null and actually see the called programs
> > > > output, which will tell me that it's still running... But I was
> > > > curious if there is a more elegant or at least interesting way of
> > > > doing this?
>
> > > If the waiting program is still running, and is still waiting, then the
> > > program it is waiting on must still be running.  What other possibilities
> > > are there?
>
> > > If you really want the "time has not come to a halt" thing, then
> > > something like this:
>
> > > perl -le '$|=1; fork or do {sleep 4*$_; exit} foreach (1..3);  \
> > >   $SIG{ALRM}=sub{print "."; alarm 1}; alarm 1; \
> > >   do {$x=wait; print "$x";} until $x==-1; \
> > >   alarm 0'
> > > .
> > > .
> > > .
> > > 20287
> > > .
> > > .
> > > .
> > > .
> > > 20288
> > > .
> > > .
> > > .
> > > .
> > > 20289
> > > -1
>
> > > Xho
>
> > > --
> > > --------------------http://NewsReader.Com/--------------------
> > > The costs of publication of this article were defrayed in part by the
> > > payment of page charges. This article must therefore be hereby marked
> > > advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
> > > this fact.
>
> > Hi Xho,
> > As always - good points. I am looking to load up the system, so a
> > parallel simulation seems to be the best approach. And frankly, the
> > period printing was just a way to see that indeed something was
> > happening, but clearly and wholly unnecessary - although I did get a
> > chuckle over the time halting comment...
>
> > And anyway 'watch ps u' in anotehr session celarly shows me the
> > processes still running.
>
> > But - the question still remains - what's the best way to call other
> > perl programs? Exec, system or something else?
>
> > pg
>
> Hi pg,
>
> a module that I've written couple of months ago was for that very
> purpose.
> Basically your script will have to instantiate an PreforkAgent, tell
> it how many children to beget (degree of parallelization) and provide
> it with a couple of callbacks as means of communication.
> These callback routines may provide any task, execute it as you like
> and perform evaluation of results and logging.
> The module's initial purpose was it to generate as much load on a
> remote system as the local server would allow. You can however, setup
> a small number of children and even delay the task assignments without
> interfering with the former tasks.
> Children will live and be re-used until the job-queue is depleted.
>
> You might download the module fromhttp://www.atablis.com/temp/PreforkAgent.pm
> and give it a try.
>
> Cheers,
> Steffen
>
> It is rather easy to integrate

cool! I'll take a look...
phil


------------------------------

Date: Fri, 4 Apr 2008 08:08:47 -0700 (PDT)
From: slinges@gmail.com
Subject: FTP problem
Message-Id: <4e232be0-c670-48e1-9dde-1b1d88afc945@y21g2000hsf.googlegroups.com>

Hello,

in the past I used Net::FTP for ftp and had no problems, however if I
try to connect to a ftp url like
ftp://ftp.gimp.org/ I can't connect?

$ftp = Net::FTP->new($url, Debug=>1 [, Passive=>1]) or die 'cannot
conect';

Any ideas what the problem is?


------------------------------

Date: Fri, 4 Apr 2008 09:24:25 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: FTP problem
Message-Id: <1e932086-3d32-414e-83d7-21dac15b3764@8g2000hsu.googlegroups.com>

On Apr 4, 11:08 am, slin...@gmail.com wrote:
> Hello,
>
> in the past I used Net::FTP for ftp and had no problems, however if I
> try to connect to a ftp url likeftp://ftp.gimp.org/I can't connect?
>
> $ftp = Net::FTP->new($url, Debug=>1 [, Passive=>1]) or die 'cannot
> conect';
>
> Any ideas what the problem is?

try doing it like the doc:
or die "Cannot connect to $url: $@";

$@ is the error.


------------------------------

Date: Fri, 4 Apr 2008 12:50:56 +0000 (UTC)
From: Jonathan Clark <clarjon1@null.wikimedia.gmail.invalid.com>
Subject: Re: Is substr only way of getting nth character of string?
Message-Id: <ft587f$nob$1@registered.motzarella.org>

On Thu, 20 Mar 2008 18:10:30 -0800, Robbie Hatley wrote:

> 
> Given program X....
> in Cobol:    857 pages
> in C:         37 pages
> in C++:        5 pages
> in APL:      @&*%@#*$%*(%^*&@#*&%#@  (1/4 line of gibberish) In Perl:   
>  JustDo($what_I_mean)
>                or die "Sorry, Dave, I'm afraid I can't do that!";

Would you mind if I grabbed that for my sigmonster?


-- 
Clarjon1

Proud Linux User.
PCLinuxOS on Dell Inspiron 1501,1 Gig ram,80 Gig Hard drive
1.7gHz AMD Athlon 64bit dualcore processor
Contact:
Gmail/gtalk:  clarjon1
irc: #pclinuxos,#pclinuxos-support,##linux on freenode
The Abrams' Principle:
	The shortest distance between two points is off the wall.


------------------------------

Date: Fri, 04 Apr 2008 10:45:41 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: mismatch between Perl 5.6 and Perl 5.8 in printing high precision  values.
Message-Id: <86sky1d3oa.fsf@lifelogs.com>

On Thu, 3 Apr 2008 22:54:51 +0100 Ben Morrow <ben@morrow.me.uk> wrote: 

BM> Quoth Ted Zlatanov <tzz@lifelogs.com>:
>> On Thu, 3 Apr 2008 01:08:59 +0100 Ben Morrow <ben@morrow.me.uk> wrote: 
>> 
BM> I think the stated position is 'perl provides no guarantees about
BM> anything to do with FP'.
>> 
>> Position of who?  

BM> Whom. :-)

Eh, if I remembered those grammar rules I'd have no room in my brain for
what $| does :)

BM> Of p5p, but note that I don't speak for 'them' in any way, so I may be
BM> mis-stating the case.

I'm curious if there are, in fact, some guarantees.  For example, "on a
full moon, under the willow tree, while softly singing the songs of
distant Earth, adding two floats will, sometimes, give you a float that
is roughly equal to their sum."  You know, spice up the docs a bit.

>> There's Math::BigFloat and Math::BigRat which are at least moderately
>> useful.

BM> There are; there are also the bigint and bignum pragmata which make them
BM> more useful still. I was talking about perl's handling of real platform
BM> floats (NVs).

Right, but big* is a FP interface that's quite useful, and should at
least be mentioned when people complain about platform floats.  Then
those same people can complain about big* performance and Intel/AMD can
sell them faster processors.  Everybody wins.

Ted


------------------------------

Date: Fri, 04 Apr 2008 11:05:31 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: New errors of export image format
Message-Id: <47f651cc$0$87071$815e3792@news.qwest.net>

Ela wrote:
> Thanks smallpond, J. Gleixner and A. Sinan Unur.
> 
> With your support I am near to finish. Now the only puzzling thing is that 
> contradictory results occur:
> 
> Supported formats: gif,png,gd,gd2
> Need PNG libs at plot_ss_b.pl line 42.
> 
> with the following code excerpt, how come it says it support png but at the 
> same time dies? If I comment the die line, ok, it plots normally but without 
> anything generated. Finally, why I give this post "frustrated" is that Perl 
> FAQ, google, or codes message itself give few hints on getting relevant 
> dependencies. If I have to install whatever PNG, GIF libraries and so, I 
> don't mind. But the problem is that I don't know whether it is that problem, 
> and where to locate the libraries directly and correctly.
> 
> #@data = ([@x], [@y]);
> @data = ([2,3,4], [1,1,1]);
> #@data = (@x, @y);
> close FP;
> 
> print 'Supported formats: ', join( ',', $graph->export_format ), "\n";
> die "Need PNG libs" unless $graph->can( 'png' );

That was just there as a different way to test for an
available format.

Hmm.. maybe I got that wrong.. After consulting the
documentation, which you can do via

perldoc GD::Graph

that should probably be:

die "Need PNG libs" unless $graph->gd->can( 'png' );

or

my $gd = $graph->plot(\@data) or die $graph->error;
die "Need PNG libs" unless $gd->can( 'png' );


> 
> $graph->plot(\@data)->png or die $graph->error;

You need to write that output to your file.

>  close IMG; 

There are many examples in the distribution, take
a look at those too.  From the perldoc:

"EXAMPLES
        See the samples directory in the distribution, and read
        the Makefile there. "


------------------------------

Date: Fri, 4 Apr 2008 07:27:32 -0700 (PDT)
From: tazommers@yahoo.com
Subject: separating substitutions from an embedded perl in a ksh script
Message-Id: <9add4ce0-02c3-418a-8d78-4c85a1063e49@8g2000hse.googlegroups.com>

I have a large ksh script which had an embedded perl invocation to do
a character replace... to fix a date in a large flat file.  I know the
script is inefficient, but I wanted to just improve the logic a bit
rather than have to install new scripts etc.  Anyway, the file has
records that if start with the character "5" may need to have the date
replaced at position 70 in the file.

Here is the code snipet I have that works, except for one thing...

CMD="perl -p -i -n -e "'"s/^5(.{68})$EFF_DATE/5\$1|$REP_DATE/g"'"
$FILE"
eval $CMD

I don't want that "|" character, but I need something to separate the
$1 for the perl group and the $REP_DATE from the ksh.  The $REP_DATE
gets replaced in ksh with the string 080407 for instance, so how does
one separate the $1 group from the string 080407?


------------------------------

Date: Fri, 04 Apr 2008 09:12:06 -0700
From: David Harmon <source@netcom.com>
Subject: Re: separating substitutions from an embedded perl in a ksh script
Message-Id: <TrydndEaTvQFzmvanZ2dnUVZ_qygnZ2d@earthlink.com>

On Fri, 4 Apr 2008 07:27:32 -0700 (PDT) in comp.lang.perl.misc,
tazommers@yahoo.com wrote,
>CMD="perl -p -i -n -e "'"s/^5(.{68})$EFF_DATE/5\$1|$REP_DATE/g"'"
>$FILE"
>eval $CMD
>
>I don't want that "|" character, but I need something to separate the
>$1 for the perl group and the $REP_DATE from the ksh.  The $REP_DATE
>gets replaced in ksh with the string 080407 for instance, so how does
>one separate the $1 group from the string 080407?

Does writing $1 as ${1} do it?

But you are essentially replacing $1 with itself!  That seems
gratuitous to me. The stuff before $EFF_DATE is just context and
should not participate in the replacement operation.  Why not an
expression something more like:
    s/(?<=^5.{68})$EFF_DATE/$REP_DATE/

The /g should not be necessary, you only want one replacement per
line anyway.

I can't figure you would need both the -p and -n switches.


------------------------------

Date: Fri, 4 Apr 2008 09:34:37 -0700 (PDT)
From: tazommers@yahoo.com
Subject: Re: separating substitutions from an embedded perl in a ksh script
Message-Id: <aa80c298-fb3c-431e-9ba1-e51715163917@8g2000hse.googlegroups.com>

The {}'s did it.  Thanks!  Much headbanging over.  :)

I tried the second suggestion and it didn't actually replace
anything... but doesn't that syntax remove the first 69 characters
from the actual string?  Yes, I'm a perl rookie btw.

> Does writing $1 as ${1} do it?
>
> But you are essentially replacing $1 with itself! =A0That seems
> gratuitous to me. The stuff before $EFF_DATE is just context and
> should not participate in the replacement operation. =A0Why not an
> expression something more like:
> =A0 =A0 s/(?<=3D^5.{68})$EFF_DATE/$REP_DATE/
>
> The /g should not be necessary, you only want one replacement per
> line anyway.
>
> I can't figure you would need both the -p and -n switches.



------------------------------

Date: Fri, 04 Apr 2008 10:58:44 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Spelling suggestions for common words - ispell, etc.
Message-Id: <86k5jdd32j.fsf@lifelogs.com>

On Thu, 3 Apr 2008 23:27:56 -0700 (PDT) Ben Bullock <benkasminbullock@gmail.com> wrote: 

BB> On Apr 3, 6:47 pm, sftriman <ironma...@yahoo.com> wrote:
>> I am looking for a way to, without custom defining a dictionary, to
>> get a list of suggested words for a misspelled word.  Or better, "the"
>> most likely intended word for a misspelled word.

>> from which I could easily pass on the dmr suggestions, but, scoring
>> and evaluating the suggestions for wjite is harder.  "white" and
>> "write" are 'ranked' (I guess) 3rd, 4th, and 7th.

BB> One thing which might help you rank the strings is the "Levenshtein
BB> distance". This gives you the "difference" between two strings as a
BB> number. I don't know if it is on CPAN but there is a module found
BB> here:

BB> http://world.std.com/~swmcd/steven/perl/lib/String/Levenshtein/index.html

BB> The documentation is here:

BB> http://world.std.com/~swmcd/steven/perl/lib/String/Levenshtein/Levenshtein.html

BB> Presumably the string with the smallest Levenshtein distance from the
BB> input string would be the most likely candidate for the spelling
BB> checker, although some very rare words might have small distances.

It's useful to rank the distance in terms of how close keys are on the
keyboard.  For example, h and j are more likely to be swapped than h and
r, for the white/write/wjite example above.  On CPAN, I found:

String::Similarity
String::KeyboardDistance (see above)
String::Approx (very comprehensive, probably the right choice for the OP)
Text::DoubleMetaphone

Ted


------------------------------

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 1421
***************************************


home help back first fref pref prev next nref lref last post