[31808] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3071 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 10 18:09:22 2010

Date: Tue, 10 Aug 2010 15: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           Tue, 10 Aug 2010     Volume: 11 Number: 3071

Today's topics:
    Re: FAQ 8.44 How do I tell the difference between error <brian.d.foy@gmail.com>
    Re: FAQ 8.44 How do I tell the difference between error <nospam-abuse@ilyaz.org>
    Re: Matrix Ops with Rational Output sln@netherlands.com
    Re: perl programming language <ralph@happydays.com>
    Re: perl programming language <uri@StemSystems.com>
    Re: Plot Module Question <edgrsprj@ix.netcom.com>
    Re: Plot Module Question <edgrsprj@ix.netcom.com>
    Re: Plot Module Question <edgrsprj@ix.netcom.com>
    Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <ralph@happydays.com>
    Re: Question re calling subroutines <hjp-usenet2@hjp.at>
    Re: Question re calling subroutines <hjp-usenet2@hjp.at>
    Re: Question re calling subroutines <kst-u@mib.org>
    Re: simple indexing in Perl? <jurgenex@hotmail.com>
    Re: simple indexing in Perl? <cartercc@gmail.com>
    Re: simple indexing in Perl? <tadmc@seesig.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 10 Aug 2010 15:10:31 +0200
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 8.44 How do I tell the difference between errors from the shell and perl?
Message-Id: <100820101510314829%brian.d.foy@gmail.com>

In article <slrni59df1.v04.hjp-usenet2@hrunkner.hjp.at>, Peter J.
Holzer <hjp-usenet2@hjp.at> wrote:

> On 2010-07-31 22:00, PerlFAQ Server <brian@theperlreview.com> wrote:
> > --------------------------------------------------------------------
> >
> > 8.44: How do I tell the difference between errors from the shell and perl?
> >
> >     (answer contributed by brian d foy)
> >
> >     When you run a Perl script, something else is running the script for
> >     you, and that something else may output error messages. The script might
> >     emit its own warnings and error messages. Most of the time you cannot
> >     tell who said what.
> 
> I find this paragraph confusing. The "something else" that "is running
> the script for" me is the perl interpreter. But from the rest of this
> entry I guess that "something else" means the shell, which doesn't run
> the script, it merely starts it. 

Starting it is the same as running it, when most people consider
"running" to be typing at the command line and hitting enter to kick
something off.

It sounds like you've sussed it out just fine by reading the whole
thing. :)


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

Date: Tue, 10 Aug 2010 21:16:34 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: FAQ 8.44 How do I tell the difference between errors from the shell and perl?
Message-Id: <slrni63gdi.qgu.nospam-abuse@powdermilk.math.berkeley.edu>

On 2010-08-10, brian d foy <brian.d.foy@gmail.com> wrote:
> In article <slrni59df1.v04.hjp-usenet2@hrunkner.hjp.at>, Peter J.
> Holzer <hjp-usenet2@hjp.at> wrote:
>
>> On 2010-07-31 22:00, PerlFAQ Server <brian@theperlreview.com> wrote:
>> > --------------------------------------------------------------------
>> >
>> > 8.44: How do I tell the difference between errors from the shell and perl?
>> >
>> >     (answer contributed by brian d foy)
>> >
>> >     When you run a Perl script, something else is running the script for
>> >     you, and that something else may output error messages. The script might
>> >     emit its own warnings and error messages. Most of the time you cannot
>> >     tell who said what.
>> 
>> I find this paragraph confusing. The "something else" that "is running
>> the script for" me is the perl interpreter. But from the rest of this
>> entry I guess that "something else" means the shell, which doesn't run
>> the script, it merely starts it. 
>
> Starting it is the same as running it, when most people consider
> "running" to be typing at the command line and hitting enter to kick
> something off.
>
> It sounds like you've sussed it out just fine by reading the whole
> thing. :)

   "When you start a Perl script, there may be an intermediate agent
    (such shell) between your action and actual execution of Perl
    interpreter."  etc

What about somesuch.  [As written above, it looks majorly confusing to
me as well...]

Yours,
Ilya


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

Date: Tue, 10 Aug 2010 06:22:46 -0700
From: sln@netherlands.com
Subject: Re: Matrix Ops with Rational Output
Message-Id: <htj266ph7lja2dhlchec075q4q0a7pu3sl@4ax.com>

On Mon, 9 Aug 2010 20:25:53 -0700 (PDT), David <dwarnold45@suddenlink.net> wrote:

>All,
>
>I have no experience with Perl modules that do linear algebra. I've
>searched CPAN and see several.
>
>Can someone advise me on what to use? I'd like to have the ability to
>start with a matrix with integer entries, put it in reduced row
>echelon form, with all of the entries as rational numbers, such as:
>
>
>A =
>
>       4              0              0              2
>      -1             -3              0              1
>       0              2              0             -1
>
>
>ans =
>
>       1              0              0              1/2
>       0              1              0             -1/2
>       0              0              0              0
>
>Suggestions? This has to be in perl.
>
>D.

Try this, only tested on your matrix.
And the swapped rows (redo) didn't come into
play on your matrix. I just guess its a redo
but don't know.
Code is based on Pseudo code from wikipedia.

-sln

---------------------------
use strict;
use warnings;

#
 my @Matrix = (
  [  4,  0,  0,  2 ],
  [ -1, -3,  0,  1 ],
  [  0,  2,  0, -1 ],
 );

 my @Mreduced = GetReducedRowEchelonForm( @Matrix);

 print "\n";
 print "@{$_}\n" for (@Matrix);
 print "------ \n";
 print "@{$_}\n" for (@Mreduced);

 exit;

#
 sub GetReducedRowEchelonForm
 {
     return () unless
          @_ && ref $_[0] eq "ARRAY";
     my @M;
     for my $k (0 .. $#_) {
          $M[$k] = [@{$_[$k]}];
     }
     my $lead = 0;
     my $rowCount = @M - 1;
     my $columnCount = @{$M[0]} - 1;

   FUNC:
     for my $r (0 .. $rowCount) 
     {
          last FUNC if $columnCount <= $lead;
          my $i = $r;

          while( $M[$i][$lead] == 0) {
               $i++;
               if ( $rowCount == $i) {
                   $i = $r;
                   $lead++;
                   last FUNC if $columnCount == $lead;
               }
               last FUNC if $i > $rowCount;
          }

          if ($i != $r) {
              my $irow = $M[$i];
              $M[$i] = $M[$r];
              $M[$r] = $irow;
              redo FUNC;      # swapped rows, should we redo? Don't know.
          }

          my $divisor = $M[$r][$lead];
          foreach my $rowval ( @{$M[$r]} ) {
               $rowval /= $divisor;
          }

          for $i (0 .. $rowCount) {
               if ($i != $r) {
                    my $multiplier = $M[$i][$lead];
                    for my $ndx (0 .. $columnCount) {
                        $M[$i][$ndx] -= $multiplier * $M[$r][$ndx];
                    }
               }
          }
          $lead++;
     }
     return @M;
 }

__END__

http://en.wikipedia.org/wiki/Row_echelon_form

The following pseudocode converts a matrix to reduced row-echelon form:

function ToReducedRowEchelonForm(Matrix M) is
    lead := 0
    rowCount := the number of rows in M
    columnCount := the number of columns in M
    for 0 <= r < rowCount do
        if columnCount <= lead then
            stop function
        end if
        i = r
        while M[i, lead] = 0 do
            i = i + 1
            if rowCount = i then
                i = r
                lead = lead + 1
                if columnCount = lead then
                    stop function
                end if
            end if
        end while
        if i != r then Swap rows i and r
        Divide row r by M[r, lead]
        for 0 <= i < rowCount do
            if i != r do
                Subtract M[i, lead] multiplied by row r from row i
            end if
        end for
        lead = lead + 1
    end for
end function



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

Date: Tue, 10 Aug 2010 11:35:54 -0400
From: Ralph Malph <ralph@happydays.com>
Subject: Re: perl programming language
Message-Id: <e7cd2$4c6171da$40779ac3$10019@news.eurofeeds.com>

Wow, this is really funny!
A person offering professional services on a
web page that looks like it was designed by a 5th
grade multimedia class!
I haven't seen such a funny juxtaposition of claimed skill
and piss poor presentation since www.sysarch.com!



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

Date: Tue, 10 Aug 2010 11:52:42 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: perl programming language
Message-Id: <87fwymlb1x.fsf@quad.sysarch.com>

>>>>> "RM" == Ralph Malph <ralph@happydays.com> writes:

  RM> Wow, this is really funny!
  RM> A person offering professional services on a
  RM> web page that looks like it was designed by a 5th
  RM> grade multimedia class!
  RM> I haven't seen such a funny juxtaposition of claimed skill
  RM> and piss poor presentation since www.sysarch.com!

speak for yourself. your posting here is as stupid as your perl code. a
double winner! and since when do presentation skills need to be matched
with development skills? ever heard of designers vs hackers? no, you
wouldn't have the brain power to realize those skills aren't always in
the same person. you lack all sorts of skills so you must be perfectly
balanced. do you weigh as much as a duck?

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Tue, 10 Aug 2010 13:32:24 -0500
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Re: Plot Module Question
Message-Id: <R7qdnfun87MXBvzRnZ2dnUVZ_jKdnZ2d@earthlink.com>

"Ben Morrow" <ben@morrow.me.uk> wrote in message 
news:k2a3j7-v741.ln1@osiris.mauzo.dyndns.org...

> That the OP is incapable of thinking clearly enough to write a program,
> and prefers to pontificate at great length about how Important
> Scientific Research is being held up due to noone here holding his hand
> and writing the program for him.

Your comments are a little difficult for me to understand.

       Since early in 2009, at several Web sites I have had a fairly 
sophisticated Perl language .exe program available as a downloadable 
freeware program for science researchers around the world.  I wrote the 
entire program myself.  The latest update that is not yet available for 
downloads is about 7000 lines of code long.

       My questions in this Newsgroup usually involve Perl usages that I 
myself have not attempted in the past such as running script that can visit 
a Web site and capture and return data and files.  I had to ask some 
questions here about that script earlier this year because it would not work 
with my programs.  And what I eventually discovered after getting opinions 
from people is that my virus software was keeping the script from working. 
The error messages being generated did not clearly point in that direction. 
Adjustments were made to the virus software to resolve the problem.

       Also, I have clearly stated repeatedly in the past that I consider 
Perl to be perhaps one of the best languages available for science 
researchers to use.  It is so versatile.  And this present effort involves 
attempts to get some documentation prepared that will make it easier for 
researchers to see how they could be using the Perl language with their 
efforts.

If you yourself are a Perl fan, then why not encourage that type of effort?



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

Date: Tue, 10 Aug 2010 13:47:07 -0500
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Re: Plot Module Question
Message-Id: <bfOdnQuYL-s2A_zRnZ2dnUVZ_rOdnZ2d@earthlink.com>

"Tad McClellan" <tadmc@seesig.invalid> wrote in message 
news:slrni5t9j3.oir.tadmc@tadbox.sbcglobal.net...

> A web server is a *program*, just as a word processor is a program.

       I am aware of those things.  But what I have concluded from personal 
experiences is that (other) science researchers are often only interested in 
trying to determine what the laws of the universe are, or whatever.  They 
won't go too far out of their way to develop computer programming or Web 
site development skills.  However, if someone makes that extremely easy for 
them by providing them with "cookbook" type instructions for what they need 
to do then they might take an interest in it.

       If you work with science researchers long enough, what you will also 
eventually discover in my opinion is that they often don't know enough about 
programming and Web site usage to be even able to explain to professional 
computer programmers what needs to be done along those lines.  And as a 
result, progress with many scientific projects is slower than it could and 
should be.

     The science researchers are unlikely to change their attitudes.  So, 
since most of us would like to see them do a better job of finding cures for 
cancer etc. the only choice we have is to try to make things easy for them.



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

Date: Tue, 10 Aug 2010 14:06:06 -0500
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Re: Plot Module Question
Message-Id: <GqydnWQq-vODPvzRnZ2dnUVZ_vKdnZ2d@earthlink.com>

"Steve" <stevem_@nogood.com> wrote in message 
news:RAC7o.56809$dx7.34021@newsfe21.iad...

> But my first thought upon reading this post was that I would probably look 
> at Imagemagick.

       I have looked at ImageMagick quite a few times.  And it is a possible 
option.  But it appears to largely be a picture file manipulation program 
rather than a simple plot generation program.  And it contains many more 
features than are needed.

Why use an ocean liner to do what should be possible with a rowboat?



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

Date: Tue, 10 Aug 2010 10:40:30 -0400
From: Ralph Malph <ralph@happydays.com>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.9 $)
Message-Id: <16086$4c6164df$40779ac3$19324@news.eurofeeds.com>

tl, dnr


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

Date: Tue, 10 Aug 2010 15:20:33 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Question re calling subroutines
Message-Id: <slrni62kh1.7p2.hjp-usenet2@hrunkner.hjp.at>

On 2010-08-10 03:20, Uri Guttman <uri@StemSystems.com> wrote:
> i review code for my recruiting business and i would downgrade any
> code with predeclared subs. putting the subs before the calls makes
> for a hard to read file.

The top-down vs. bottom-up debate will probably never be decided. You
are obviously firmly in the top-down camp, but others may prefer it the
other way around. Some time ago I read "Coders at Work" by Peter Seibel.
He asked every one "top-down or bottom-up?" and although I didn't count
the answers, I seem to remember that it was about an even split (with
quite a few answering "both" or "neither").

	hp



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

Date: Tue, 10 Aug 2010 15:22:31 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Question re calling subroutines
Message-Id: <slrni62kkn.7p2.hjp-usenet2@hrunkner.hjp.at>

On 2010-08-10 05:27, Uri Guttman <uri@StemSystems.com> wrote:
>>>>>> "BM" == Ben Morrow <ben@morrow.me.uk> writes:
>
>  BM> Quoth "Uri Guttman" <uri@StemSystems.com>:
>
>  >> and that is a waste of pixels as well. why do more work than you need
>  >> to? i review code for my recruiting business and i would downgrade any
>  >> code with predeclared subs.
>
>  BM> Well, apart from anything else it moves errors from runtime to compile
>  BM> time, which is always a good thing.
>
> true in general. but then we would all be using prototypes! :)

The main reason I don't use prototypes is that they are ignored for
method calls.

	hp



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

Date: Tue, 10 Aug 2010 14:47:30 -0700
From: Keith Thompson <kst-u@mib.org>
Subject: Re: Question re calling subroutines
Message-Id: <ln8w4eywb1.fsf@nuthaus.mib.org>

"Uri Guttman" <uri@StemSystems.com> writes:
>>>>>> "KT" == Keith Thompson <kst-u@mib.org> writes:
>
>   KT> "Uri Guttman" <uri@StemSystems.com> writes:
>   >>>>>>> "KT" == Keith Thompson <kst-u@mib.org> writes:
>   KT> I tend to omit parentheses in many cases where they're not necessary.
>   KT> For example, I might write:
>   >> 
>   KT> sub Foo;
>   KT> ...
>   KT> my $x = Foo 42; # rather than Foo(42)
>   KT> ...
>   KT> sub Foo {
>   KT> my($arg) = @_;
>   KT> return $arg + 1;
>   KT> }
>   >> 
>   >> that only works if you declare Foo before you call it. perl can't tell
>   >> if a bareword is a sub if it hasn't seen it before unless you use parens.
>
>   KT> Which is why I always predeclare all my subroutines.
>
> and that is a waste of pixels as well. why do more work than you need
> to? i review code for my recruiting business and i would downgrade any
> code with predeclared subs. putting the subs before the calls makes for
> a hard to read file. i put low importance subs at the bottom and order
> the rest is some form of logical top down. this allows for easier
> understanding of the code as you read it. and that means predeclaring
> won't work. remember code is for people, not computers. and code is for
> OTHER people, not yourself.
[snip]

It seems to be that predeclaring vs. not predeclaring is largely a
matter of taste.  Personally, I like to see the list of subroutines
collected in one place, at the top of the source file; it's an
opportunity to add comments briefly describing each one, rather
than having such documentation scattered throughout the program
(or script, or whatever we're calling it this week).

I am admittely influenced by some other languages I've used, in
which the interface (e.g., list of subroutines) and implementation
(e.g., statements that perform the actual work) conventionally
are, or in some cases must be, physically separated.  I'm thinking
particularly of Ada's separate specifications and bodies and C and
C++'s .h and .c (or .cpp) files, but I tend to apply the pattern
even for a program contained in a single source file.  Sure, it's
some extra typing, but my fingers can use the exercise.

YMMV -- in fact, apparently YMDV.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"


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

Date: Tue, 10 Aug 2010 06:17:04 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: simple indexing in Perl?
Message-Id: <rnj266ldjn9rshkmlmvfqp81bbe47rnqkr@4ax.com>

"ela" <ela@yantai.org> wrote:
>
>
>I'm new to database programming and just previously learnt to use loops to 
>look up and enrich information using the following codes. However, when the 
>tables are large, I find this process is very slow. Then, somebody told me I 
>can build a database for one of the file real time and so no need to read 
>the file from the beginning till the end again and again. 

What I gathered from your code without going into details is that for
each line in OFP your are opening, reading through, and closing AFP.

I/O operations are by far the slowest operations and there is a trivial
solution that will probably speed up your program dramatically: instead
of reading AFP again and again and again just read it into an array once
at the beginning of your program and then loop over that array instead
of over the file.

Only if AFP is too large for that (serveral GB) then you may need to
look for a better algorithmic solution. This requires knowledge and
experience and a database may or may not help, depending upon what you
actually are trying to achive.

jue


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

Date: Tue, 10 Aug 2010 06:43:32 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: simple indexing in Perl?
Message-Id: <1cc73c85-f200-4805-8c2f-98964cbcf996@l14g2000yql.googlegroups.com>

On Aug 10, 3:39=A0am, "ela" <e...@yantai.org> wrote:
> I'm new to database programming and just previously learnt to use loops t=
o
> look up and enrich information using the following codes. However, when t=
he
> tables are large, I find this process is very slow. Then, somebody told m=
e I
> can build a database for one of the file real time and so no need to read
> the file from the beginning till the end again and again. However, perl D=
BI
> has a lot of sophisticated functions there and in fact my tables are only
> large but nothing special, linked by an ID. Is there any simple way to
> achieve the same purpose? I just wish the ID can be indexed and then
> everytime I access the record through memory and not through I/O...

You have input, which you want to process and turn into output.

Your input consists of data contained in some kind of file. This is
exactly the kind of task that Perl excels at.

You have two choices: (1) you can use a database to store and query
your data, or (2) you can use your computer's memory to store and
query your data.

If you have a large amount of permanent data that you need to add to,
delete from, and change, your best strategy is to use a database. Read
your data file into your database. Most databases have external
commands (i.e., not SQL) for doing that, so it should be
straightforward and easy -- note that you do not use Perl for this,
and probably shouldn't.

If you have a small to moderate amount of data, whether permanent or
temporary, that you don't need to add to, delete from, or modify, your
best strategy is to use your computer's memory to store and query your
data. Simply open the file, read each line, destructure each line into
a key and value, and stuff it into a hash.

For example, suppose your data looks like this:
12345,George,Washington,First
23456,John,Adams,Second
34567,Thomas,Jefferson,Third
45678,James,Madison,Fourth

You can do this:
my %pres;
open PRES, '<', 'data.csv' or die "$!";
while(<PRES>)
{
   chomp;
   my ($id, $first, $last, $place) =3D split /,/;
   $pres{$place} =3D "$id, $first, $last";
}
close PRES;

If you need a multilevel data structure, see documentation, starting
maybe with lists of lists.

CC.


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

Date: Tue, 10 Aug 2010 09:26:38 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: simple indexing in Perl?
Message-Id: <slrni62o75.tue.tadmc@tadbox.sbcglobal.net>

Jens Thoms Toerring <jt@toerring.de> wrote:
> ela <ela@yantai.org> wrote:

>> print '($listfile, $accfile, $infofile)'; <STDIN>;
>
> What's that at end of the line good for?


Pausing the program until something is typed on STDIN.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 3071
***************************************


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