[18502] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 670 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 10 18:16:27 2001

Date: Tue, 10 Apr 2001 15:15:28 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <986940927-v10-i670@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 10 Apr 2001     Volume: 10 Number: 670

Today's topics:
        Private subroutine inside subroutine (Brian E. Lavender)
    Re: registration script <amazingkgb@earthlink.net>
    Re: registration script <amazingkgb@earthlink.net>
    Re: save a value of a variable between subroutines run. <webmaster@webdragon.unmunge.net>
    Re: save a value of a variable between subroutines run. <bart.lateur@skynet.be>
    Re: SMB or NetBios? Spoofing. (On Topic) <alessandro.augusto@br.bosch.com>
    Re: SMB or NetBios? Spoofing. (On Topic) <wayne.keenan@ntlworld.com>
    Re: SMB or NetBios? Spoofing. nobull@mail.com
    Re: So what do YOU use Perl for? <a.v.a@home.nl>
    Re: So what do YOU use Perl for? (Craig Berry)
        THANK YOU & FINAL CODE <NO_SPAM_klubbheads@home.com>
    Re: THANK YOU & FINAL CODE <joe+usenet@sunstarsys.com>
    Re: To run perl in the backround <T_boss75@curanet.com>
    Re: unicode, perl and webbrowsers <flavell@mail.cern.ch>
    Re: unicode, perl and webbrowsers <elijah@workspot.net>
    Re: unicode, perl and webbrowsers <flavell@mail.cern.ch>
    Re: using dup() <rick.delaney@home.com>
    Re: using dup() <bart.lateur@skynet.be>
    Re: Using References (Mark Jason Dominus)
    Re: Using References <lmoran@wtsg.com>
    Re: We have 'use strict' and 'my', and now 'our', but n <gtoomey@usa.net>
        Why is finish() necessary here with DBI? Bug in DBD::OD <webmuse@my-deja.com>
    Re: win32: *.pl > *.exe howto <gellyfish@gellyfish.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 10 Apr 2001 21:49:00 -0000
From: brian@brie.com (Brian E. Lavender)
Subject: Private subroutine inside subroutine
Message-Id: <td6vucqr8165af@corp.supernews.com>


I created a private subroutine inside another subroutine.  Rather than
pass the variables to the private subroutine, I made them visible to
the private subroutine using local. Is this good coding practice? I am
still don't completely understand local, but it appears it is making
$arg2 visible to any block inside outer. Here's my sample chunk of code.

TIA,

brian

#!/usr/local/bin/perl

use strict;

sub outer (@) {
    use vars qw($arg2);
    my $arg1 = shift;
    local $arg2 = shift;
    
    print "outer arg1: $arg1\n";

    _inner();

    sub _inner {
        print "inner arg2: $arg2\n";
    }
  
}


main: {
    my $arg2;
    outer("fred","barney");
    print "Inside main ",$arg2, "\n";
    # should print nothing for $arg2
}

-- 
Brian Lavender
http://www.brie.com/brian/


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

Date: Tue, 10 Apr 2001 18:22:31 GMT
From: "Atayarani" <amazingkgb@earthlink.net>
Subject: Re: registration script
Message-Id: <HbIA6.73$c53.14071@newsread1.prod.itd.earthlink.net>


"Steven Smolinski" <sjs@linux.ca> wrote in message
news:slrn9d54u9.1o1.sjs@ragnar.stevens.gulch...
> [ Please post your comments at the end of the suitably trimmed article
> you're replying to.  The regulars around here prefer it, and you will
> get more help from them that way. Jeopardectomy performed. ]
>
> Atayarani <amazingkgb@earthlink.net> wrote:
> > "Steven Smolinski" <sjs@linux.ca> wrote:
> > > Atayarani <amazingkgb@earthlink.net> wrote:
> > > > I am very new to Perl, but hope that I will get some helpful
> > > > responses.
> > >
> > > To get helpful responses, you must help people to understand the
> > > problem.
> > >
> > > > [... snip CGI program "doesn't work": 500 server error ...]
> >
> > I get an error: 500
> >
> > the pages are: www.atayarani.com/form.html
> > and www.atayarani.com/cgi-bin/readinput.pl
>
> We can't see the code in that second URL, of course, because the
> webserver tries to execute it.
>
> In any case, did you look at the URLs I posted at all?  They would have
> told you to check lots of things:
>
> - Did you run the script from the command line?
> - Did you fix all the warnings/errors from the command line?
> - Did you use -w, -T and strict?
>
> In any case, I looked at the form.html quickly.  It's non-compliant HTML
> by a long shot.  Your quoting is all over the place.  All the inputs
> look like this:
>
>     <input type = "text" size = "35 name = "address>
>
> when they should look like this:
>
>     <input type="text" size="35" name="address">
>
> If the page even works, it's by magic and all-too-forgiving browser
> manufacturers.  But that's off-topic here.  Fix your HTML, try debugging
> the script from the command line and let us know how you did.
>
> HTH.
>
> Steve
> --
> Steven Smolinski => http://www.steven.cx/
>

Nothing wrong with the page itself, after submitting there were issues, but
it was solved by changing the case of a few sections




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

Date: Tue, 10 Apr 2001 18:24:01 GMT
From: "Atayarani" <amazingkgb@earthlink.net>
Subject: Re: registration script
Message-Id: <5dIA6.77$c53.14434@newsread1.prod.itd.earthlink.net>


"PropART" <temp1@williamc.com> wrote in message
news:3AD307F3.6D118F7A@williamc.com...
> Atayarani wrote:
> >
> > I am very new to Perl, but hope that I will get some helpful responses.
I
> > am trying to create a script for my page, in which a user can register
(for
> > benefits unknown) and all information submitted is sent to a specified
email
> > address.  I currently am using a script copied from a book, for a start.
It
> > did not work, I got an Internal Server Error.  The permissions are
correct,
> > and the path is correct.  I have no idea where it went wrong.
> >
> > -atayarani
>
> Note: you shouldn't cross-post and you shouldn't ask questions that
> are not related to the Perl language in this news group.

How is this not related to the Perl language?  It is a perl script I had
issues with.

>
> does yr. Perl code compile on the command line? did you xfer it to the
> server as ascii? are you sending the correct response header back? are
> you using CGI.pm? are all special characters escaped correctly? what
> does your error log say?
>
> If you don't know how to check your error log you also might try
> adding this line to redirect errors...
>
> use CGI::Carp qw(carpout fatalsToBrowser);
>
> --williamc
>






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

Date: 10 Apr 2001 18:28:25 GMT
From: "Scott R. Godin" <webmaster@webdragon.unmunge.net>
Subject: Re: save a value of a variable between subroutines run... (++)
Message-Id: <9avjc9$ctp$1@216.155.33.76>

In article <sTCA6.197879$A6.43915858@news4.rdc1.on.home.com>,
 "Roman Filippov" <NO_SPAM_klubbheads@home.com> wrote:

 | > particularly when you can
 | >
 | > #!perl -w
 | > use strict;
 | > use CGI qw/:standard/;
 | >
 | > my @tabledata = qw/one two three four five six seven/;
 | >
 | > print table("\n",
 | >         map { Tr(td($_)), "\n"} @tabledata,
 | >       );
 | >
 | > with CGI.pm you can literally create your HTML template using the
 | > function-oriented interface of the CGI module. MUCH simpler, unless your
 | > HTML is so blastedly complex this would be otherwise impossible.. That's
 | > for you to decide.
 | >
 | 
 | As i said, I don't like modules. And btw, i implemented my own include
 | feature in templates.

I utterly and completely cannot understand why you wouldn't like 
something that makes your job easier, i.e. simpler to write, and easier 
to maintain.

Why re-invent the wheel? 

There's also various ::Template modules that can do similar things for 
more complex html/text formats. 

Yes things can be done without them, but having easily parsed 
maintainable code that practically writes itself, is not something to be 
so easily ignored. However, suit yourself. *shrug*

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: Tue, 10 Apr 2001 21:26:17 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: save a value of a variable between subroutines run... (++)
Message-Id: <vgu6dt0ipsffl9tgaol5pg0lha1o3k5k73@4ax.com>

Roman Filippov wrote:

>So, the problem is, that I don't want to open and close 100 times, because
>it can overload a machine. I want $filename and @file value to be saved
>between the runs of the subroutine. At the same time I don't want the
>variables to be global, I want them to be local. In this case I could check
>if the 'old' $filename matches a new one, that was send as an argument and
>if it does match then DO NOT read the file again, if filenames do not match
>then read the file.

Are you talking about memoization? Then maybe check out
<http://search.cpan.org/search?dist=Memoize>.

-- 
	Bart.


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

Date: Tue, 10 Apr 2001 14:30:54 -0300
From: Alessandro <alessandro.augusto@br.bosch.com>
Subject: Re: SMB or NetBios? Spoofing. (On Topic)
Message-Id: <3AD3434E.AAE1C578@br.bosch.com>

nobull@mail.com wrote:
>> Even if you could somehow have believed the first part of your
>> question was on topic there is no way whatever you could produce a
>> convincing argument that you believed this was on topic.

Off course its on topic.

>> After the recent disucussions about the difficultly in drawing the
>> line between the problem domain and the language domain Alessandro
>> is quite simply taking the piss when he writes

I have no idea what are you talking about.

alessandro> I wanna know what protocol does perl for NT uses to connect
with the
alessandro> remore machines. Is is SMB or NetBios?

>> I think you mean you want to know what protocol a particular program
>> written in Perl uses. Read the source or read the documentation or ask
the
>> author.

Great answer. I am the author! And I have no ideia.
I am using Adminmisc and TieRegistry modules, and I havent seen any part
that
it specify the protocol.

alessandro> After I discover the protocol, I would like to know about
spoofing.

this is true and possible if you dont know.
I developed an script to automate remote tasks for a NT network. But if I
or someone discover what data is sent by my script to the workstations,
the bad person can try to spoof the workstations.

this is a problem, and maybe I can use perl to encript the data. So I
thought
someone here have already thinked about it.

How to secure the perl data transfered between the server and the
workstations.

Alessandro



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

Date: Tue, 10 Apr 2001 20:48:45 +0100
From: "wayne.keenan" <wayne.keenan@ntlworld.com>
Subject: Re: SMB or NetBios? Spoofing. (On Topic)
Message-Id: <3AD3639D.AF7947D3@ntlworld.com>

checkout
Net::PlRPC


Alessandro wrote:

> nobull@mail.com wrote:
> >> Even if you could somehow have believed the first part of your
> >> question was on topic there is no way whatever you could produce a
> >> convincing argument that you believed this was on topic.
>
> Off course its on topic.
>
> >> After the recent disucussions about the difficultly in drawing the
> >> line between the problem domain and the language domain Alessandro
> >> is quite simply taking the piss when he writes
>
> I have no idea what are you talking about.
>
> alessandro> I wanna know what protocol does perl for NT uses to connect
> with the
> alessandro> remore machines. Is is SMB or NetBios?
>
> >> I think you mean you want to know what protocol a particular program
> >> written in Perl uses. Read the source or read the documentation or ask
> the
> >> author.
>
> Great answer. I am the author! And I have no ideia.
> I am using Adminmisc and TieRegistry modules, and I havent seen any part
> that
> it specify the protocol.
>
> alessandro> After I discover the protocol, I would like to know about
> spoofing.
>
> this is true and possible if you dont know.
> I developed an script to automate remote tasks for a NT network. But if I
> or someone discover what data is sent by my script to the workstations,
> the bad person can try to spoof the workstations.
>
> this is a problem, and maybe I can use perl to encript the data. So I
> thought
> someone here have already thinked about it.
>
> How to secure the perl data transfered between the server and the
> workstations.
>
> Alessandro



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

Date: 10 Apr 2001 17:34:50 +0100
From: nobull@mail.com
Subject: Re: SMB or NetBios? Spoofing.
Message-Id: <u9hezwaf2t.fsf@wcl-l.bham.ac.uk>

After the recent disucussions about the difficultly in drawing the
line between the problem domain and the language domain Alessandro
<alessandro.augusto@br.bosch.com> is quite simply taking the piss when
he writes:

> I wanna know what protocol does perl for NT uses to connect with the
> remore machines. Is is SMB or NetBios?

I think you mean you want to know what protocol a particular program
written in Perl uses.

Read the source or read the documentation or ask the author.

> After I discover the protocol, I would like to know about pacot
> spoofing.

Even if you could somehow have believed the first part of your
question was on topic there is no way whatever you could produce a
convincing argument that you believed this was on topic.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 10 Apr 2001 15:09:53 GMT
From: AvA <a.v.a@home.nl>
Subject: Re: So what do YOU use Perl for?
Message-Id: <3AD2FA02.2F7F8C93@home.nl>

Lou Moran wrote:

> On Sat, 07 Apr 2001 20:43:01 -0400, Szilvia Oszko <soszko@gmu.edu>
> wrote wonderful things about sparkplugs:
>
> >One recurring theme in this newsgroup seems to be that Perl!=CGI and
> >that while Perl is often used to write CGI scripts, it can also be used
> >to do a lot of other things. I'd be curious to see what non-CGI stuff
> >you do with Perl.
>
> I used Perl to learn programming.  And I find myself using it over the
> other languages I have picked up along the way.
>
> --
> print "\x{263a}"

take a look at www.perl.com , ull find that u can do alot with perl...f.i.
to write gnome applications



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

Date: Tue, 10 Apr 2001 18:45:16 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: So what do YOU use Perl for?
Message-Id: <td6l5scc8eosfe@corp.supernews.com>

Bart Lateur (bart.lateur@skynet.be) wrote:
: Elaine Ashton wrote:
: >True but far and away the most searched for items on search.cpan.org are
: >DBI, CGI, LWP, MIME::*, HTML::* and XML. While this doesn't
: >indicate usage it does indate that 80% of the queries are related to
: >CGI and the web in some form or another. 
: 
: You're assuming too much. Nothing indicates that DBI is related to CGI
: whatsoever.

Ditto LWP (which is primarily for fetching rather than producing web
content) and XML (which is a general-purpose data exchange and storage
format).

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Tue, 10 Apr 2001 21:07:28 GMT
From: "Roman Filippov" <NO_SPAM_klubbheads@home.com>
Subject: THANK YOU & FINAL CODE
Message-Id: <kCKA6.199965$A6.44429910@news4.rdc1.on.home.com>


Hello All!

Thank you, everybody, for a great help! Here is a final piece of code if
anybody interested:


#### START CODE
sub template  {
my $filename = shift;
my $fillings = shift;

my $template = parse( $filename );

# substitue all the fields that are in a following form in a text file
<%ANY_FIELD_NAME%>
$template =~   s{ <% (.*? ) %> }
  { exists( $fillings->{$1} )
   ? $fillings->{$1}
   : ''
  }gsex;

return $template;
}

sub parse {
my %cache if 0;

my $filename = shift;

my $template = $cache{$filename} ||
 do {
  local *TEMPLATE;
  local $/;
  open (TEMPLATE, "< $filename") or return "[file does not exist:
$filename]";
  my $template = <TEMPLATE>;
  close(TEMPLATE) or die $!;

  # include other templates from the initial template ( <%include
file="template_name.tpl"%> )
  $template =~ s/<%include file="([^"\n]+)"%>/($1 ne $filename) ? parse($1)
: ''/eg;

  $cache{$filename} = $template;

  return $template;
 };

return $template;
}
#### END CODE


#### EXAMPLE
<!-- initial.tpl -->
<html>
<head>
    <title><%title%></title>
</head>
<body>
<%include file="header.tpl"%>
<%body%>
</body>
</html>
<!-- /initial.tpl -->


<!-- header.tpl -->
<b><%header%></b>
<!-- /header.tpl -->

#!perl

print "Content-type: text/html\n\n";
print template('initial.tpl',{ title => 'Template test', body => 'here goes
body', header => 'Template' });


#### OUTPUT
<html>
<head>
    <title>Template test</title>
</head>
<body>
<b>Template</b>
here goes body
</body>
</html>
#### END OUTPUT


Any comments? Maybe there is something to simplify?




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

Date: 10 Apr 2001 18:02:35 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: THANK YOU & FINAL CODE
Message-Id: <m31yr076ro.fsf@mumonkan.sunstarsys.com>

"Roman Filippov" <NO_SPAM_klubbheads@home.com> writes:

> #### START CODE
> sub template  {
> my $filename = shift;
> my $fillings = shift;

  my ($filename, $fillings) = @_; # nitpick :-)

> my $template = parse( $filename );
> 
> # substitue all the fields that are in a following form in a text file
> <%ANY_FIELD_NAME%>
> $template =~   s{ <% (.*? ) %> }
>   { exists( $fillings->{$1} )
>    ? $fillings->{$1}
>    : ''
>   }gsex;
> 
> return $template;
> }
> 
> sub parse {
> my %cache if 0;
 ^^^^^^^^^^^^^^^^
*Don't* use this in real code- and especially not without a comment.
It's an unsupported parlor trick and I apologize for encouraging you
to use it in your program.  From

  http://www.perl.com/pub/2000/05/p5pdigest/THISWEEK-20000521.html

 ...
Jan Dubois: I think this behavior is a side effect of the implementation
            and shouldn't be documented as a feature. It should at best
            be "undefined" behavior that may change in the future (IMHO).

Larry: In Ada parlance, use of this feature would be considered erroneous. 
 ...


If this is anything more than a throwaway script, it would be far 
better to write it correctly:

  { 
    my %cache;

    sub parse {

> my $filename = shift;
> 
> my $template = $cache{$filename} ||
>  do {
>   local *TEMPLATE;
>   local $/;
>   open (TEMPLATE, "< $filename") or return "[file does not exist:
> $filename]";
>   my $template = <TEMPLATE>;
>   close(TEMPLATE) or die $!;
> 
>   # include other templates from the initial template ( <%include
> file="template_name.tpl"%> )
>   $template =~ s/<%include file="([^"\n]+)"%>/($1 ne $filename) ? parse($1)
> : ''/eg;
> 
>   $cache{$filename} = $template;
> 
>   return $template;
>  };
> 
> return $template;
> }
> #### END CODE


Cool- using recursion! Now you really *are* memoizing the results of 
parse(). In that case, here's another way to do it:

    my $filename = shift;
    return $cache{$filename} if exists $cache{$filename}; # use memo

    # ordinary control flow for non-cached files

    local (*TEMPLATE, $/, $_);

    open TEMPLATE, "< $filename" or die "'$filename' won't open:$!";
    $_ = <TEMPLATE>;
    close TEMPLATE or die "'$filename' closed with error: $!";

    # parse file for includes
    s/<%include file="([^"\n]+)"%>/($1 ne $filename) ? parse($1) : ''/ge;
    
    $cache{$filename} = $_; # keeps return value for future memoization

    }

  } # extra bracket to eliminate "my %cache if 0;" trick.

[...]

> Any comments? Maybe there is something to simplify?

Despite your aversion to using modules, you really ought to look at
some of the SSI and Template stuff on CPAN, if for nothing else, to
see how other people achieve the same (or better) effect.  It's one
of the best ways to learn Perl, and to appreciate how effective some 
of those modules really are.

HTH
-- 
Joe Schaefer         "Everything that can be invented has been invented."
                                               -- Charles H. Duell


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

Date: Tue, 10 Apr 2001 16:00:40 -0400
From: "T_Boss" <T_boss75@curanet.com>
Subject: Re: To run perl in the backround
Message-Id: <SFJA6.140780$lj4.4353726@news6.giganews.com>

I have tied it but didn,t get any response at all.
No error message, and the program is not working either.

"wayne.keenan" <wayne.keenan@ntlworld.com> wrote in message
news:3AD2B19E.3B8E1EA@ntlworld.com...
> a recipe is in the cookbook, it goes along the lines of using a
bootstrapping
> perl script:
> credits go to Tom Christiansen & Nathan Torkington
> http://www.oreilly.com/catalog/cookbook/
>
>
> #!/usr/bin/perl -w
> # loader - starts Perl scripts without the annoying DOS window
> use strict;
> use Win32;
> use Win32::Process;
>
> # Create the process object.
>
> Win32::Process::Create($Win32::Process::Create::ProcessObj,
>     'C:/perl5/bin/perl.exe',            # Whereabouts of Perl
>     'perl realprogram',                 #
>     0,                                  # Don't inherit.
>     DETACHED_PROCESS,                   #
>     ".") or                             # current dir.
> die print_error();
>
> sub print_error() {
>     return Win32::FormatMessage( Win32::GetLastError() );
> }
>
> T_Boss wrote:
>
> > I have developed a perl program wich has to monitor some PsrtMasters.
> > to run it, I have to open the comment promt box. and run the program.
> > To keep it running I have to keep this box open.
> > Is there anyway to let perl run in the backround, so that i can close
this
> > box??
> >  I have Active perl 5.6 on Win NT 4.0  Sp 5.0
>




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

Date: Tue, 10 Apr 2001 17:53:14 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: unicode, perl and webbrowsers
Message-Id: <Pine.LNX.4.30.0104101715130.32121-100000@lxplus003.cern.ch>

On Tue, 10 Apr 2001, peter pilsl wrote:

> I put a very simple testscript online, that lets you enter any text in a
> form and print out the submitted text and the ord-numbers of it
> characters.
> Encoding ist 'UTF-8' and all is done with perl 5.6.0
>
> http://www.customers.goldfisch.at/cgi-bin/unicodetest.pl
> (source: http://www.customers.goldfisch.at/unicodetest.pl)

I suspect that your problem here is that you are mixing up
Perl's new unicode handling features with the handling of single
bytes (octets).

I haven't used Perl's Unicode features yet - I simply handle the
bytes in the way that I want.  And I _can_ successfully submit utf-8
text using Netscape 4.

> When I enter the russian YERU in the form I get the following ord-values
> returned: 209-139,

utf-8 coding uses either 1 byte (for us-ascii characters only) or
two or more bytes (for all other characters).

so one character is interpreted as two characters in
> perl.

> The correct unicode-tag

you mean "numerical character reference" in HTML terminology

> for this YERU (that is actually the small-
> letter-yeru) is &#1099.

Correct, and utf-8-coded that is x'd18b', in other words in decimal
it's 209 followed by 139.

> Now I would like to know, what is the connection between this 209-139-
> ordvalues and 1099 ?

You need to read the specification for utf-8 coding, or at least have
some code which understands it for you.

> I thought perl is able to store any unicodecharacter as one internal
> character or is this a problem of the substr-function I used to extract
> the chars ...

I leave that for a Perl specialist to answer (and for once we
are on topic here ;-)

As I say, I have been accustomed to work with the individual bytes.

> How should I internal store the text ?

You are telling the world that your document is coded in utf-8, so
either you need to store it in utf-8, or you will need to convert it
for storing, and convert it again when transmitting it.

> Just keep the strings as they are

You probably want to keep your options open to resolve some of
the browser curiosities that I reported (and probably some more which
you will find if you put it into production!).  A certain heuristic
approach seems to be called for.

> and store them into the database and hope this is all compliant to the
> important standards.

Take a look at the rules which apply to the database.  I don't really
want to get involved in discussing that.  Make a clean boundary
between your HTML and the database.  Solve each problem separately and
then fit the two together.

> Or should I try to find a way to convert all this
> ord-values into the correct html-tags &#wxyz and store this values.

That's not excluded, but I wouldn't choose that approach if I could
avoid it, because of the data bloat involved.

This is absolutely NOT optimised, it's for didactic purposes only,
and it expects numerical character references in decimal.  I expect
the regulars to give it their usual pasting, but that's par for the
course...


#!/usr/local/bin/perl -w
use strict;

# Program to turn "&#bignumber;" numerical character refs into utf-8.

# stripped-down version for UCS2

my $debug = 1;
my $s = '';

while (<>) {  # read standard input

  while (s/^(.*?)\&\#([0-9]+);?//) {  # look for &#digits[;]

    print $1;    # everything to the left of the match

    if ($2 < 0x80) { # 7bit ascii was presumably &#n; for good reason
      print "&#$2;"; $s = "";
      }
    elsif ($2 < 0x800) { # two bytes
      $s = chr(0xc0 | ($2>>6)) . chr(0x80 | ($2 & 0x3f));
      }
    else { # three bytes
      $s = chr(0xe0 | ($2>>12)) . chr(0x80 | (($2 & 0xfff)>>6)) .
             chr(0x80 | ($2 & 0x3f));
      }

    if ($s ne "") {
      printf("\n<!-- %d %x %s -->\n", $2, $2, unpack("H*",$s)) if $debug;
      print $s;
      }
    }
  print $_;
  }




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

Date: 10 Apr 2001 19:02:52 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: unicode, perl and webbrowsers
Message-Id: <eli$0104101434@qz.little-neck.ny.us>

In comp.lang.perl.misc, Alan J. Flavell <flavell@mail.cern.ch> wrote:
> On Tue, 10 Apr 2001, peter pilsl wrote:
> > I thought perl is able to store any unicodecharacter as one internal
> > character or is this a problem of the substr-function I used to extract
> > the chars ...
> I leave that for a Perl specialist to answer (and for once we
> are on topic here ;-)

The Convert::Scalar module provides ways to tell perl that a string
is not, eg, a set of one byte chars that coincidentally are utf-8, but
that some string is utf-8.

Here is a demo program. Perhaps someone else can explain what is
happening with $chr2 after the cmp.

#!/usr/bin/perl -w  
use strict;
require 5.006;
use vars qw( $chr1 $chr2 $chr3 @oct $oct $len $isutf8 $same );
use charnames qw( :full );	# comes with perl 5.6.0
use Convert::Scalar qw( :utf8 );

# \N{name} is a feature of the charnames module.
$chr1   = "\N{LATIN CAPITAL LETTER J}\N{SKULL AND CROSSBONES}";
@oct    = $chr1 =~ /(.)/g;
$len    = length($chr1);
$oct    = @oct;
$isutf8 = (utf8 $chr1)? "yes" : "no";

print "CHR 1: $oct bytes, $len chars, in <$chr1>; is utf8? $isutf8\n";

$chr2   = "J☠";
@oct    = $chr2 =~ /(.)/g;
$len    = length($chr2);
$oct    = @oct;
$isutf8 = (utf8 $chr2)? "yes" : "no";

print "CHR 2: $oct bytes, $len chars, in <$chr2>; is utf8? $isutf8\n";

print "(<$chr1> cmp <$chr2>)";
$same   = ($chr1 cmp $chr2)? "same" : "not same";
print " == $same\n";

print "But after cmp, they are now <$chr1> and <$chr2>\n";

$chr3   = "J☠";
utf8_on $chr3;
@oct    = $chr3 =~ /(.)/g;
$len    = length($chr3);
$oct    = @oct;
$isutf8 = (utf8 $chr3)? "yes" : "no";

print "CHR 3: $oct bytes, $len chars, in <$chr3>; is utf8? $isutf8\n";

__END__

:r! perl %
CHR 1: 4 bytes, 2 chars, in <J☠>; is utf8? yes
CHR 2: 4 bytes, 4 chars, in <J☠>; is utf8? no
(<J☠> cmp <J☠>) == same
But after cmp, they are now <J☠> and <J☠>
CHR 3: 4 bytes, 2 chars, in <J☠>; is utf8? yes

Elijah
------
thinks Convert::Scalar needs to be mentioned more


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

Date: Tue, 10 Apr 2001 21:47:07 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: unicode, perl and webbrowsers
Message-Id: <Pine.LNX.4.30.0104102143580.32121-100000@lxplus003.cern.ch>

On Tue, 10 Apr 2001, Alan J. Flavell wrote:

> And I _can_ successfully submit utf-8 text using Netscape 4.

Excuse me, I should now correct that assertion, instead of leaving it
on record here.  In fact, it only works in very limited circumstances,
as my subsequent posting to c.i.w.authoring.html explains in a bit
more detail.

[Nothing on-topic for Perl here.  f'ups set as precaution.]



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

Date: Tue, 10 Apr 2001 16:10:23 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: using dup()
Message-Id: <3AD333AC.60729549@home.com>

"Andrew J. Perrin" wrote:
> 
> #!/usr/local/bin/perl -w
> 
> use strict;
> use IO::File;

With newer perls (5.6.0+) you can dispense with IO::File for this
purpose.
 
> my @files;
> foreach (@ARGV) {
>   if ($_ eq 'STDOUT') {
>     push(@files, \*STDOUT);
>   } else {
>     my $fh = new IO::File(">>$_");

      open my $fh, ">>$_";

>     push(@files, $fh);
>   }
> }

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Tue, 10 Apr 2001 20:38:50 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: using dup()
Message-Id: <rer6dtg053ar2mhgu9kgqu828kj7q9q8cg@4ax.com>

Victor Hannak wrote:

>I have the following code:
>
>    open(LOG, ">>/tmp/logfile");
>    open(STDOUT, ">&LOG");
>    print "test";
>    close(LOG);
>
>I was expecting the word test to go both to stdout and the logfile, but
>it goes to neither.  How can I get it to go to both at the same time?

At most, it might go to the file. By reopening STDOUT as ">&LOG", you
first close he old STDOUT, and reopen it as a dup of the othe handle,
LOG. But ">&$handle" only works if you use the same file mode, which
most probably the reason why you get nothing.

	open STDOUT, ">>&LOG"

is more likely to succeed. But you still only get one stream getting the
output.

BTW check out perlfaq5:

	How do I print to more than one file at once?


If you don't like to use an external program for the tee functionality,
in principle it is possible to write it in a module, using a tied
filehandle. Should I bother actually doing it?

-- 
	Bart.


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

Date: Tue, 10 Apr 2001 17:04:17 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Using References
Message-Id: <3ad33d19.46bc$180@news.op.net>
Keywords: fling, litigious, node, template


In article <qav5dts37g3v1i4qel1or5kopfnblcmhc2@4ax.com>,
Lou Moran  <lmoran@wtsg.com> wrote:
>Why would I do this?  When would this be useful? 

Have a look at 

        http://perl.plover.com/FAQs/References.html

There are a couple of simple but very practical examples.
-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Tue, 10 Apr 2001 14:30:28 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: Using References
Message-Id: <r7k6dtkrtsv511ag2baq4tnntdc2d0svf1@4ax.com>

On Tue, 10 Apr 2001 17:04:17 GMT, mjd@plover.com (Mark Jason Dominus)
wrote wonderful things about sparkplugs:

>
>In article <qav5dts37g3v1i4qel1or5kopfnblcmhc2@4ax.com>,
>Lou Moran  <lmoran@wtsg.com> wrote:
>>Why would I do this?  When would this be useful? 
>
>Have a look at 
>
>        http://perl.plover.com/FAQs/References.html
>
>There are a couple of simple but very practical examples.

"Think of the President: a messy, inconvenient bag of blood and
bones."

I spit my 7-Up out when I read that.  

Oh and I see why References would be useful now, thanks for the
pointer.

--
print "\x{263a}" 


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

Date: Wed, 11 Apr 2001 02:42:32 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: We have 'use strict' and 'my', and now 'our', but no 'use local-scope' -   why?
Message-Id: <rxGA6.606$482.1797@newsfeeds.bigpond.com>

I think Perl 6 will pass on this one.

What we really need is a switch statement!!
And a syntax makeover to make Perl as clear an Python ;-)

gtoomey
--------
<nobull@mail.com> wrote in message news:u9snjh9eq0.fsf@wcl-l.bham.ac.uk...
> Bloody awfull idea.
>
> The reason that using my() is good is not because lexically scoped
> variables in Perl are a little faster than package scoped ones.  The
> reason my() is good is because it is good practice, in all
> programmming languages, to limit varaiables' lifetime and scope to the
> smallest appripriate enclosing scope.  Also requiring explicit
> declaration of variables helps prevent typos in variable names causing
> hard to track bugs.
>
 ...





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

Date: Tue, 10 Apr 2001 15:07:22 -0400
From: "Thomas" <webmuse@my-deja.com>
Subject: Why is finish() necessary here with DBI? Bug in DBD::ODBC?
Message-Id: <KRIA6.138$R27.17745@news4.mco>

Hello,

I am using DBI version 1.14, DBD::ODBC version 0.28, and SQL Server
7.0
on a Windows NT machine.

I wrote a database module that uses DBI to access SQL Server with
the DBD::ODBC driver. It sacrifices database speed for "programmer
speed" and ease of use, and works similarly to Win32::ODBC.

Because of the limitations of SQL Server, only one statement handle
can be used per database handle. So instead of using two handles,
you'd
typically use two instances of my db module to do complex things, like
inserting rows into the database while you iterate over a result set.

While testing this module, I found that I would often get this error:

DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server
Driver]Connection
is busy with results for another hstmt (SQL-S1000)(DBD:
st_execute/SQLExecute err=-1) at C:/Perl/site/lib/DB.pm line 466.

Line 466 is where I prepare a new statement handle, overwriting the
old statement handle (which may have been in use already).

This error was normally cropping up in cases where a SELECT was given
that returned multiple rows, but only a few rows were fetched. So in
that case it kind of makes sense. But I've also seen it occur in cases
where only one row was being returned, and that row was being fetched
by the module (using $sth->fetchrow_hashref). So in this case, I do
not
understand why it was happening.

I was able to workaround the problem by adding this before the
'prepare' statement:

if ($self->{sth}->{Active})
{
    $self->{sth}->finish();
}

But I'm still wondering if that is the best way to deal with this
behavior, and why it's even happening in the second case described
above?

Is it a bug in DBD::ODBC? I never had this problem when using
Win32::ODBC
connecting to the same database.

-thomas





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

Date: 10 Apr 2001 20:34:55 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: win32: *.pl > *.exe howto
Message-Id: <9avqpf$9p8$2@plutonium.btinternet.com>

Alessandro <alessandro.augusto@br.bosch.com> wrote:
> Jonathan Stowe wrote:
> 
>> alexander gausa <alexander.gausa@gmx.de> wrote:
>> > hi!
>> > i want to generate an exe-file from an pl-file.
>> >
>>
>> renaming the file works for me.
>>
> I think Johnathan, that it works to you because you have the interpretor
> Perl instaled on that machine.
>

Yes, that is correct.

> When you install perl, the files with the extension .pl are linked
> to Perl.exe.  Try to remove or change Perl.exe´s name and see if still
> working? I haven´t test this, but I think it won´t work.

Nope.  When I install Perl nothing is linked in that manner.  I dont think
I even have a perl.exe on this machine.  I think that a Perl program
with the correct shebang line will execute on this machine whatever the
suffix of the file is.

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

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


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