[25718] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7958 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 9 18:05:27 2005

Date: Sat, 9 Apr 2005 15:05:09 -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           Sat, 9 Apr 2005     Volume: 10 Number: 7958

Today's topics:
    Re: Conditional constant in regular expression <perl@my-header.org>
    Re: Conditional constant in regular expression <noreply@gunnar.cc>
    Re: Conditional constant in regular expression <perl@my-header.org>
    Re: Conditional constant in regular expression <tadmc@augustmail.com>
    Re: Conditional constant in regular expression axel@white-eagle.invalid.uk
    Re: Perl Embed in C++ Problem -> Urgent, please help! <1usa@llenroc.ude.invalid>
    Re: Perl Embed in C++ Problem -> Urgent, please help! rbric@adomain.com
    Re: Perl Embed in C++ Problem -> Urgent, please help! <1usa@llenroc.ude.invalid>
        Perl executable showing html in default browser <m.boom@mhjboom.nl>
    Re: Perl executable showing html in default browser <1usa@llenroc.ude.invalid>
    Re: Perl executable showing html in default browser <postmaster@castleamber.com>
    Re: Perl executable showing html in default browser <jurgenex@hotmail.com>
    Re: Start a program and get a hold of it's STDOUT and S <zentara@highstream.net>
        What's wrong with this code ? codefixer@gmail.com
    Re: What's wrong with this code ? <tony_curtis32@yahoo.com>
    Re: What's wrong with this code ? codefixer@gmail.com
    Re: What's wrong with this code ? (Anno Siegel)
        Working in a secure site <jimsimpson@cox.net>
    Re: Working in a secure site <spamtrap@dot-app.org>
    Re: YARQ - Yet another regex question <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 09 Apr 2005 16:41:59 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: Conditional constant in regular expression
Message-Id: <9spf511eu660dvfv6l3bk458b0nsk4rc5k@4ax.com>

X-Ftn-To: Fritz Bayer 

>The words "domain:", "path:" and "query:" are the constants, which
>should be prepended if a capturing group in non empty.
>
>Is there a single regular expression, which can solve this problem? I
>don't want to depend on any perl, java or on any other code.

  use strict;
  use Data::Dumper;
  
  my @fields = qw/domain path query/;
  my $dreg = qr{
    ^http://
    ([^/]+)/?     #domain
    (?: (.+)/)?   #path
    (?: [^?]+)?   #document
    (?: \? (.*))? #query
  }xi;
  
  my @url = qw{
    http://www.example.com/path/index.html
    http://www.example.com/path/index.html?somekey=value
    http://www.example.com/
  };
  for my $u (@url) {
    my %adr;
    my $i = 0;
    $adr{$fields[$i++]} = $_ for grep defined, $u =~ /$dreg/;
    print Dumper \%adr;
  }

Anyway, strongly consider cpan URL module as it covers complete RFC.


-- 
Matija


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

Date: Sat, 09 Apr 2005 19:45:47 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Conditional constant in regular expression
Message-Id: <3bqiijF6g6omdU1@individual.net>

Matija Papec wrote:
> X-Ftn-To: Fritz Bayer 
>> Is there a single regular expression, which can solve this problem? I
>> don't want to depend on any perl, java or on any other code.
> 
>   use strict;
>   use Data::Dumper;
>   
>   my @fields = qw/domain path query/;
>   my $dreg = qr{
>     ^http://
>     ([^/]+)/?     #domain
>     (?: (.+)/)?   #path
>     (?: [^?]+)?   #document
>     (?: \? (.*))? #query
>   }xi;
>   
>   my @url = qw{
>     http://www.example.com/path/index.html
>     http://www.example.com/path/index.html?somekey=value
>     http://www.example.com/
>   };
>   for my $u (@url) {
>     my %adr;
>     my $i = 0;
>     $adr{$fields[$i++]} = $_ for grep defined, $u =~ /$dreg/;
>     print Dumper \%adr;
>   }

That looks like Perl code to me. ;-)

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


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

Date: Sat, 09 Apr 2005 21:09:54 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: Conditional constant in regular expression
Message-Id: <su9g51l9nrqjoa52q6o014l8tq6t6q0eqr@4ax.com>

X-Ftn-To: Gunnar Hjalmarsson 

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>That looks like Perl code to me. ;-)

Err, right; at first I thought that OP doesn't want to use external modules
but now I see that his request is even more extreme. :)



-- 
Matija


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

Date: Sat, 9 Apr 2005 12:52:05 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Conditional constant in regular expression
Message-Id: <slrnd5g5i5.6g1.tadmc@magna.augustmail.com>

Fritz Bayer <fritz-bayer@web.de> wrote:

> I
> don't want to depend on any perl


Then you are in the wrong newsgroup.


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


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

Date: Sat, 09 Apr 2005 16:03:46 -0500
From: axel@white-eagle.invalid.uk
Subject: Re: Conditional constant in regular expression
Message-Id: <c-ydnRT9Rv-v3sXfRVn-jg@adelphia.com>

Matija Papec <perl@my-header.org> wrote:
>>The words "domain:", "path:" and "query:" are the constants, which
>>should be prepended if a capturing group in non empty.

>>Is there a single regular expression, which can solve this problem? I
>>don't want to depend on any perl, java or on any other code.
 
>  my @fields = qw/domain path query/;
>  my $dreg = qr{
>    ^http://
>    ([^/]+)/?     #domain
>    (?: (.+)/)?   #path
>    (?: [^?]+)?   #document
        ^^^^^^
Should be:  ([^?]+)

Axel



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

Date: Sat, 09 Apr 2005 17:49:49 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl Embed in C++ Problem -> Urgent, please help!
Message-Id: <Xns96338CA0C71FAasu1cornelledu@127.0.0.1>

rbric@adomain.com wrote in news:jhte51h8kncckijsdhi9tktib5enfqadc1@
4ax.com:

> On 4 Apr 2005 19:38:41 -0700, sleepymish@gmail.com wrote:
> 
>>
>>A. Sinan Unur wrote:
 ...
>>> /* embed.cc */
>>>
>>> #ifdef __cplusplus
>>> extern "C" {
>>> #include <EXTERN.h>
>>> #include <perl.h>
>>> static PerlInterpreter *my_perl;
>>> }
>>> #endif
>>>
>>
>>This worked! I included the #ifdef...#endif block in my code and
>>everything compiled!
>>
> Lots of things compile, but .....
> did the perl interpreter work inside the binary at runtime the same
> when compiled in C? Well now, let me see, code written for C
> just needs to be re-compiled for C++ without change.... hmmm

No, the purpose of the above is to tell the compiler that when compiling 
the C++ program, it should use C linkage conventions for the perl 
related stuff.

The perl libraries are not recompiled in the process. They are linked 
with the OP's program.

This is not Perl specific. Linking to any C library from C++ program is 
achieved this way. Otherwise, you would not be able to do following:

D:\Home> cat my_message.c
/* my_message: return a custom message
 */

const char *my_message(void) {
    return "Hello from Sinan";
}
/* EOF: my_message.c */

D:\Home> gcc -c -Wall -O2 my_message.c -o my_message.o

D:\Home> cat show.cc
#include <iostream>

extern "C" {
    const char *my_message(void);
};

int main(void) {
    std::cout << my_message() << std::endl;
}

/* EOF: show.cc */

D:\Home> g++ -Wall -O2 show.cc my_message.o -o show.exe

D:\Home> show
Hello from Sinan

Note that my_message.o was compiled as C from my_message.c. When show.cc 
was compiled as as C++ using g++, the linker was able to resolve the 
reference to the C function my_message in my_message.o thanks to the 
extern "C" { ... } declaration in show.cc.

Now, as I admitted, I had never dabbled in embedding etc, and there 
might be something else that is the problem with the OP's code (as he 
failed to show source code).

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Sat, 09 Apr 2005 13:21:14 -0700
From: rbric@adomain.com
Subject: Re: Perl Embed in C++ Problem -> Urgent, please help!
Message-Id: <dbdg511e7ohnsaegjvb85hno0f3f03t41v@4ax.com>

On Sat, 09 Apr 2005 17:49:49 GMT, "A. Sinan Unur"
<1usa@llenroc.ude.invalid> wrote:

>rbric@adomain.com wrote in news:jhte51h8kncckijsdhi9tktib5enfqadc1@
>4ax.com:
>
>> On 4 Apr 2005 19:38:41 -0700, sleepymish@gmail.com wrote:
>> 
>>>
>>>A. Sinan Unur wrote:
>...
>>>> /* embed.cc */
>>>>
>>>> #ifdef __cplusplus
>>>> extern "C" {
>>>> #include <EXTERN.h>
>>>> #include <perl.h>
>>>> static PerlInterpreter *my_perl;
>>>> }
>>>> #endif
>>>>
>>>
>>>This worked! I included the #ifdef...#endif block in my code and
>>>everything compiled!
>>>
>> Lots of things compile, but .....
>> did the perl interpreter work inside the binary at runtime the same
>> when compiled in C? Well now, let me see, code written for C
>> just needs to be re-compiled for C++ without change.... hmmm
>
>No, the purpose of the above is to tell the compiler that when compiling 
>the C++ program, it should use C linkage conventions for the perl 
>related stuff.
>
>The perl libraries are not recompiled in the process. They are linked 
>with the OP's program.
>
>This is not Perl specific. Linking to any C library from C++ program is 
>achieved this way. Otherwise, you would not be able to do following:
>
>D:\Home> cat my_message.c
>/* my_message: return a custom message
> */
>
>const char *my_message(void) {
>    return "Hello from Sinan";
>}
>/* EOF: my_message.c */
>
>D:\Home> gcc -c -Wall -O2 my_message.c -o my_message.o
>
>D:\Home> cat show.cc
>#include <iostream>
>
>extern "C" {
>    const char *my_message(void);
>};
>
>int main(void) {
>    std::cout << my_message() << std::endl;
>}
>
>/* EOF: show.cc */
>
>D:\Home> g++ -Wall -O2 show.cc my_message.o -o show.exe
>
>D:\Home> show
>Hello from Sinan
>
>Note that my_message.o was compiled as C from my_message.c. When show.cc 
>was compiled as as C++ using g++, the linker was able to resolve the 
>reference to the C function my_message in my_message.o thanks to the 
>extern "C" { ... } declaration in show.cc.
>
>Now, as I admitted, I had never dabbled in embedding etc, and there 
>might be something else that is the problem with the OP's code (as he 
>failed to show source code).
>
>Sinan

Very nice. Since you mention linkage, I thought that the 
calling convention (stack) might be different between C/C++
requiring a recompile of all C modules to obj's. Linkage fixups
(offsets) to entry points when the obj's are merged.

I'm not from the unix world (the other) so I imagine gcc compiler
is for i (I didn't see a link switch, does this compile pass 1,2 then
link?). 

Regardless, no need to recompile src from C to C++, just use
C++ linker on C obj's huh... hey news to me, but you did a good
job describing cdecl's and such !

Please correct me if I'm wrong, I havent used a compiler in 3
years, but did for the previous 20 before..

-Redneck



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

Date: Sat, 09 Apr 2005 22:02:24 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl Embed in C++ Problem -> Urgent, please help!
Message-Id: <Xns9633B773B9529asu1cornelledu@127.0.0.1>

rbric@adomain.com wrote in
news:dbdg511e7ohnsaegjvb85hno0f3f03t41v@4ax.com: 

> On Sat, 09 Apr 2005 17:49:49 GMT, "A. Sinan Unur"
> <1usa@llenroc.ude.invalid> wrote:

>>Note that my_message.o was compiled as C from my_message.c. When
>>show.cc was compiled as as C++ using g++, the linker was able to
>>resolve the reference to the C function my_message in my_message.o
>>thanks to the extern "C" { ... } declaration in show.cc.

 ...

> Very nice. Since you mention linkage, I thought that the 
> calling convention (stack) might be different between C/C++
> requiring a recompile of all C modules to obj's. Linkage fixups
> (offsets) to entry points when the obj's are merged.

You should view my comments in the context of the OP's task. In 
embedding the interpreter, recall that I used the command line:

asu1@Aardvark ~/src/embed
$ gcc -o embed embed.cc `perl -MExtUtils::Embed -e ccopts -e ldopts`

meaning the same options are used when building embed as were used when 
building perl and the associated libraries.

> I'm not from the unix world (the other) so I imagine gcc compiler
> is for i 

It is hard for me to parse to full meaning of the sentence above, but 
for the record, I am not "from the unix world" either. The code I have 
shown in this thread was all built on a Windows XP system.

> -Redneck

No need to point out who you are, robic0.

This thread is becoming too off-topic, I am afraid. You are going to 
have to troll elsewhere.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Sat, 9 Apr 2005 17:33:54 +0200
From: "Merijn Boom" <m.boom@mhjboom.nl>
Subject: Perl executable showing html in default browser
Message-Id: <4257f5e2$0$145$e4fe514c@news.xs4all.nl>

Hi,



I would like to know is somebody has experience in showing HTML from a perl 
executable in the default browser and let that html interact with the perl 
executable via the browser. This is because we would like to convert some of 
our perl scripts (ActiveState) via the Activestate compiler in order to have 
some stand alone executables.



Any help would be appreciated,



Merijn





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

Date: Sat, 09 Apr 2005 15:45:17 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl executable showing html in default browser
Message-Id: <Xns9633778376417asu1cornelledu@127.0.0.1>

"Merijn Boom" <m.boom@mhjboom.nl> wrote in
news:4257f5e2$0$145$e4fe514c@news.xs4all.nl: 

> I would like to know is somebody has experience in showing HTML from a
> perl executable in the default browser and let that html interact with
> the perl executable via the browser. 

What do you mean by "html interact with the perl executable"?

Do you need 

http://search.cpan.org/~gaas/libwww-perl-5.803/lib/HTTP/Daemon.pm

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: 9 Apr 2005 15:46:47 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Perl executable showing html in default browser
Message-Id: <Xns96336DA1259EEcastleamber@130.133.1.4>

Merijn Boom wrote:

> Hi,
> 
> I would like to know is somebody has experience in showing HTML from a
> perl executable in the default browser and let that html interact with
> the perl executable via the browser.

I guess the only way to do it with a default browser is CGI.

> This is because we would like to
> convert some of our perl scripts (ActiveState) via the Activestate
> compiler in order to have some stand alone executables.

Check out PAR to get a Perl "executable". (It's a file with perl.exe and 
all you need in a single file which bootstraps Perl and your script).

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: Sat, 09 Apr 2005 16:05:16 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl executable showing html in default browser
Message-Id: <03T5e.4838$H_5.2438@trnddc01>

[Also multi-posted to clp. Don't do that, please]
Merijn Boom wrote:
> I would like to know is somebody has experience in showing HTML from
> a perl executable in the default browser and let that html interact
> with the perl executable via the browser.

Typically people use the Common Gateway Interface for such kind of
applications. You may want to ask in a NG that actually deals with CGI.

If the HTML code is rendered by the browser or shown as text is (among other
things) a matter of the HTTP header. You may want to ask in NG that actually
deals with HTML and HTTP.

> This is because we would
> like to convert some of our perl scripts (ActiveState) via the
> Activestate compiler in order to have some stand alone executables.

The Common Gateway Interface doesn't care if the server side executable is a
script or a compiled program. You may want to ask in a NG that actually
deals with CGI.

Having said that there is one caveat that is actually related to Perl.
Typically Perl compilers didn't have a very good track record in the past,
i.e. people used to have a lot of problems getting their compiled scripts to
run. Now, this may have changed, so please take it with a grain of salt.

Another question is _why_ you want to compile you scripts. If your intention
is to hide you source code then I strongly recommend to read "perldoc -q
hide"

jue





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

Date: Sat, 09 Apr 2005 10:23:52 -0400
From: zentara <zentara@highstream.net>
Subject: Re: Start a program and get a hold of it's STDOUT and STDIN?
Message-Id: <h7of51t9165pgoqo1au3chee05v88k70ng@4ax.com>

On Sat, 9 Apr 2005 01:41:15 -0700, "Snail" <snail@localhost.com> wrote:

>
>Would IPC::Open3 be good for this? And using IO::Select for seeing 
>whether OUT or ERR has data coming from the server? Is this a good 
>approach? 
>

Here are 2 examples for you. I'm using "bc" instead of a server, but it
demonstrates all of the ideas, and some of the problems you will
encounter, principally with the linux "pipe buffer", which is usually
4k, and how to keep it empty. ( no data lingering in the pipe ).    

There are 2 versions, the first has a problem with only outputing 1
line, but is simple, to demonstrate the code basics.

The second example, uses a technique shown in "perldoc -q filehandle".
It will accept unlimited output, but still has a problem with the final
output buffer being "exactly" 4k.  You might be able to avoid that,
by printing 4k empty space to the pipe, when done outputting, in your
server. I don't have that luxery with bc.
#########################################################3
#!/usr/bin/perl
# It's only drawback is it only outputs 1 line of bc output
# so it errs on something like 234^12345 (which outputs a big number)
use warnings;
use strict;
use IPC::Open3;
use IO::Select;

my $pid = open3(\*WRITE, \*READ,\*ERROR,"bc");

my $sel = new IO::Select();
$sel->add(\*READ);
$sel->add(\*ERROR);

my($error,$answer)=('','');

while(1){

 print "Enter expression for bc, i.e. 2 + 2\n";
 chomp(my $query = <STDIN>);
 
 #send query to bc
 print WRITE "$query\n";

 foreach my $h ($sel->can_read)
 {
   my $buf = '';
   if ($h eq \*ERROR)
   {
     sysread(ERROR,$buf,4096);
     if($buf){print "ERROR-> $buf\n"}
   }
   else
   {
     sysread(READ,$buf,4096);
     if($buf){print "$query = $buf\n"}
   }
 }
}

waitpid($pid, 1);
 
__END__
###################################################

Here is a better, more complex version, but if you look at the
"pipe-sucking" logic, it has a problem if the last pipeful is exactly
4096.
####################################################
#!/usr/bin/perl
use warnings;
use strict;
use IPC::Open3;
require 'sys/ioctl.ph';

# I tested this with 
#  "q @ 2" to generate errors
# "123^12345" to generate big output
# "123^23456" to generate huge output

my $pid = open3(\*WRITE, \*READ,\*ERROR,"bc");

while(1){
my($error,$answer,$rsize,$esize,$errortot,$answertot)=('','',0,0,'','');

print "Enter expression for bc, i.e. 2 + 2\n";
chomp(my $query = <STDIN>);
if(length($query) == 0){next} #removes empty input

#send query to bc
print WRITE "$query\n";

#this do loop waits and eliminates need for a delay to let bc output
#It is NOT limited to 4060 bytes from bc, it keeps reading
#until a semi-full buffer is sent, which signals end of output
  do { 
      #see which filehandles have output from perldoc -q filehandle
      $esize = pack("L", 0);
      ioctl(\*ERROR, FIONREAD(), $esize) or die "Couldn't call ioctl:
$!\n";
      $esize = unpack("L", $esize);
      print "esize-> $esize\n" unless ($esize < 1);

      $rsize = pack("L", 0);
      ioctl(\*READ, FIONREAD(), $rsize) or die "Couldn't call ioctl:
$!\n";
      $rsize = unpack("L", $rsize);
      print "rsize-> $rsize\n" unless ($rsize <1);

     #get the output from bc
     if($esize > 0){sysread(ERROR,$error,$esize); $errortot =
$errortot.$error}
     if($rsize > 0){sysread(READ,$answer,$rsize); $answertot =
$answertot.$answer}
    } until(($esize > 0)or(($rsize > 0)and($rsize < 4060)));


if(length($errortot) > 0){ print "\e[1;31m ERROR-> $errortot \e[0m \n"}
if(length($answertot) > 0){print "Output->$query = $answertot\n"}

}

waitpid($pid, 1);



-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


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

Date: 9 Apr 2005 12:19:10 -0700
From: codefixer@gmail.com
Subject: What's wrong with this code ?
Message-Id: <1113074350.799090.211020@g14g2000cwa.googlegroups.com>

Hi,

I am trying to do substitution for XML characters. I am getting the
following error for this piece of code.

Thanks.

sub parseXML
{
	my $ret= $_;
	switch ($_)
		{
			case "&"	{	print "&#38;";	}
			case "<"	{	print "&#60;";	}
			case ">"	{	print "&#62;";	}
			case "\'"	{	print "&#39;";	}
			case "\""	{	print "&#34;";	}


		}


	return $ret;

}
String found where operator expected at generateXML.pl line 107, near
"case "&""

        (Do you need to predeclare case?)
String found where operator expected at generateXML.pl line 108, near
"case "<""

        (Do you need to predeclare case?)
syntax error at generateXML.pl line 106, near ")
                {"
syntax error at generateXML.pl line 108, near "case "<""
generateXML.pl had compilation errors.



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

Date: Sat, 09 Apr 2005 14:32:04 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: What's wrong with this code ?
Message-Id: <87wtrbycej.fsf@limey.hpcc.uh.edu>

>> On 9 Apr 2005 12:19:10 -0700,
>> codefixer@gmail.com said:

> Hi, I am trying to do substitution for XML characters. I am
> getting the following error for this piece of code.

> Thanks.

> switch ($_)

Have you

    use Switch;

'ed?  There's no built-in switch statement.

There are also modules to do entity encoding, e.g.

    HTML::Entities

but I'll let someone else narrow in on that for XML
specifically.

hth
t



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

Date: 9 Apr 2005 12:36:54 -0700
From: codefixer@gmail.com
Subject: Re: What's wrong with this code ?
Message-Id: <1113075414.925951.11760@o13g2000cwo.googlegroups.com>


Tony Curtis wrote:
> >> On 9 Apr 2005 12:19:10 -0700,
> >> codefixer@gmail.com said:
>
> > Hi, I am trying to do substitution for XML characters. I am
> > getting the following error for this piece of code.
>
> > Thanks.
>
> > switch ($_)
>
> Have you
>
>     use Switch;

 No when I copied the sub I forgot to add that. :( That was the
problem.
Thanks.
>
> 'ed?  There's no built-in switch statement.
>
> There are also modules to do entity encoding, e.g.
>
>     HTML::Entities
>
> but I'll let someone else narrow in on that for XML
> specifically.
> 
> hth
> t



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

Date: 9 Apr 2005 20:43:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: What's wrong with this code ?
Message-Id: <d39eq8$dcr$1@mamenchi.zrz.TU-Berlin.DE>

 <codefixer@gmail.com> wrote in comp.lang.perl.misc:
> Hi,
> 
> I am trying to do substitution for XML characters. I am getting the
> following error for this piece of code.
> 
> Thanks.
> 
> sub parseXML
> {
> 	my $ret= $_;
> 	switch ($_)
> 		{
> 			case "&"	{	print "&#38;";	}
> 			case "<"	{	print "&#60;";	}
> 			case ">"	{	print "&#62;";	}
> 			case "\'"	{	print "&#39;";	}
> 			case "\""	{	print "&#34;";	}
> 
> 
> 		}
> 
> 
> 	return $ret;
> 
> }
> String found where operator expected at generateXML.pl line 107, near
> "case "&""

Tony Curtis has explained how to make the case-statement work, but in
Perl "case" is rarely needed (that's why it doesn't have it in the first
place).  The routine parseXML (a rather pretentious name for a modest
routine, I'd say) would be better written like this (untested):

    {
        my %trans = map { $_ => sprintf '&#%02d;', ord $_ } qw( & < > ' ");
        sub parseXML {
            print $trans{ $_} if $trans{ $_};
            $_;
        }
    }

This uses a hash (%trans) to distinguish the cases.  A bare block is used
to give %trans a small lexical scope. It doesn't hard-code the ASCII
equivalents but lets Perl do the work, though the wisdom of this could be
debated.  It should work like the original, but is much more compact.

Anno


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

Date: Sat, 9 Apr 2005 14:44:07 -0400
From: "jim simpson" <jimsimpson@cox.net>
Subject: Working in a secure site
Message-Id: <SnV5e.387$5J3.126@lakeread01>

I want to write Perl script that will allow me to get my data from a secure
site after I have manually entered the site using the proper user name and
password. I think this means that I must first get from the browser, the
code and cookie that have been returned by the server.

Does anyone know if this is possible and hopefully point me in a direction
to get started.

Thanks.

Jim




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

Date: Sat, 09 Apr 2005 15:40:36 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Working in a secure site
Message-Id: <WPidnRhfQqMpssXfRVn-pg@adelphia.com>

jim simpson wrote:
> I want to write Perl script that will allow me to get my data from a secure
> site after I have manually entered the site using the proper user name and
> password. I think this means that I must first get from the browser, the
> code and cookie that have been returned by the server.

No, it means you want to write a user agent (aka browser) in Perl. It's 
easier than you might think, because the "heavy lifting" has already 
been done for you. Have a look at these CPAN modules:

     LWP
     WWW::Mechanize

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Sat, 09 Apr 2005 17:25:48 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: YARQ - Yet another regex question
Message-Id: <Xns9633888E567A0asu1cornelledu@127.0.0.1>

rbric@adomain.com wrote in
news:u4re51dcvfi331rkb9fn45b7g91kg4jt43@4ax.com: 

> while ($line =~ s/=\n//) {};

In general, you might want to use

1 while ( ... );

instead of putting an empty block at the end.

However, you don't really need a while loop there:

$line =~ s/=\n//g;

would be preferable.

Just because I am bored and looking for something to do:

#! /usr/bin/perl

use strict;
use warnings;

sub make_loop_replacer {
    my $s = 'a';
    $s .= "=\n" for (1 .. 100_000);
    $s .= 'b';
    sub { 1 while $s =~ s/=\n// }
}

sub make_sg_replacer {
    my $s = 'a';
    $s .= "=\n" for (1 .. 100_000);
    $s .= 'b';
    sub { $s =~ s/=\n//g }
}

use Benchmark ':all';

cmpthese 5_000_000, {
    loop => make_loop_replacer(),
    sg   => make_sg_replacer(),
};

__END__

D:\Home\asu1\UseNet\clpmisc> t
          Rate loop   sg
loop 2908668/s   -- -50%
sg   5763689/s  98%   --



-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

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 V10 Issue 7958
***************************************


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