[21905] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4109 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 12 21:06:19 2002

Date: Tue, 12 Nov 2002 18:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 12 Nov 2002     Volume: 10 Number: 4109

Today's topics:
        [Q] Script to search auction sites? (Sir Loin of Beef)
    Re: [Q] Script to search auction sites? <spam@thecouch.homeip.net>
    Re: A vision for Parrot <schlenk@uni-oldenburg.de>
    Re: About to tear my hair out here ... (Newbie Question <wsegrave@mindspring.com>
        Better coding through inheritance? <lance@augustmail.com>
    Re: Better coding through inheritance? <me@dwall.fastmail.fm>
    Re: Better coding through inheritance? <s_grazzini@hotmail.com>
    Re: Better coding through inheritance? <vm.mayer@comcast.net>
    Re: DBI, mysql, how do I get the results into an array  ctcgag@hotmail.com
    Re: help with Win32::OLE MS Word <brian_helterline@hp.com>
    Re: Help! Bad Interperter: no such file or directory (David Efflandt)
    Re: how to debug anonymous functions <garry@ifr.zvolve.net>
    Re: LWP-download help <mgjv@tradingpost.com.au>
    Re: menu ? <mgjv@tradingpost.com.au>
    Re: menu ? (Jay Tilton)
    Re: Newbie with Perl <bart.lateur@pandora.be>
    Re: Perl: string vs. numeric <s_grazzini@hotmail.com>
        referening a returned array? (Vorxion)
    Re: referening a returned array? (Alan Barclay)
        Try your hand at perl golf (Ton Hospel)
        UTF8 counting first octet hi bits <ekulis@apple.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 13 Nov 2002 00:01:05 GMT
From: NOSPAMmdknight@pacific.net.sg (Sir Loin of Beef)
Subject: [Q] Script to search auction sites?
Message-Id: <3dd19617.6357935@news.pacific.net.sg>

I would like to write a small script with a single text box and button
that can search 2 local auction sites for items simultaneously. Is
this possible? How would I go about it?

Thanks.


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

Date: Tue, 12 Nov 2002 19:31:01 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: [Q] Script to search auction sites?
Message-Id: <3DD19D45.6040904@thecouch.homeip.net>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1



Sir Loin of Beef wrote:
| I would like to write a small script with a single text box and button
| that can search 2 local auction sites for items simultaneously. Is
| this possible? How would I go about it?

You'll need a working /cgi-bin/ directory to start off.

Use the CGI module to interface and collect the information from the web
browser.  See http://search.cpan.org/author/JHI/perl-5.8.0/lib/CGI.pm
for details.

Use LWP or LWP::Simple to connect to the remote auction sites.  See
http://search.cpan.org/author/GAAS/libwww-perl-5.65/lib/LWP/Simple.pm
for details.

Parse the returning results if necessary.  See
http://www.perldoc.com/perl5.8.0/pod/perlre.html for details.


Best of luck.

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE90Z1FeS99pGMif6wRAo0UAJ4mbvcoLONQvIIylU74M98x02Q0fwCfdpbW
6Lk+euw9rjkaOtVs1HOGA0U=
=u3kM
-----END PGP SIGNATURE-----



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

Date: Wed, 13 Nov 2002 00:38:36 +0100
From: Michael Schlenker <schlenk@uni-oldenburg.de>
Subject: Re: A vision for Parrot
Message-Id: <aqs2vm$cuehl$1@ID-102549.news.dfncis.de>

MikkelFJ wrote:
> Sorry for the repost at perl, I didn't release the post was crossposted (I
> entered via Ruby).
> 
> 
> "Neil Madden" <nem00u@cs.nott.ac.uk> wrote in message
> news:LRaA9.1325$J55.292310@newsfep2-win.server.ntli.net...
> 
> 
>>Hmm.. the more I think about this, the more problems it seems to present.
> 
> I'd
> 
>>love to be able to write an extension, and have it instantly work with x
>>different langauges. Also, I'd love to be able to use Python and Perl
>>extensions from Tcl, without loading seperate interpreters and all that.
> 
> Am I
> 
>>dreaming of an impossible Utopia?
> 
> 
> I wrote some DLL helper logic that makes it easy to query a vtable by name
> in another DLL.
> The vtables can be created in whatever way, but the vtable is not assocated
> with allocated memory, as is the case with COM. This makes it quite flexible
> without really being limited because one could decide that the first
> function should return a 'this' pointer and the second function should be
> the destructor, or whatever.

Basically the same as the Tcl STUBS mechanism for loading extensions in 
different versions of the tcl interpreter without recompiling or 
relinking the extension.

Michael



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

Date: Tue, 12 Nov 2002 17:18:23 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: About to tear my hair out here ... (Newbie Question)
Message-Id: <aqs2ig$1nr$1@slb5.atl.mindspring.net>

"Simon" <simontheak@hotmail.com> wrote in message
news:495e297c.0210180814.441844@posting.google.com...
<snip>
> Anyway, I'm stuck at the first hurdle. All I'm trying to do is write a
> script that accepts the input from an HTML form and writes it up to
> the screen.
>
> Here's what I've got:
>
> #!/usr/bin/perl
> $formdata = $ENV{'CONTENT_LENGTH'}

This appears to have been your first hurdle. None of us appears to have
helped you over it. Try:

#!/usr/bin/perl -w
use strict;
read(STDIN, my $formdata, $ENV{'CONTENT_LENGTH'});

> print "Content-type:text/html\n\n";
>
> print "<html><head><title>Test Page</title></head>\n";
> print "<body>\n";
> print "<h2>Hello, world!</h2>\n";
> print $formdata;
> print "</body></html>\n";
>
> As you can probably imagine, it's not working. Anyone got any idea
> why? I can't tell you HOW greatful I would be!

Your code, with my modifications, worked fine on this system, except I
didn't wish to make a form to submit data to it.

When you use your form that submits to your (corrected) script, you'll find
your formdata is actually printed on the screen, but in the URL-encoded
format in which it was presented to the server.

That said (written), I'd suggest you skip the first hurdle and go directly
to using CGI.pm, where your code could be something like (tested w.
IndigoPerl):

#!perl -w
use strict;
use CGI qw(-no_xhtml :standard *pre);
print header, start_html('Test Page'), h2('Hello, world!'), hr, 'You
entered:', start_pre;
foreach (param()){print p, $_, ' = ', param($_)}
print end_pre, end_html;

One advantage you'll find in favor of your use of CGI.pm is that you can
test your code from the command line, query string, or a POST from a form,
e.g., try something like pointing your browser to (after you've tested the
code from the command line):

http://localhost/cgi-bin/simontheak.pl?first=Simon;last=Theak

(if necessary, change the path to that which is appropriate for your system)
to see what you get from my version of your script.

Bill Segraves










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

Date: Tue, 12 Nov 2002 17:37:05 -0600
From: Lance Hoffmeyer <lance@augustmail.com>
Subject: Better coding through inheritance?
Message-Id: <pan.2002.11.12.23.37.05.579488.8037@augustmail.com>

I am not a developer so please excuse me if I got my terminology wrong
in using the word inheritance.  I am writing code that I will be using
over and over again.  I would like to take the common components that I
will be using and put them in a seperate file so that I can clean things
up a little.  I would like to put the code below in a file called month.pl
and then use it in another file called print.pl.  What do I need to change
to use these files like this?

Lance


################## print.pl ####################
use month.pl;


print "$numonth \n";
print "$numonthfull \n";
my $var1 = column2column_number("A");
print "var1 \n";


################## month.pl ####################
# Get Month so we can set quartly titles and monthly columns;
my $now = ctime();
my ($day,$month,$numday,$tim,$yr) = unpack("A4 A4 A3 A9 A4",$now);
# Convert Current month to numeric month in which data is being reported
# If month=December then reporting month = November
#
my %months=(Jan=>"12", Feb=>"01", Mar=>"02", Apr=>"03", May=>"04", 
            Jun=>"05",Jul=>"06", 
            Aug=>"07", Sep=>"08", Oct=>"09", Nov=>"10", Dec=>"11");
my %monthsfull=(1=>"January", 2=>"February", 3=>"March", 
                4=>"April", 5=>"May", 6=>"June",7=>"July", 
                8=>"August", 9=>"September", 10=>"October", 
                11=>"November", 12=>"December");

my $numonth = $months{$month};
my $numonthfull = $monthsfull{$numonth};

#my $monyr = $numonth.$yr;
#print "$monyr\n";

my $qtrcol = "c";
if($monyr=~/102002/){$qtrcol="d"};
if($monyr=~/112002/){$qtrcol="e"};
if($monyr=~/122002/){$qtrcol="f"};
if($monyr=~/012003/){$qtrcol="g"};
if($monyr=~/022003/){$qtrcol="h"};
if($monyr=~/032003/){$qtrcol="i"};
if($monyr=~/042003/){$qtrcol="j"};
if($monyr=~/052003/){$qtrcol="k"};
if($monyr=~/062003/){$qtrcol="l"};
if($monyr=~/072003/){$qtrcol="m"};
if($monyr=~/082003/){$qtrcol="n"};
if($monyr=~/092003/){$qtrcol="o"};
if($monyr=~/102003/){$qtrcol="p"};
if($monyr=~/112003/){$qtrcol="q"};
if($monyr=~/122003/){$qtrcol="r"};


# Change columns to numbers for regex later
sub column2column_number{
my %col2num = ("A" => 1, "B" => 2, "C" => 3, "D" => 4, "E" =>  5,"F" => 6,
    "G" => 7, "H" => 8, "I" => 9, "J" => 10, 
    "K" => 11,"L" => 12,"M" => 13,"N" => 14,
    "O" => 15,"P" => 16,"Q" => 17,"R" => 18,"S" => 19,"T" => 20, 
    "U" => 21,"V" => 22,"W" => 23,"X" => 24,"Y" => 25,"Z" => 26,
    "a" => 1, "b" => 2, "c" => 3, "d" => 4, "e" =>  5,"f" => 6,
    "g" => 7, "h" => 8, "i" => 9, "j" => 10, 
    "k" => 11,"l" => 12,"m" => 13,"n" => 14,
    "o" => 15,"p" => 16,"q" => 17,"r" => 18,"s" => 19,"t" => 20, 
    "u" => 21,"v" => 22,"w" => 23,"x" => 24,"y" => 25,"z" => 26
);
my $colnum = $col2num{$_[0]};#This $_[0] is the way to pass an argument#
}



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

Date: Wed, 13 Nov 2002 01:21:39 GMT
From: "David K. Wall" <me@dwall.fastmail.fm>
Subject: Re: Better coding through inheritance?
Message-Id: <Xns92C4CF2042268dkwwashere@204.127.202.16>

Lance Hoffmeyer <lance@augustmail.com> wrote:

> I am not a developer so please excuse me if I got my terminology wrong
> in using the word inheritance.  I am writing code that I will be using

Inheritance usually refers to object-oriented programming....

> over and over again.  I would like to take the common components that
> I will be using and put them in a seperate file so that I can clean
> things up a little.  I would like to put the code below in a file
> called month.pl and then use it in another file called print.pl.  What
> do I need to change to use these files like this?

See 'perldoc -q "create a module"'

Also check out the perlmod and perlnewmod section of the Perl docs.  What 
you want to do is create your own module of code you commonly use.

In my opinion these docs aren't terribly great at introducing the 
subject;  I think they're intended more for people who already know what 
to do and just need to look up specifics.  I'd recommend a book or two, 
but I'm at home now and all my books are at work.  There's probably stuff 
on the web, too, but you can search as easily as I can. :-)

You'll find the h2xs program (comes with a standard install of Perl) to 
be helpful in creating a module.  It will create a skeleton module which 
you can flesh out.

-- 
David Wall - me@dwall.fastmail.fm
"Oook."


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

Date: Wed, 13 Nov 2002 01:34:02 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: Better coding through inheritance?
Message-Id: <e_hA9.112478$Up6.23602789@twister.nyc.rr.com>

Lance Hoffmeyer <lance@augustmail.com> wrote:
> I am not a developer so please excuse me if I got my 
> terminology wrong in using the word inheritance.

You did, I'm afraid...

> I am writing code that I will be using over and over again.  I 
> would like to take the common components that I will be using 
> and put them in a seperate file so that I can clean things up a 
> little.  I would like to put the code below in a file called 
> month.pl and then use it in another file called print.pl.  What 
> do I need to change to use these files like this?
> 
> Lance
> 
> 
> ################## print.pl ####################
> use month.pl;

  require 'month.pl';

And check:

  $ perldoc perlmod
  $ perldoc -f use
  $ perldoc -f require

HTH
-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


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

Date: Tue, 12 Nov 2002 20:48:20 -0500
From: Mike Mayer <vm.mayer@comcast.net>
Subject: Re: Better coding through inheritance?
Message-Id: <vm.mayer-08C5B7.20482012112002@news-east.giganews.com>

In article <pan.2002.11.12.23.37.05.579488.8037@augustmail.com>,
 Lance Hoffmeyer <lance@augustmail.com> wrote:

> I am not a developer so please excuse me if I got my terminology wrong
> in using the word inheritance.  I am writing code that I will be using
> over and over again.  I would like to take the common components that I

The word you are looking for is "reuse." 

mike


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

Date: 13 Nov 2002 00:07:21 GMT
From: ctcgag@hotmail.com
Subject: Re: DBI, mysql, how do I get the results into an array without
Message-Id: <20021112190721.019$GG@newsreader.com>

"Brandon L" <spam@digitaltension.com> wrote:
> I keep getting this error in my logs. I cant figure out the problem.
> Below is my script I am using, I am a novice-intermediate scripter (aka i
> dont know that much). This use to generate a lot more errors but it only
> does one error per page view now.
>
> DBD::mysql::st fetchrow_array failed: fetch() without execute() at
> ./inc/common.inc line 109.

Oddly enough, I started seeing this problem just a few days
ago on code I (alas) have to maintain.

I don't understand people's fascination with creating subroutine
wrappers around DBI's methods.  Why not just use the methods
directly?  If you used the method directly, the error message
would tell you where you're problem was occuring, rather than just
pointing to a general-purpose subroutine.

> next, in various parts of my script i use this sub like this:
> $query = qq~SELECT * FROM database WHERE 1~;

You are not using strict.  Ugh.


> sqlQuery($query);

You are retrieving the results through a global variable, rather than
as the return value of the subroutine.  Ugh Ugh.


> sub sqlQuery {
>   undef(@sqlResults);
>
>   $myQuery = "$_[0]";
>
>   $sth = $dbh->prepare($myQuery);
>   # Shouldnt this fix the fethrow_array failed without execution error?
>   $rv = $sth->execute or die "executing: ", $dbh->errstr;

That depends on what is causing the error.  I bet you call sqlQuery with
a query of "Update blah" or "Insert blah" at some point.  The execute
succeeds, so there is no error to catch at this point.  On the other hand,
the query was not a select, so it doesn't set itself up for future
invokation of fetch.

>
>   while (@sqlArray = $sth->fetchrow_array) {
>     @sqlArray = join ("|", @sqlArray);

Ack.  Store scalars in scalars.

>     push(@sqlResults, "@sqlArray");

double Ack.  why the quotes?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
                    Usenet Newsgroup Service


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

Date: Tue, 12 Nov 2002 15:50:15 -0800
From: "Brian Helterline" <brian_helterline@hp.com>
Subject: Re: help with Win32::OLE MS Word
Message-Id: <aqs46t$63f$1@hpcvsgen.cv.hp.com>

"ted" <tednospam94107@yahoo.com> wrote in message
news:<aqqdmq$k4c$1@slb2.atl.mindspring.net>...
> Hello,
>
> I'm trying to extract text from MS Word docs that have tables and bulleted
> lists.
>
> How would I detect tables and bulleted lists (and nested lists) in the
Word
> doc? They are scattered throughout the doc.
>
> Any help appreciated. Thanks.
> -Ted
>
Hi Ted,
There is a Tables collection for the document that contains all the tables
within the document.
Word->Document->Tables
Bulleted lists are just a format style so you would have to search for a
style to locate them.
-brian




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

Date: Wed, 13 Nov 2002 00:02:34 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Help! Bad Interperter: no such file or directory
Message-Id: <slrnat35kq.32h.efflandt@typhoon.xnet.com>

On 11 Nov 2002 19:26:30 -0800, Corey Andrews <matirxrabbit@Hotmail.com> wrote:
> Hey,
> I'm running slack 8.1, and for some odd reason, my perl scripts won't
> run.  When I type in the cmd "perl script.pl" it tests and runs fine,
> but typing in the "./script.pl" by itself comes out with the error "
> bad interperter: no such file or directory ".  Is this normal?
> Checking twice (using cmd "which perl")..i'm pretty sure I got
> everything down. It's chmod 755 and I even downloaded the most recent
> perl interperter to be sure.  But it's still no go.  I need to be able
> to run this correctly so my cgi scripts will work on my httpd server. 
> Any ideas?

Has the script touched a Windows box?  DOS/Win ends text lines with CR-LF
(carriage return, linefeed = ^M^J or \015\012) and Unix ends text lines
with just LF.  It is possible that the error is attempting to tell you
that it cannot find "perl^M", but the ^M prints as invisible CR.  In that
case you either need to ftp upload the script as ASCII text (not binary)
or otherwise remove the carriage returns without removing linefeeds.

-- 
David Efflandt - All spam ignored  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Wed, 13 Nov 2002 00:17:58 -0000
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: how to debug anonymous functions
Message-Id: <slrnat36hm.sai.garry@zfw.zvolve.net>

On 12 Nov 2002 10:53:36 -0800, Raj <raj@tao.ca> wrote:
> does anyone know if this is possible? If yes, do you know how
> I would go about setting a breakpoint and step through the code?
> I believe I tried it in the past and it didn't work. But I have
> not definitively verified this. 
> 
> Thanks for any help!

I can't imagine why you wouldn't do the obvious and try it.  

    $ perl -d
    Default die handler restored.

    Loading DB routines from perl5db.pl version 1.07
    Editor support available.

    Enter h or `h h' for help, or `man perldebug' for more help.

    $p = sub { print "hello from anon sub\n";
		return 1; };
    print "about to call \$p->()\n";
    print $p->(), "\n";
    print "done\n";
    __END__
    main::(-:2):	            return 1; };
      DB<1> b 2
      DB<2> c
    about to call $p->()
    hello from anon sub
    main::CODE(0x100ab0)(-:2):	            return 1; };
      DB<2> c
    1
    done
    Debugged program terminated.  Use q to quit or R to restart,
      use O inhibit_exit to avoid stopping after program termination,
      h q, h R or h O to get additional info.  
      DB<2>

-- 
Garry Williams


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

Date: Tue, 12 Nov 2002 23:24:10 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: LWP-download help
Message-Id: <slrnat33hc.2kt.mgjv@verbruggen.comdyn.com.au>

On 12 Nov 2002 06:44:34 -0800,
	Chris Liu <fcqmax@pchome.com.tw> wrote:
> fcqmax@pchome.com.tw (Chris Liu) wrote in message news:<806277c.0211120020.8bfb3b3@posting.google.com>...
>> Somehow lwp-download doesn't recognize the variables in the URL string
>> when I use the GET method. Any advice? Thanks.
>> 
>> a perl newbie
> 
> duh...ok, I'm one step up a newbie.. lwp-download doesn't recognize
> get url strings...

I doubt that you're right.

Can you please post exactly what you gave as an argument to
lwp-download?

Martien
-- 
                        | 
Martien Verbruggen      | Never hire a poor lawyer. Never buy from a
Trading Post Australia  | rich salesperson.
                        | 


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

Date: Tue, 12 Nov 2002 23:34:38 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: menu ?
Message-Id: <slrnat344v.2kt.mgjv@verbruggen.comdyn.com.au>

On Tue, 12 Nov 2002 20:26:31 -0800,
	Linux.ie <mail@eircom.net> wrote:
> Hi all.
> I want help with a script.ITS NOT HOMEWORK !!!!
> 
> I want to have a menu in my program.With then parts to it each part numbered
> and with a name to it.
> i want to be able to enter a number and select a option and when i select
> that option it will show info for that option and also be given a option to
> back to the main menu.

Print your "options", with a number or letter in front of it. Read one
line, do whatever it is you need to do based on that number, then
return.

Alternatively, you could see whether someone has done what you want in
a module for. Check search.cpan.org. if you have curses, you could
look at Curses::Widgets::Menu, Cdk::Menu or Cmenu. If you don't have
curses, maybe Term::prompt can be of help.  If you're looking for GUI
stuff, look at Tk::Menu, maybe.

Martien
-- 
                        | 
Martien Verbruggen      | The four horsemen of the apocalypse are
Trading Post Australia  | called Abort, Retry, Ignore and Fail.
                        | 


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

Date: Wed, 13 Nov 2002 00:45:48 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: menu ?
Message-Id: <3dd19afc.13837507@news.erols.com>

"Linux.ie" <mail@eircom.net> wrote:

: Hi all.
: I want help with a script.ITS NOT HOMEWORK !!!!

Stop shouting.

: I want to have a menu in my program.With then parts to it each part numbered
: and with a name to it.
: i want to be able to enter a number and select a option and when i select
: that option it will show info for that option and also be given a option to
: back to the main menu.
: 
: please someone help

Help how?  Write the program for you?  Fat chance.

What have you tried so far?

Do you even have an algorithm conceptualized, e.g.
    1. Print menu/message.
    2. Wait for user input.
    3. React to user input.
    4. Repeat.

Did you read the FAQ (perldoc -q menu)?  Was that answer
unsatisfactory in some way?



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

Date: Wed, 13 Nov 2002 01:40:35 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Newbie with Perl
Message-Id: <qqa3tugrrp7s6jdu215aggagepe0a2bv0r@4ax.com>

Michael J Wilusz wrote:

> Sure, I can pick up a Perl book and thumb through 700
>pages... and then when I'm done reading it, I can be all set to retire.
>Judging from the example code, there are certain parallels with Java, but
>there's many hurdles to still jump over.

Well then maybe it's a matter of picking proper tutorials. Online
articles on Perl are often nice. <http://www.perl.com> has a few;
<http://hotwired.lycos.com/webmonkey/programming/> also. But my
favourites by far are the magazine columns by Randal L. Schwartz,
<http://www.stonehenge.com/merlyn/columns.html>. Many of these are very
similar in spirit to your problem here, Especially those in UnixReview,,
so it seems, so they may help you get on the way quickly.

	<http://www.stonehenge.com/merlyn/UnixReview/>

-- 
	Bart.


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

Date: Wed, 13 Nov 2002 01:30:49 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: Perl: string vs. numeric
Message-Id: <dXhA9.112476$Up6.23599945@twister.nyc.rr.com>

Daniel Pfeiffer <occitan@esperanto.org> wrote:
> Derek Thomson <derek@wedgetail.com> skribis:
>> If you want the subroutine to try to detect if the argument is not a 
>> number, and then quote it, you'll find ways to do this in the Perl 
>> documentation that you already have.
> 
> Does it?  I've looked, and I've also looked at the way Data::Dumper 
> does it:  When it uses the extension it get's it right, but when 
> doing it in Perl it gets it wrong!  It seems absolutely impossible 
> to distinguish numbers from number-like strings.

It's maybe harder than it needs to be, but certainly
not impossible.

  sub is_stringy { ($_[0] ^ $_[0]) ne '0' }

Or:

  use B qw/svref_2object SVf_POK/;

  sub is_stringy { 
    svref_2object(\$_[0])->FLAGS & SVf_POK 
  } 

> That Perl can handle numbers as strings and inversely is almost 
> always convenient.  But at times one would want to know what kind 
> of argument one got.
> 
> One case I stumbled across is that Perl stupidly uses a different 
> parser for transforming a string to a number than when compiling.  
> This is a catastrophe if you want to handle octal values and '0123' 
> != 0123.  So the caller of such a function has to do extra things, 
> like not just conveniently pass qw/0123 .../, or call oct when 
> reading from some source.

You seem to understand perl's behavior, but maybe
this will still be useful:

  http://groups.google.com/groups?selm=3bc04c81.4f7b%249f%40news.op.net

Skip to the end if you want some justification for
the 'stupidity'.

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


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

Date: 12 Nov 2002 18:29:57 -0500
From: vorxion@fairlite.com (Vorxion)
Subject: referening a returned array?
Message-Id: <3dd18ef5$1_2@news.iglou.com>

Okay, using MIME::Entity I'm trying to use the body() method.  The docs
claim that it returns the body in an array of lines.  Okay...

@body = $top->body;
forech (@body) {print;}

 ...And this yields:

ARRAY(0x34078c)

Someone care to tell me how to get INTO that array?  Please?

-- 
Vorxion - Member of The Vortexa Elite


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

Date: 13 Nov 2002 00:39:53 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: referening a returned array?
Message-Id: <1037147993.401762@elaine.furryape.com>

In article <3dd18ef5$1_2@news.iglou.com>, Vorxion <vorxion@fairlite.com> wrote:
>...And this yields:
>
>ARRAY(0x34078c)
>
>Someone care to tell me how to get INTO that array?  Please?

You have a reference to the array. Use

$body = $top->body;
foreach(@{$body){ print; }

and check 'perldoc perlref' and 'perldoc perlreftut'



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

Date: Wed, 13 Nov 2002 01:53:22 +0000 (UTC)
From: thospel@mail.dma.be (Ton Hospel)
Subject: Try your hand at perl golf
Message-Id: <aqsbai$eb3$1@post.home.lunix>

perl golf = trying to solve a certain problem with perl using
as few characters as possible.

The monthly challenge now running: http://perlgolf.sourceforge.net/TPR/0/6/
Prizes for the winners, fun for all.


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

Date: Tue, 12 Nov 2002 17:41:55 -0800
From: Ed Kulis <ekulis@apple.com>
Subject: UTF8 counting first octet hi bits
Message-Id: <B9F6EDE3.49EF%ekulis@apple.com>

Hi,

I'm trying to decode UTF-8 so that I can protect various conversion
functions from characters that they can't deal with

Here's the UTF-8 bit coding scheme

First 
octet 
range

0  -127: 0xxxxxxx 

192-223: 110xxxxx 10xxxxxx
224-239: 1110xxxx 10xxxxxx 10xxxxxx
240-247: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
248-251: 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
252-255: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx

You'll notice that when the first bit is 1 the number of 1's before the 0
incdicate the number of the multi-octets in the UTF-8 code.

I'd like some clever way to determing the number of bits before the 0.

It seems that there's a more elegant way to find out then to check the
ranges and then map the range to the number of octets in for the UTF8
character.

Is there a way to do something like a "Roll Left Thru Carry" to determine
the numnber of hi bits before the first 0 ?

Is there some masking technique that can show the # of bits before the first
0 ?

I've tried some of the bit shift operations like ">>" and "<<" but they
leave you with the result after the bit shift but I can't seem to find a
simple way to determine which bit got shifted off the left say when you

    $b = 192 << 1 ;


-ed



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

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


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