[29224] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 468 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 30 03:09:41 2007

Date: Wed, 30 May 2007 00: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           Wed, 30 May 2007     Volume: 11 Number: 468

Today's topics:
        bidirectional pipe & inetd <papahuhn@gmx.net>
        CGI mysql problem <mmccaws@comcast.net>
    Re: CGI mysql problem <spamtrap@dot-app.org>
    Re: CGI mysql problem <mmccaws@comcast.net>
    Re: Cygwyn Question on broken link <kst-u@mib.org>
    Re: duplicates <tadmc@augustmail.com>
    Re: duplicates <tadmc@augustmail.com>
    Re: duplicates <jeevan.ingale@gmail.com>
    Re: login example <paduille.4061.mumia.w+nospam@earthlink.net>
        new CPAN modules on Wed May 30 2007 (Randal Schwartz)
        parsing a csv file with a blob of text <mikegws@gmail.com>
    Re: parsing a csv file with a blob of text <paduille.4061.mumia.w+nospam@earthlink.net>
    Re: parsing a csv file with a blob of text <noreply@gunnar.cc>
    Re: The Concepts and Confusions of Prefix, Infix, Postf <xah@xahlee.org>
    Re: Use different modules based on variable <tadmc@augustmail.com>
        What is MAXINT, or when to use bigint? <bwooster47@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 30 May 2007 03:10:01 +0200
From: papahuhn <papahuhn@gmx.net>
Subject: bidirectional pipe & inetd
Message-Id: <5c417bF2qmi9uU1@mid.dfncis.de>

Hello,
I want to create a wrapper for an application that is normally run by 
xinetd.
The information flow should be as following: xinetd <-> wrapper <-> app.

So I have to execute the app within the wrapper and communicate with it 
using a bidirectional pipe. Unfortunately there is a problem with the 
input-buffering of the open2() handles as mentioned by perldoc perlipc:

 > The problem with this is that Unix buffering is really going to ruin
 > your day.  Even though your "Writer" file handle is auto-flushed, and
 > the process on the other end will get your data in a timely manner,
 > you can't usually do anything to force it to give it back to you in a
 > similarly quick fashion.  In this case, we could, because we gave
 > cat a -u flag to make it unbuffered. But very few Unix commands are
 > designed to operate over pipes, so this seldom works unless you
 > yourself wrote the program on the other end of the double-ended pipe.


My first attempts to use Expect did not solve the problem.
Has anyone concrete experience with this matter?

Thanks


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

Date: 29 May 2007 20:43:39 -0700
From: mmccaws2 <mmccaws@comcast.net>
Subject: CGI mysql problem
Message-Id: <1180496619.878199.324440@z28g2000prd.googlegroups.com>

Where to begin trouble shooting this?

The problem is that I have 17 entries in mysql database and when I run
my sub routine it only returns the entries that are not in the first
two rows.  I tried to update the first row, without result.  And I re-
entered  the first two rows to rows 18 and 19 and then they would be
entered in the feeds array.

I'm running mysql ver mysql-5.0.37-osx10.4-i686
apache 2.2;
Mac osx tiger

I check the scalar on the returned array and it always is two less
than what the db shows.

Thanks
mike


sub get_all_feeds {
    my $self = shift;
    my @args = @_;


    my $allfeed_sql = qq{
SELECT title, url, xml, date, feed_id
FROM rss_feeds
    };
    my $dbh = $self->{dbh};

    my $sth = $dbh->prepare($allfeed_sql) or die "Couldn't prepare:
" . $dbh->errstr;
    $sth->execute or die "Couldn't execute: " . $sth->errstr;
     my @tablefeeds = $sth->fetchrow_array;
    # is there already a row with this username?
    if (!$sth->fetchrow_array) {
        return 0;
    }

    my @feeds;
    while (my $row = $sth->fetchrow_hashref) {
        my $feed =
            Feeds::Feed->new_feed(title        => $row->{title},
                               url             => $row->{url},
                               xml             => $row->{xml},
                               date            => $row->{date},
                               feed_id         => $row->{feed_id});

        push (@feeds, $feed);
    }
    return @feeds;
}



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

Date: Wed, 30 May 2007 00:02:35 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: CGI mysql problem
Message-Id: <m2ps4jdkmc.fsf@local.wv-www.com>

mmccaws2 <mmccaws@comcast.net> writes:

> The problem is that I have 17 entries in mysql database and when I run
> my sub routine it only returns the entries that are not in the first
> two rows.

>     my $sth = $dbh->prepare($allfeed_sql) or die "Couldn't prepare:
> " . $dbh->errstr;
>     $sth->execute or die "Couldn't execute: " . $sth->errstr;
>      my @tablefeeds = $sth->fetchrow_array;

Now the first row is in @tablefeeds.

>     # is there already a row with this username?
>     if (!$sth->fetchrow_array) {

You've fetched the second row and thrown it away.

>         return 0;
>     }
>
>     my @feeds;
>     while (my $row = $sth->fetchrow_hashref) {
>         my $feed =
>             Feeds::Feed->new_feed(title        => $row->{title},
>                                url             => $row->{url},
>                                xml             => $row->{xml},
>                                date            => $row->{date},
>                                feed_id         => $row->{feed_id});
>
>         push (@feeds, $feed);
>     }
>     return @feeds;


This loop puts the rest of the rows, starting with the third, in @feeds
and returns that.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: 29 May 2007 21:54:00 -0700
From: mmccaws2 <mmccaws@comcast.net>
Subject: Re: CGI mysql problem
Message-Id: <1180500840.007188.193670@q19g2000prn.googlegroups.com>

On May 29, 9:02 pm, Sherm Pendley <spamt...@dot-app.org> wrote:
> mmccaws2 <mmcc...@comcast.net> writes:
> > The problem is that I have 17 entries in mysql database and when I run
> > my sub routine it only returns the entries that are not in the first
> > two rows.
> >     my $sth = $dbh->prepare($allfeed_sql) or die "Couldn't prepare:
> > " . $dbh->errstr;
> >     $sth->execute or die "Couldn't execute: " . $sth->errstr;
> >      my @tablefeeds = $sth->fetchrow_array;
>
> Now the first row is in @tablefeeds.
>
> >     # is there already a row with this username?
> >     if (!$sth->fetchrow_array) {
>
> You've fetched the second row and thrown it away.
>
> >         return 0;
> >     }
>
> >     my @feeds;
> >     while (my $row = $sth->fetchrow_hashref) {
> >         my $feed =
> >             Feeds::Feed->new_feed(title        => $row->{title},
> >                                url             => $row->{url},
> >                                xml             => $row->{xml},
> >                                date            => $row->{date},
> >                                feed_id         => $row->{feed_id});
>
> >         push (@feeds, $feed);
> >     }
> >     return @feeds;
>
> This loop puts the rest of the rows, starting with the third, in @feeds
> and returns that.
>
> sherm--
>
> --
> Web Hosting by West Virginians, for West Virginians:http://wv-www.net
> Cocoa programming in Perl:http://camelbones.sourceforge.net

Fantastic.  I thought the while would start from scratch, but I see
that now.

Thanks

mike



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

Date: Tue, 29 May 2007 19:06:40 -0700
From: Keith Thompson <kst-u@mib.org>
Subject: Re: Cygwyn Question on broken link
Message-Id: <lnodk35akv.fsf@nuthaus.mib.org>

ian <ipellew@yahoo.com> writes:
> I have broken the link on Cygwin /usr/lib/perl5/ that pointed to 5.8/
> cygwin or whatever.
> I have tried unistall and install but cannot get back to having the
> cygwin dir in /usr/lib/perl5/5.8

On my Cygwin system (fully updated, under Windows XP), /usr/lib/perl5
is not a symlink, and there are no symlinks anywhere under
the /usr/lib/perl5 directory:

% ls -ld /usr/lib/perl5
drwxrwx---+ 5 kst Users 0 May 29 19:04 /usr/lib/perl5
% find /usr/lib/perl5 -type f | wc -l
2548
% find /usr/lib/perl5 -type d | wc -l
339
% find /usr/lib/perl5 -type l | wc -l
0

I don't know just what problem you're having, but you're likely to get
better help on the Cygwin mailing list, <http://cygwin.com/lists.html>.

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


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

Date: Tue, 29 May 2007 20:58:25 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: duplicates
Message-Id: <slrnf5pmi1.nsj.tadmc@tadmc30.august.net>

Brad Baxter <baxter.brad@gmail.com> wrote:
> On May 29, 4:08 pm, Michele Dondi <bik.m...@tiscalinet.it> wrote:
>> On Tue, 29 May 2007 11:38:42 -0700, Jim Gibson
>>
>> <jgib...@mail.arc.nasa.gov> wrote:
>> >Here's a fish:
>>
>> What's of the elitist clpmisc attitude? ;-)
>
> s/of/with/;


Due to the smiley, I think

   s/of/become of/;

was the intent.


>   -- elitist (alleged) English speaker


I only speak 'merican though, so I may be way off base...


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 29 May 2007 19:55:21 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: duplicates
Message-Id: <slrnf5pirp.nsj.tadmc@tadmc30.august.net>

usenet@DavidFilmer.com <usenet@DavidFilmer.com> wrote:
> On May 29, 10:33 am, julia_2...@hotmail.com wrote:

>>> eat -> eated
>
> eated???


I think that's when something is warmed up in England...


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 29 May 2007 23:55:16 -0700
From: jeevs <jeevan.ingale@gmail.com>
Subject: Re: duplicates
Message-Id: <1180508116.023743.10340@r19g2000prf.googlegroups.com>

On May 29, 11:28 pm, use...@DavidFilmer.com wrote:
> On May 29, 10:33 am, julia_2...@hotmail.com wrote:
>
> > I would like to find and delete duplicates to reduce the number of
> > entries I have for each word. Need your help to achieve that.
>
> How about this:
>
> #!/usr/bin/perl
>
>    use strict;
>    use warnings;
>
>    my %word;
>    while (<DATA>) {
>       chomp;
>       my ($word1, $word2) = split (/ -> /, $_);
>       push @{$word{$word1}}, $word2;
>    }
>    print($_," -> ",join(" ",@{$word{$_}}),"\n") for keys %word;
>
> __DATA__
> dog -> doggy
> dog -> dogs
> want -> wants
> want -> wanting
> want -> wanted
> eat -> eaten
> eat -> eating
> eat -> eated
>
> OUTPUT
> eat -> eaten eating eated
> want -> wants wanting wanted
> dog -> doggy dogs
>
> >> eat -> eated
>
> eated???
>
> --
> The best way to get a good answer is to ask a good question.
> David Filmer (http://DavidFilmer.com)


Hi David .. Sorry but i dint follow the syntax you used

like you used

push (@{$hash{$key}}, $value);

How does this work.. I mean i can understand when one uses @{$arr_ref}
to derefenciate an array ref.
but what does @{$hash{$key}} stands for... IF you can point me to some
data or link that will be fine too...



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

Date: Wed, 30 May 2007 03:21:18 GMT
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: login example
Message-Id: <O467i.11557$296.9375@newsread4.news.pas.earthlink.net>

On 05/29/2007 05:54 PM, precode@comcast.net wrote:
> [...]
> Is there a link for information on using perl to login with a free or 
> no money account where visiotrs to a site can register and access the 
> internet without a fee
> 
> Thank you
> 
> idunno
> 

The newsgroup alt.freewebhosting is over there ------------------>

Check Yahoo too.



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

Date: Wed, 30 May 2007 04:42:09 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Wed May 30 2007
Message-Id: <JIu7q9.20DH@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Apache-FastForward-1.1
http://search.cpan.org/~jwach/Apache-FastForward-1.1/
new age of spreadsheet web services
----
Apache2-ASP-0.08
http://search.cpan.org/~johnd/Apache2-ASP-0.08/
ASP for a mod_perl2 environment.
----
Archive-Extract-0.22
http://search.cpan.org/~kane/Archive-Extract-0.22/
A generic archive extracting mechanism
----
Audio-MPD-Common-0.1.0
http://search.cpan.org/~jquelin/Audio-MPD-Common-0.1.0/
a bunch of common helper classes for mpd
----
Bot-BasicBot-Pluggable-Module-Twitter-0.0.3
http://search.cpan.org/~franckc/Bot-BasicBot-Pluggable-Module-Twitter-0.0.3/
Post message to twitter
----
Brick-0.226_02
http://search.cpan.org/~bdfoy/Brick-0.226_02/
Complex business rule data validation
----
CPANPLUS-0.79_04
http://search.cpan.org/~kane/CPANPLUS-0.79_04/
API & CLI access to the CPAN mirrors
----
Captcha-reCAPTCHA-v0.6
http://search.cpan.org/~andya/Captcha-reCAPTCHA-v0.6/
A Perl implementation of the reCAPTCHA API
----
Class-Trigger-0.11_01
http://search.cpan.org/~miyagawa/Class-Trigger-0.11_01/
Mixin to add / call inheritable triggers
----
DBIx-Class-InflateColumn-ISBN-0.03000
http://search.cpan.org/~penguin/DBIx-Class-InflateColumn-ISBN-0.03000/
Auto-create Business::ISBN objects from columns.
----
DBIx-TextIndex-0.26
http://search.cpan.org/~dkoch/DBIx-TextIndex-0.26/
Perl extension for full-text searching in SQL databases
----
Data-LazyACL-0.04
http://search.cpan.org/~tomyhero/Data-LazyACL-0.04/
Simple and Easy Access Control List
----
DateTime-TimeZone-0.6602
http://search.cpan.org/~drolsky/DateTime-TimeZone-0.6602/
Time zone object base class and factory
----
DateTime-Util-Astro-0.11001
http://search.cpan.org/~dmaki/DateTime-Util-Astro-0.11001/
Utilities for Astronomical Calculations
----
DateTime-Util-Calc-0.13002
http://search.cpan.org/~dmaki/DateTime-Util-Calc-0.13002/
DateTime Calculation Utilities
----
Devel-Hide-0.0004
http://search.cpan.org/~ferreira/Devel-Hide-0.0004/
Forces the unavailability of specified Perl modules (for testing)
----
Devel-REPL-1.000000
http://search.cpan.org/~mstrout/Devel-REPL-1.000000/
a modern perl interactive shell
----
Devel-REPL-1.000001
http://search.cpan.org/~mstrout/Devel-REPL-1.000001/
a modern perl interactive shell
----
Encode-2.22
http://search.cpan.org/~dankogai/Encode-2.22/
character encodings
----
Encode-2.23
http://search.cpan.org/~dankogai/Encode-2.23/
character encodings
----
Encode-JP-Mobile-0.05
http://search.cpan.org/~miyagawa/Encode-JP-Mobile-0.05/
Shift_JIS variants of Japanese Mobile phones
----
File-Copy-Reliable-0.31
http://search.cpan.org/~lbrocard/File-Copy-Reliable-0.31/
file copying and moving with extra checking
----
Geo-Coder-GoogleMaps-0.12
http://search.cpan.org/~dupuisarn/Geo-Coder-GoogleMaps-0.12/
Google Maps Geocoding API
----
Geo-StreetAddress-FR-0.0.4
http://search.cpan.org/~franckc/Geo-StreetAddress-FR-0.0.4/
Perl extension for parsing French street addresses
----
HTML-StripScripts-0.991
http://search.cpan.org/~drtech/HTML-StripScripts-0.991/
Strip scripting constructs out of HTML
----
HTML-StripScripts-Parser-0.991
http://search.cpan.org/~drtech/HTML-StripScripts-Parser-0.991/
XSS filter using HTML::Parser
----
Lyrics-Fetcher-LyricWiki-0.02
http://search.cpan.org/~bigpresh/Lyrics-Fetcher-LyricWiki-0.02/
Get song lyrics from www.LyricWiki.org
----
Module-Pluggable-Dependency-0.0.4
http://search.cpan.org/~mndrix/Module-Pluggable-Dependency-0.0.4/
order plugins based on inter-plugin dependencies
----
Template-Plugin-DateTime-0.05
http://search.cpan.org/~dmaki/Template-Plugin-DateTime-0.05/
A Template Plugin To Use DateTime Objects
----
Text-Template-Simple-0.48
http://search.cpan.org/~burak/Text-Template-Simple-0.48/
Simple text template engine
----
WWW-Facebook-API-v0.1.1
http://search.cpan.org/~unobe/WWW-Facebook-API-v0.1.1/
Facebook API implementation
----
WWW-Facebook-API-v0.1.3
http://search.cpan.org/~unobe/WWW-Facebook-API-v0.1.3/
Facebook API implementation
----
WWW-Facebook-FQL-0.03
http://search.cpan.org/~seano/WWW-Facebook-FQL-0.03/
Simple interface to Facebook's FQL query language
----
WebService-Nestoria-Search-0.08
http://search.cpan.org/~kaoru/WebService-Nestoria-Search-0.08/
Perl interface to the Nestoria Search public API.
----
YAML-LibYAML-0.11
http://search.cpan.org/~ingy/YAML-LibYAML-0.11/
LibYAML bindings for Perl
----
YAML-Tests-0.04
http://search.cpan.org/~ingy/YAML-Tests-0.04/
Common Test Suite for Perl YAML Implementations
----
re-engine-PCR-0.02_01
http://search.cpan.org/~avar/re-engine-PCR-0.02_01/
Pugs::Compiler::Rule regex engine
----
re-engine-Plugin-0.04_01
http://search.cpan.org/~avar/re-engine-Plugin-0.04_01/
API to write custom regex engines
----
threads-1.62
http://search.cpan.org/~jdhedden/threads-1.62/
Perl interpreter-based threads


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 29 May 2007 18:50:26 -0700
From: "mikegws@gmail.com" <mikegws@gmail.com>
Subject: parsing a csv file with a blob of text
Message-Id: <1180489826.060249.51730@k79g2000hse.googlegroups.com>


I've got a script output that's run on dozens of systems and outputs
into a huge csv file.  I'm new
at perl and would use Text:CSV but it doesn't understand the blob of
text in ""'s.

Right now I just need to break up the file into a directory for linux,
directory for solaris and put
the blob output in quotes for that hostname into a file in that dir.

I'm not sure how to properly read the blob from beginning to end and
key it off the hostname.  Any
ideas?

------------
unixsys52,Solaris8,UltraSPARC-II 296Mhz,1024,"********


Creating a report on all Elan SG products installed on this system

-----------------***********************-----------------

License Key                         = R8PE-PDIY-NEGG-D34H-6PPP-3PPP-
K3OX
Product Name                        = Elan Dynatek Help Desk 4.0
Serial Number                       = 93692
Features :=

********",

(repeat over and over for each new system)

----------------Script-----------------

#!/usr/bin/perl

use File::Path;

my $file = 'licenseout.csv';
my $licfile = "license.txt";

open (F, $file) || die ("Could not open $file!");

while (<F>)
{
        if (/UltraSPARC/) {
                ($hostname,$osver,$proc,$ram,$elanlic) = split ',',
$_;
                mkpath "/tmp/elic-solaris/$hostname";
                chdir "/tmp/elic-solaris/$hostname";
                if (/,"*.."/)  {
                        open (LC, ">>$licfile");
                        print LC "$_";
                        }
                }
        }
        if (/Intel/) {
                ($hostname,$os,$osver,$proc,$ram,$elanlic) = split
',', $_;
                mkpath "/tmp/elic-linux/$hostname";
                chdir "/tmp/elic-linux/$hostname";
                 if (/,"*.."/)  {
                        open (LC, ">>$licfile");
                        print LC "$_";
                        }
        }
}

close (F);



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

Date: Wed, 30 May 2007 03:21:19 GMT
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: parsing a csv file with a blob of text
Message-Id: <P467i.11558$296.5358@newsread4.news.pas.earthlink.net>

On 05/29/2007 08:50 PM, mikegws@gmail.com wrote:
> I've got a script output that's run on dozens of systems and outputs
> into a huge csv file.  I'm new
> at perl and would use Text:CSV but it doesn't understand the blob of
> text in ""'s.
> [...]

Check out the "binary" option for Text::CSV.



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

Date: Wed, 30 May 2007 06:07:16 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: parsing a csv file with a blob of text
Message-Id: <5c4boiF2urs2jU1@mid.individual.net>

mikegws@gmail.com wrote:
> I've got a script output that's run on dozens of systems and outputs
> into a huge csv file.  I'm new
> at perl and would use Text:CSV but it doesn't understand the blob of
> text in ""'s.
> 
> Right now I just need to break up the file into a directory for linux,
> directory for solaris and put
> the blob output in quotes for that hostname into a file in that dir.
> 
> I'm not sure how to properly read the blob from beginning to end and
> key it off the hostname.  Any
> ideas?

How about something like:

     my $data = do { local $/; <F> };

     while ( $data =~ /(.+?),"(.+?)",/gs ) {
         my ($hostname, $osver, $proc, $ram) = split /,/, $1;
         my $elanlic = $2;

         # do whatever you want
     }

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 30 May 2007 00:00:53 -0700
From: Xah Lee <xah@xahlee.org>
Subject: Re: The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations
Message-Id: <1180508453.226022.44230@q19g2000prn.googlegroups.com>

Prefix, Infix, Postfix notations in Mathematica

2000-02-21, 2007-05

[In the following essay, I discuss prefix, infix, postfix notations
and Mathematica's syntax for them. The full HTML formatted article is
available at:
http://xahlee.org/UnixResource_dir/writ/notations.html
]

THE HEAD OF EXPRESSIONS

Lisp's nested parenthesis syntax is a Functional Notation. It has the
general form of =E2=80=9C(f a b ...)=E2=80=9D where any of the symbols insi=
de the
matching parenthesis may again be that form. For example, here's a
typical code from Emacs Lisp.

; Recursively apply (f x i), where i is the ith element in the list
li.
; For example, (fold f x '(1 2)) computes (f (f x 1) 2)
(defun fold (f x li)
  (let ((li2 li) (ele) (x2 x))
    (while (setq ele (pop li2))
      (setq x2 (funcall f x2 ele))
    )
    x2
  )
)

Vast majority of computer languages, interpret source code in a one-
dimensional, linear nature. Namely, from left to right, line by line,
as in written text. (Examples of computer languages's source code that
are not linear in nature, are spread sheets, cellular automata,
graphical programing languages) For languages that interprets source
code linearly, the logics of their syntax necessarily have a
hierarchical structure (i.e. tree). The lisp's notation, is the most
effective in visually showing the logics of the syntax. This is
because, a function and its arguments, are simply laid out inside a
parenthesis. The level of nesting corresponds to the =E2=80=9Cprecedence=E2=
=80=9D in
evaluating the expression.

The first element inside the matching parenthesis, is called the
=E2=80=9Chead=E2=80=9D of the expression. For example, in =E2=80=9C(f a b)=
=E2=80=9D, the =E2=80=9Cf=E2=80=9D is the
head. The head is a function, and the rest of the symbols inside the
matching parenthesis are its arguments.

The head of lisp's notation needs not to be defined as the first
element inside the parenthesis. For example, we can define the =E2=80=9Chea=
d=E2=80=9D
to be the last element inside the parenthesis. So, we write =E2=80=9C(arg1
arg2 ... f)=E2=80=9D instead of the usual =E2=80=9C(f arg1 arg2 ...)=E2=80=
=9D and its
syntactical analysis remains unchanged. Like wise, you can move the
head outside of the parenthesis.

In Mathematica, the head is placed in front of the parenthesis, and
square brackets are used instead of parenthesis for the enclosing
delimiter. For example, lisp's =E2=80=9C(f a b c)=E2=80=9D is syntactically=
 equivalent
to Mathematica's =E2=80=9Cf[a,b,c]=E2=80=9D. Other examples: =E2=80=9C(sin =
=CE=B8)=E2=80=9D vs =E2=80=9CSin[=CE=B8]=E2=80=9D,
=E2=80=9C(map f list)=E2=80=9D vs =E2=80=9CMap[f,list]=E2=80=9D. Placing th=
e head in front of the
matching bracket makes the notation more familiar, because it is a
conventional math notation.

However, there is a disadvantage in moving the head of a expression
from inside the matching bracket to outside. Namely: The nesting of
the matching delimiters, no longer corresponds to the logics of the
syntax, when the head is itself a compound expression.

For example, suppose Reflection(vectorV,pointP) is function that
returns a function f, such that f(graphicsData) will reflect the
graphicsData along a line passing pointP and parallel to vectorV. In
lisp, we would write =E2=80=9C((Reflection vectorV pointP) graphicsData)=E2=
=80=9D. In
Mathematica, we would write =E2=80=9CReflection[vectorV,pointP]
[graphicsData]=E2=80=9D. In lisp's version, the nesting corresponds to the
logics of the evaluation. In the Mathematica's form, that is no longer
so.

For another example, suppose Deriv is a function that takes a function
f and returns a function g (the derivative of f), and we want to apply
g to a variable x. In lisp, we would write =E2=80=9C((Deriv f) x)=E2=80=9D.=
 In
Mathematica, we would write =E2=80=9CDeriv[f][x]=E2=80=9D. In lisp's versio=
n, the
nesting corresponds to the logics of the evaluation. In the
Mathematica's form, the logics of the evaluation no longer corresponds
to the nesting level, because now the head is outside of the enclosing
delimiters, so the head of expressions no longer nests.

PREFIX, POSTFIX, INFIX

A prefix notation in Mathematica is represented as =E2=80=9Cf@arg=E2=80=9D.
Essentially, a prefix notation in this context limits it to uses for
functions on only one argument. For example: =E2=80=9Cf@a@b@c=E2=80=9D is e=
quivalent
to =E2=80=9Cf[a[b[c]]]=E2=80=9D or in lispy =E2=80=9C(f (a (b c)))=E2=80=9D=
 . Mathematica also offers a
postfix notation using the operator =E2=80=9C//=E2=80=9D. For example, =E2=
=80=9Cc//b//a//f=E2=80=9D is
syntactically equivalent to =E2=80=9Cf[a[b[c]]]=E2=80=9D. (unix's pipe =E2=
=80=9C|=E2=80=9D syntax, is
a form of postfix notation. e.g. =E2=80=9Cc | b | a | f=E2=80=9D).

For example, =E2=80=9CSin[List[1,2,3]]=E2=80=9D can be written in postfix as
=E2=80=9CList[1,2,3]//Sin=E2=80=9D, or prefix =E2=80=9CSin@List[1,2,3]=E2=
=80=9D. (by the way, they are
semantically equivalent to =E2=80=9CMap[Sin, List[1,2,3]]=E2=80=9D in Mathe=
matica) For
infix notation, the function symbol is placed between its arguments.
In Mathematica, the generic form for infix notation is by sandwiching
the tilde symbol around the function name. e.g.
=E2=80=9CJoin[List[1,2],List[3,4]]=E2=80=9D is syntactically equivalent to =
=E2=80=9CList[1,2]
~Join~ List[3,4]=E2=80=9D.

In Mathematica, there is quite a lot syntax variations beside the
above mentioned systematic constructs. For example, Plus[a,b,c] can be
written as =E2=80=9Ca+b+c=E2=80=9D, =E2=80=9CPlus[a+b,c]=E2=80=9D, =E2=80=
=9CPlus[Plus[a,b],c]=E2=80=9D, or =E2=80=9C(a
+b)~Plus~c=E2=80=9D. =E2=80=9CList[a,b,c]=E2=80=9D can be written as =E2=80=
=9C{a,b,c}=E2=80=9D, and
=E2=80=9CMap[f,List[a,b,c]]=E2=80=9D can be written as =E2=80=9Cf /@ {a,b,c=
}=E2=80=9D.

The gist being that certain functions are given a special syntactical
construct to emulate the irregular and inefficient but nevertheless
well-understood conventional notations. Also, it reduces the use of
deep nesting that is difficult to type and manage. For example, the
=E2=80=9CPlus=E2=80=9D function is given a operator =E2=80=9C+=E2=80=9D, so=
 that Plus[3,4] can be
written with the more familiar =E2=80=9C3+4=E2=80=9D. The =E2=80=9CList=E2=
=80=9D function is given a
syntax construct of =E2=80=9C{}=E2=80=9D, so that, List[3,4] can be more ea=
sily
written as =E2=80=9C{3,4}=E2=80=9D. The boolean =E2=80=9CAnd=E2=80=9D funct=
ion is given the operator
=E2=80=9C&&=E2=80=9D, so that And[a,b] can be written with the more familia=
r and
convenient =E2=80=9Ca && b=E2=80=9D. Combining all these types of syntax va=
riations,
it can make the source code easier to read than a purely nested
structure. For example, common math expressions such as =E2=80=9C3+2*5>7=E2=
=80=9D
don't have to be written as =E2=80=9CGreater[Plus[3,Times[2,5]],7]=E2=80=9D=
 or the
lispy =E2=80=9C(> (+ 3 (* 2 5)) 7)=E2=80=9D.
C and Perl

When we say that C is a infix notation language, the term =E2=80=9Cinfix
notation=E2=80=9D is used loosely for convenience of description. C and oth=
er
language's syntaxes derived from it (e.g. C++, Java, Perl,
Javascript...) are not based on a notation system, but takes the
approach of a ad hoc syntax soup. Things like =E2=80=9Ci++=E2=80=9D, =E2=80=
=9C++i=E2=80=9D, =E2=80=9Cfor(;;)
{}=E2=80=9D, =E2=80=9Cwhile(){}=E2=80=9D, 0x123, =E2=80=9Csprint(...%s...,.=
 .=2E)=E2=80=9D, ... are syntax
whimsies.

As a side note, the Perl mongers are proud of their slogan of =E2=80=9CThere
Are More Than One Way To Do It=E2=80=9D in their gazillion ad hoc syntax
sugars but unaware that in functional languages (such as Mathematica,
Haskell, Lisp) that there are consistent and generalized constructs
that can generate far more syntax variations than the ad hoc
inflexible Perl both in theory AND in practice. (in lisp, its power of
syntax variation comes in the guise of macros.) And, more importantly,
Perlers clamor about Perl's =E2=80=9Cexpressiveness=E2=80=9D more or less o=
n the
syntax level but don't realize that semantic expressibility is far
more important.

  Xah
  xah@xahlee.org
=E2=88=91 http://xahlee.org/



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

Date: Tue, 29 May 2007 20:52:18 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Use different modules based on variable
Message-Id: <slrnf5pm6i.nsj.tadmc@tadmc30.august.net>

perlguru <manojkumargupta@gmail.com> wrote:
> This is with respect to a thread "Use different modules based on
> variable" <http://groups.google.com/group/comp.lang.perl.misc/
> browse_thread/thread/00b9efe4f4416943?tvc=2> .
>
> In this I had suggested for making use of 'require', but that
> suggestion was bounced back very badly.


Because it did not do what the original poster asked for.


> I am just a user of Perl, and don't have indepth idea about its
> design, And the way its interpreter works.


Then "perlguru" is a rather pretentious nickname to choose...


>  What is dispatch table? 


The %chooser hash in the thread you reference is an example
of a dispatch table.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 29 May 2007 20:52:56 -0700
From: "bwooster47@gmail.com" <bwooster47@gmail.com>
Subject: What is MAXINT, or when to use bigint?
Message-Id: <1180497176.687453.79890@q69g2000hsb.googlegroups.com>

On my machine, perl -V:ivsize  returns
ivsize='4';

This I thought meant that 4-byte integers are supported, so max
integer is probably 2billion or 4billion (approximately).

But - I seem to be able to add much larger numbers, and stay in
integer space - such as 51 billion.

The exponentiation operator does internally use "double", but it still
seems to return very large integers, only breaking at around 10^15, as
this output shows:

2**50 = 1.12589990684262e+015
2**49 =  562949953421312
2**32 =           4294967296
with
use bigint;
2**50 = 1125899906842624

If I know the maximum integer I may encounter in a program, is there a
programmatic way to determine whether to use bigint? Doing a "use
bigint" slows down the whole thing by 40 times, in the example I am
running, and a few tests I ran show same results with and without
bigint.
But - how to know for sure that I don't need bigint - if I know that
all calculations to 2**49 are safe, that would make it sure. But not
sure what is so magic about 2**49!



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

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


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