[19988] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2183 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 22 11:15:40 2001

Date: Thu, 22 Nov 2001 08:15:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006445709-v10-i2183@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 22 Nov 2001     Volume: 10 Number: 2183

Today's topics:
    Re: how to calculate the CRC of a string... <bart.lateur@skynet.be>
        passing hash reference to function: bug? <jfontain@winealley.com>
    Re: passing hash reference to function: bug? (Rafael Garcia-Suarez)
    Re: Problem with perl modules (Anno Siegel)
    Re: Using CGI.pm to obtain a list of params (Wiliam Stephens)
    Re: Using CGI.pm to obtain a list of params (Jon Bell)
    Re: variable scope <matthew.garrish@sympatico.ca>
    Re: Which ISPs support perl scripts? (Tad McClellan)
    Re: Which ISPs support perl scripts? (Tad McClellan)
    Re: XML::Parser, DBI and unicode <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 22 Nov 2001 15:28:12 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: how to calculate the CRC of a string...
Message-Id: <ev4qvt00of3ef1nnma21hq8peus1aj37gi@4ax.com>

MAGiC MANiAC^mTo wrote:

>I like to upload it to my host when I'm ready with my script file.
>What files do I have to upload to my host?...

Gee. What kind of server does your host have? Because it sure likes like
you'll have to install it yourself. And, since this module depends on XS
(a compiled extension in C), simply copying of the necessary files won't
work, unless the other server is precisely the same architecture as
yours (same processor, same OS and preferably same OS version, same
include libs, same perl, ...)

If it is Windows, and he's using a compatible perl, then it could work.
Check out what's in the .tar.gz file to see what files you need. All you
need to do is put them in an appropriate subdirectory of your chosen lib
root.

If it is an Unix compatible, then you'll have to compile it yourself, in
the traditional manner. It is feasable if you have telnet access. If
not... it might be possible to temporarily wrap the installer
instructions it in a CGI script, and call it through the browser,
installing it in a directory owned by "nobody". Make sure you make all
installed files world writable, or you'll never succeed in getting rid
of them again.

For instructions on how to do a custom install, check out these entries
in the FAQ, perlfaq8 (it is part of the standard perl docs):

Found in D:\programs\indigoperl\lib\pod\perlfaq8.pod
  How do I install a module from CPAN?
  How do I keep my own module/library directory?

But honestly, I'd stay away from this as a newbie.

There is a CRC library file avilable somewhere, in pure perl, thus which
doesn't require installation. Let me see...

Here's one:

	<http://www.sph.umich.edu/~aspinall/code/crc32>

but not the one I was thinking of... Ah, there it is:

	<http://swissknife.sourceforge.net/>

See the two "CRC64" links at the bottom of the page.

-- 
	Bart.


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

Date: Thu, 22 Nov 2001 15:17:06 +0100
From: Jean-Luc Fontaine <jfontain@winealley.com>
Subject: passing hash reference to function: bug?
Message-Id: <3BFD08E2.1050104@winealley.com>

The following code:

sub f(\%) {my ($p) = @_;}
my %h;
f(\%h);

fails with:

Type of arg 1 to main::f must be hash (not reference constructor) at 
 ./tst.pl line 9, near "%h)"
Execution of ./tst.pl aborted due to compilation errors.



whereas the same (!!!) code but with the function in a separate file works:

do './f.pl';
my %h;
f(\%h);


$ cat f.pl
sub f(\%) {my ($p) = @_;}



I would love to have an explanation.

Many thanks in advance.

Jean-Luc



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

Date: 22 Nov 2001 14:27:59 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: passing hash reference to function: bug?
Message-Id: <slrn9vq2su.ls7.rgarciasuarez@rafael.kazibao.net>

Jean-Luc Fontaine wrote in comp.lang.perl.misc:
> The following code:
> 
> sub f(\%) {my ($p) = @_;}
> my %h;
> f(\%h);
> 
> fails with:
> 
> Type of arg 1 to main::f must be hash (not reference constructor) at 
> ./tst.pl line 9, near "%h)"
> Execution of ./tst.pl aborted due to compilation errors.
> 
> 
> 
> whereas the same (!!!) code but with the function in a separate file works:
> 
> do './f.pl';
> my %h;
> f(\%h);
> 
> 
> $ cat f.pl
> sub f(\%) {my ($p) = @_;}
> 
> 
> 
> I would love to have an explanation.

The do() happens at runtime.
The prototype checking happens at compile time.
If you want the prototype to be checked, use 'use' instead of 'do', or
wrap it in a BEGIN block.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
$japh="Just another Perl hacker,\n";@j=split/(?= )/,$japh;for my $i
(0..3){*{(($x)=$j[3-$i]=~/\w+/g)[0]}=sub(@){print$j[$i]}}eval$japh;


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

Date: 22 Nov 2001 14:11:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Problem with perl modules
Message-Id: <9tj134$jf4$1@mamenchi.zrz.TU-Berlin.DE>

According to Marco the \"madbat\" <madbat28@hotmail.com>:
>  try to install the module Bit::Vector 6.1 for Perl 5.6.1 on Solaris 8, and
> when i type the "make" command, i have this output error about my gcc (ver.
> 3.02) compiler !!!
> who help me please !!!!
> 
> 
> # make
> gcc -c  -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FIL
> E_OFFSET_BITS=64 -O   -DVERSION=\"6.1\" -DXS_VERSION=\"6.1\" -fPIC -I/usr/lo
> cal/lib/perl5/5.6.1/sun4-solaris/CORE BitVector.c
> BitVector.c:8:80: stdlib.h: No such file or directory

[snip more error messages]

It's not finding the basic include files (stdlib.h, in this case).  The
file should reside somewhere below /usr/include/.  Try to find it there.
If it doesn't exist, your gcc installation is incomplete.  If it does,
the makefile is looking for it in the wrong place.

Anno


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

Date: 22 Nov 2001 07:00:23 -0800
From: wil@fbagroup.co.uk (Wiliam Stephens)
Subject: Re: Using CGI.pm to obtain a list of params
Message-Id: <39e3e00a.0111220700.45faeb44@posting.google.com>

"brian norman" <brian.norman@gecm.com> wrote in message news:<3bfba755$1@pull.gecm.com>...

> use CGI;
> 
> my %Hash;
> my $cgi=new CGI;
> foreach my $V ( $cgi->param())    # without specifying a specific param it
> returns a list of them all
>     {
>     $Hash{$V}=$cgi->param($V);    # to get them into your personal hash
>     }

Thanks for the sample code. That is what I needed indeed. I now need
to assign each param to a specific variable, which I think I should be
able to manage.

That should loop through all params, right?

Wiliam Stephens
http://www.fbagroup.co.uk


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

Date: Thu, 22 Nov 2001 15:20:23 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: Using CGI.pm to obtain a list of params
Message-Id: <Gn7Jxz.6v9@presby.edu>

In article <39e3e00a.0111220700.45faeb44@posting.google.com>,
Wiliam Stephens <wil@fbagroup.co.uk> wrote:
>"brian norman" <brian.norman@gecm.com> wrote in message
>news:<3bfba755$1@pull.gecm.com>...
>
>> use CGI;
>> 
>> my %Hash;
>> my $cgi=new CGI;
>> foreach my $V ( $cgi->param())    # without specifying a specific param it
>> returns a list of them all
>>     {
>>     $Hash{$V}=$cgi->param($V);    # to get them into your personal hash
>>     }
>
>Thanks for the sample code. That is what I needed indeed. I now need
>to assign each param to a specific variable, which I think I should be
>able to manage.

Of course, if you know the parameter names in advance (as you should, 
either because you created the form yourself, or you read the docs for 
it), you can assign them straight away to specific variables without 
bothering with a hash.  For example, if two of the parameters are named 
'firstname' and 'lastname':

my $FirstName = $cgi->param('firstname');
my $LastName  = $cgi->param('lastname');

etc.  So far, I've used the read-into-hash thing only as a debugging
measure.

-- 
Jon Bell <jtbell@presby.edu>                        Presbyterian College
Dept. of Physics and Computer Science        Clinton, South Carolina USA


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

Date: Thu, 22 Nov 2001 09:34:53 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: variable scope
Message-Id: <RZ7L7.25276$pd.3258474@news20.bellglobal.com>


"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x7oflvbcy0.fsf@home.sysarch.com...
>
> your experience in language development tells you otherwise? haw many
> languages do you know or have ever worked in? there was no fence
> sitting. my variables are simply lexically scoped in the block they are
> declared in. the case of a my variable as a foreach index means it is
> scoped INSIDE the foreach block. that's it. no more rules. it is totally
> here and not half-assed.
>

I'm beginning to think I did write my own language, and it's called English.
Unfortunately no one here seems to know it. I'm tempted to go through and
count the number of times people have misread my original post. I harassed
Ilya for the answer I wanted, and I got it long ago! The thread has since
descended into something else entirely.

All I wanted was to know how the scoping of a foreach block works, and why
it wouldn't catch the multiple declarations as an error. If you think you'll
never make that mistake, good for you. I also stand by my original opinion
that it's not the failsafe method you take it for. Once the variable is
masked, it becomes useless within the loop (unless you are privy to some
wisdom about how to add code in the netherworld between the end of the loop
and the resumption of the body).

So why not just initialize the variable within the scope of the loop, rather
than within a new block, since it's life only lasts for as long as the loop?
You are obviously content with whatever the perl overlords dictate, but I
haven't heard a single reason why this is a "good thing". Only that that's
the way it is...

Matt




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

Date: Thu, 22 Nov 2001 15:32:53 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Which ISPs support perl scripts?
Message-Id: <slrn9vq0uj.sk5.tadmc@tadmc26.august.net>

Bob <null@null.com> wrote:
>In article <9t4duk$f9k$1@news8.svr.pol.co.uk>, "Chris Clarke"
><mad-biker@couplands-well.freeserve.co.uk> wrote:
>
>> As an absolute perl beginner... how do I find an ISP which supports perl
>> scripts?  I am currently with Freeserve, and the ISP would have to be free.
>
>No one lets you run perl scripts for free. Deal with it.


*Everyone* can run Perl programs for free.

Perl is free for a wide variety of platforms, you download it,
you install it, you use it. You pay nothing.

You do not need an ISP to run Perl programs. You do not need
a connection to the internet to run Perl programs.


I expect the OP really meant to ask something like:

   How do I find an ISP which supports CGI programs written in Perl?


Now the answer to _that_ question may well be as you describe above  :-)


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


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

Date: Thu, 22 Nov 2001 15:32:54 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Which ISPs support perl scripts?
Message-Id: <slrn9vq1fp.sk5.tadmc@tadmc26.august.net>

Chris Clarke <mad-biker@couplands-well.freeserve.co.uk> wrote:

>As an absolute perl beginner... how do I find an ISP which supports perl
>scripts?  


I recommend that you don't try to learn both the application area (CGI)
and the programming language at the same time.

Learn Perl first. When you are comfortable with Perl, then move
on to whatever application area you wish to apply Perl to.

You can make a great deal of progress learning before you need
to find an ISP or pay for anything.


First install the perl distribution on your local computer and 
learn Perl programming.

Then install a free web server on your local computer, and learn
how to make Perl communicate following the Common Gateway Interface.


Now you can program from both the command line and in a CGI
environment and learn/debug to your heart's content.

You can develop your code without an ISP, without internet
access even.

Once you have it running well at your house and you're ready
to make it "live" on a web server on the 'net, _then_ you need
to find an ISP.


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


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

Date: Thu, 22 Nov 2001 15:25:04 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: XML::Parser, DBI and unicode
Message-Id: <716qvt0gl1l9m9o5kkmntv9cae4qaehdjb@4ax.com>

Natanael Copa wrote:

>my $u = Unicode::String::utf8($line_from_xml);
>
>when I 'print $u->latin1;' it displays correctly but when I insert in mysql 
>it doesn't. the chars (for example &#233;) are show as two byte's. Thats is 
>not what I want.
>
>my $sql = "INSERT INTO tbl_name (col) VALUES 
>(".$dbh->qoute($line_from_xml).")";
>
>my $u = Unicode::String::utf8($sql);
>$dbh->do($u->latin1);

You've got this reversed. ONLY the line from XML should be treated as
UTF-8.

my $u = Unicode::String::utf8($line_from_xml);
my $sql ="INSERT INTO tbl_name (col) VALUES ("
  . $dbh->quote($u->latin1) .")";
$dbh->do($sql);

>I wonder why 'print $u->latin1' works and not '$dbh->do($u->latin1)'???

Beats me. Probably treating the SQL as Unicode somehow corrupts the SQL
statement.

-- 
	Bart.


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

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


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