[23609] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5816 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 17 11:05:38 2003

Date: Mon, 17 Nov 2003 08:05:06 -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           Mon, 17 Nov 2003     Volume: 10 Number: 5816

Today's topics:
    Re: Calling a different shell than the inherited one <xx087@freenet.carleton.ca>
        comments on JAPH? <ThomasKratz@REMOVEwebCAPS.de>
        Creating UNICODE filenames with PERL 5.8 (Allan Yates)
    Re: Creating UNICODE filenames with PERL 5.8 <flavell@ph.gla.ac.uk>
        extract block of text (mike)
    Re: extract block of text <pilsl_usenet@goldfisch.at>
    Re: extract block of text <christoph.schuch@gmx.at>
        multilinepattern match <sunil_franklin@hotmail.com>
    Re: multilinepattern match <HelgiBriem_1@hotmail.com>
    Re: Problem with IO::Socket::INET and pop (Joe)
        regexp on HTML <bart-news@NOSPAMtvreclames.nl>
        Signal handling in objects <spaceman-13187-20031106@ausgehaucht.sensenmann.at>
    Re: Whitespace removal in html generated by cgi <syscjm@gwu.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 17 Nov 2003 14:23:15 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Calling a different shell than the inherited one
Message-Id: <slrnbrhmfv.h45.xx087@smeagol.ncf.ca>

dn_perl@hotmail.com <dn_perl@hotmail.com> wrote:
>  I often use C-shell for reasons beyond my control.
[...]
>  If I use :
>  system("sqlplus username/password << EOH");
[...]
>  ... then won't the sqlplus run within the inherited C shell?

'perldoc -f system' says that it won't:
    If there is only one scalar argument, the argument is checked for
    shell metacharacters, and if there are any, the entire argument is
    passed to the system's command shell for parsing (this is "/bin/sh
    -c" on Unix platforms, but varies on other platforms).

-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


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

Date: Mon, 17 Nov 2003 14:21:04 +0100
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: comments on JAPH?
Message-Id: <3fb8cbe7.0@juno.wiesbaden.netsurf.de>

Hi,

below my first attempt for a JAPH. It's not that obfuscated, but I had
a tough time pressing it into 4 lines.

Comments anyone?

Thomas

-- 
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</  #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..



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

Date: 17 Nov 2003 06:36:11 -0800
From: allan@yates.ca (Allan Yates)
Subject: Creating UNICODE filenames with PERL 5.8
Message-Id: <d6f51524.0311170636.2f956afa@posting.google.com>

I have been having distinct trouble creating file names in PERL
containing UNICODE characters. I am running ActiveState PERL 5.8 on
Windows 2000.

For a simple test, I picked a UNICODE character that could be
displayed by Windows Explorer. I can select the character(U+0636) from
'charmap' and cut/paste into a filename on Windows Explorer and the
character displays the same as it does in 'charmap'. This proves that
I have the font available.

When I attempt to create the same filename with PERL, I end up with a
filename two characters long: ض

I somebody could point me in the correct direction, I would very much
appreciate it. I have read the UNICODE documents included with PERL as
well searching the newgroups and the web, and everything appears to
indicate this should work.

Perl program:

  $name = chr(0x0636);

  if (!open(FILE,">uni_names/$name")) {
     print STDERR "Could not open ($!): $name\n";
  }

  close (FILE);


Thanks,

Allan.
a y a t e s  a t  s i g n i a n t  d o t  c o m


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

Date: Mon, 17 Nov 2003 15:12:29 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Creating UNICODE filenames with PERL 5.8
Message-Id: <Pine.LNX.4.53.0311171438540.22311@ppepc56.ph.gla.ac.uk>

On Mon, 17 Nov 2003, Allan Yates wrote:

> I have been having distinct trouble creating file names in PERL
> containing UNICODE characters. I am running ActiveState PERL 5.8 on
> Windows 2000.

N.B I have limited expertise in this specific area, but some of the
locals around here seem to look to me to answer Unicode questions of
any kind, so I'll give it a try, as long as you take the answers with
the necessary grains of salt...

First important question is - have you set the option for wide
character API in system calls?

> For a simple test, I picked a UNICODE character that could be
> displayed by Windows Explorer. I can select the character(U+0636) from

that'd be Arabic letter DAD, right?

Its utf-8 representation will be two octets: 0xd8, 0xb6.

> 'charmap' and cut/paste into a filename on Windows Explorer and the
> character displays the same as it does in 'charmap'. This proves that
> I have the font available.

(I think that's the least of your worries at the moment...)

> When I attempt to create the same filename with PERL, I end up with a
> filename two characters long: ض

Those look like 0xd8 and 0xb6 to me...

At a quick glance, I suspect we are seeing the pair of octets that
represent the character in utf-8 (Perl's internal representation)
rather than as what Win32 would use, which AIUI is utf-16LE (which in
this case would come out as 0x3606, IINM).  However, I'm not sure that
(other than for diagnostic purposes) you should ever need to tangle
with it in that form, since Perl ought to know what to do in a (wide)
system call.

The system call is evidently treating them as two one-byte characters,
hence my question about wide system calls.  Look for the reference to
wide system calls in the perlrun page, and the other references to
which it links.

> I somebody could point me in the correct direction, I would very much
> appreciate it. I have read the UNICODE documents included with PERL as

OK, but there are also some Win32-specific documents/web-pages that
come with the ActivePerl distribution.  In some situations they might
be just what you need.

> well searching the newgroups and the web, and everything appears to
> indicate this should work.

If the above is not the answer, then maybe Win32API::File has
something for you - but I've never been there myself, so don't pay too
much attention to that.

> Perl program:

But did you start it with the -C option, or set the wide system calls
thingy?  I think that may prove to be the key.

Good luck, and please report your findings.


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

Date: 17 Nov 2003 06:36:51 -0800
From: s99999999s2003@yahoo.com (mike)
Subject: extract block of text
Message-Id: <dfd17ef4.0311170636.4b990537@posting.google.com>

hi
i have some data contained in a file like this:

/* ----------------- Heading1 ----------------- */

line: Heading1	type: b
#owner: you@company.com


/* ----------------- Heading2 ----------------- */

line: Heading2	type: c
command: echo "hi" 
owner: me@company.com
machine: server


/* ----------------- Heading3 ----------------- */

 ....


how can i extract the data from "Heading2" to "Heading3" such that
i have this output without the "Headings" and without the empty lines.

line: Heading2	type: c
command: echo "hi" 
owner: me@company.com
machine: server

thanks for any help


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

Date: Mon, 17 Nov 2003 16:04:39 +0100
From: peter pilsl <pilsl_usenet@goldfisch.at>
Subject: Re: extract block of text
Message-Id: <3fb8e4a4$1@e-post.inode.at>

mike wrote:

> 
> how can i extract the data from "Heading2" to "Heading3" such that
> i have this output without the "Headings" and without the empty lines.
> 
> line: Heading2        type: c
> command: echo "hi"
> owner: me@company.com
> machine: server
> 
> thanks for any help
> 

even if OT, cause no perl-question included:

standard approach:
you read the input line per line. If you reach Heading2, set a flag. If you 
reach Heading3 clear the flag. For each line that is not empty check if the 
flag is set - if yes print out the line. (its more efficient to check the 
flag first and then if the line is empty)

if the inputfile is known to be of limited length, you can read all the 
file at once by altering the $/-variable and use the m//-operator to get 
the Text between Heading2 and Heading3 and the s///-operator to eliminate 
empty lines.

If you have any questions regarding one of these steps please feel free to 
ask again and dont forget to post part of your source so we can help you 
even better.

best,
peter

-- 
peter pilsl
pilsl_usenet@goldfisch.at
http://www.goldfisch.at



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

Date: Mon, 17 Nov 2003 16:22:54 +0100
From: "Christoph Schuch" <christoph.schuch@gmx.at>
Subject: Re: extract block of text
Message-Id: <3fb8e7d0@post.usenet.com>

**** Post for FREE via your newsreader at post.usenet.com ****

The following Code should handle your task


open(filein,"<file")

while ($line=<filein>) {

    if ( $line =~ m/\/\* -+ Heading2 -+ \*\/ ) { $flag=0 };

    if ( $flag == "1" && ! ( $line =~ m/^$/ )) {
        print $line;
    }

    if ( $line =~ m/\/\* -+ Heading1 -+ \*\/ ) { $flag=1 };
}


christoph



-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 *** Usenet.com - The #1 Usenet Newsgroup Service on The Planet! ***
                      http://www.usenet.com
Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


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

Date: Mon, 17 Nov 2003 13:32:07 +0530
From: "Sunil" <sunil_franklin@hotmail.com>
Subject: multilinepattern match
Message-Id: <Np%tb.1$U71.32@news.oracle.com>

Hi,
    I have to match a string like

"end;
/"

in a file. Any suggestions on how to do this?

Thanks,
Sunil.







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

Date: Mon, 17 Nov 2003 16:01:10 +0000
From: Helgi Briem <HelgiBriem_1@hotmail.com>
Subject: Re: multilinepattern match
Message-Id: <b3shrv40qb0j08le376e99nkovvdnou282@4ax.com>

On Mon, 17 Nov 2003 13:32:07 +0530, "Sunil"
<sunil_franklin@hotmail.com> wrote:

>Hi,
>    I have to match a string like
>
>"end;
>/"
>
>in a file. Any suggestions on how to do this?

perldoc -q 'matching over more than one line'


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

Date: 17 Nov 2003 05:50:05 -0800
From: unixverse@yahoo.com (Joe)
Subject: Re: Problem with IO::Socket::INET and pop
Message-Id: <fcc97b00.0311170550.5489e434@posting.google.com>

"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in message news:<Xns9432BF749A82asu1cornelledu@132.236.56.8>...
> unixverse@yahoo.com (Joe) wrote in
> news:fcc97b00.0311130526.fe5e615@posting.google.com: 
> 
> > Ben Morrow <usenet@morrow.me.uk> wrote in message
> > news:<boueo5$9cp$1@wisteria.csv.warwick.ac.uk>... 
> >> unixverse@yahoo.com (Joe) wrote:
> >> > # Connect to the POP server using port 110
> >> > $SocketHandle = IO::Socket::INET->new (Proto=>"tcp",
> >> > PeerAddr=>$ServerName, PeerPort=>$Port);
> 
> are you sure $Port == 110 at this point?
> ...
> 
> >> > The web hosting company keeps telling me that they didn't change
> >> > anything and that they can connect fine via telnet ServerName 110.
>  ...
> > For $! I get 'Bad file number' and for $@ 'IO::Socket::INET:
> > Connection refused' 
> 
> That means your script could not connect to $ServerName on that port. 
> Could it be a firewall issue? This does not seem to have much to do with 
> Perl.
> 
> Sinan.

Yeah ... it used to work with port 110 for the POP server.

The thing is that Outlook can connect fine and it is using the same
protocol and port to connect to that server.

I do sit behind a firewall but if the machine on which the script runs
does not have a firewall there should not be a problem ... right? 
Maybe I'm wrong and even if the page that calls the script is behind a
firewall there is a problem.

Thanks,
Joe


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

Date: Mon, 17 Nov 2003 16:57:34 +0100
From: "Bart van den Burg" <bart-news@NOSPAMtvreclames.nl>
Subject: regexp on HTML
Message-Id: <bpar5a$df6$1@reader10.wxs.nl>

Hi

I need to empty the very last cell that can be found in $r

Currently, I have
    $r =~ s:<td>.*</td></tr>$:<td></td></tr>:;

But that merges all cells into one empty cell...
Any ideas on how to do this?

Thanks
Bart

HTML source table =

<table>
<tr class='row1'><td>Name</td><td>Referer</td></tr>
<tr class='row2'><td>Description</td><td>Hoe ben je op deze site terecht
gekomen?</td></tr>
<tr class='row1'><td colspan='2'><table>
<tr><th>no</th><th>Option</th><th>Votes</th></tr>
<tr><td>1.</td><td>Zoekmachine</td><td>17</td><td><img
src='images/delete.gif'/></td><td></td><td><a
href="admin.pl?sessionID=9ZooUn8AAAEAACNWBk0AAAAA&amp;amp;action=poll&amp;ac
tion2=edit&amp;action3=moveup&amp;id=3&amp;option="><img
src='images/arrowdown.gif'/></a></td></tr>
<tr><td>2.</td><td>Andere site</td><td>17</td><td><img
src='images/delete.gif'/></td><td><img src='images/arrowup.gif'/></td><td><a
href="admin.pl?sessionID=9ZooUn8AAAEAACNWBk0AAAAA&amp;amp;action=poll&amp;ac
tion2=edit&amp;action3=moveup&amp;id=3&amp;option="><img
src='images/arrowdown.gif'/></a></td></tr>
<tr><td>3.</td><td>Ander persoon</td><td>10</td><td><img
src='images/delete.gif'/></td><td><img src='images/arrowup.gif'/></td><td><a
href="admin.pl?sessionID=9ZooUn8AAAEAACNWBk0AAAAA&amp;amp;action=poll&amp;ac
tion2=edit&amp;action3=moveup&amp;id=3&amp;option="><img
src='images/arrowdown.gif'/></a></td></tr>
<tr><td>4.</td><td>Gewoon URL gegokt</td><td>11</td><td><img
src='images/delete.gif'/></td><td><img src='images/arrowup.gif'/></td><td><a
href="admin.pl?sessionID=9ZooUn8AAAEAACNWBk0AAAAA&amp;amp;action=poll&amp;ac
tion2=edit&amp;action3=moveup&amp;id=3&amp;option="><img
src='images/arrowdown.gif'/></a></td></tr>
<tr><td>5.</td><td>Anders</td><td>6</td><td><img
src='images/delete.gif'/></td><td><img src='images/arrowup.gif'/></td><td><a
href="admin.pl?sessionID=9ZooUn8AAAEAACNWBk0AAAAA&amp;amp;action=poll&amp;ac
tion2=edit&amp;action3=moveup&amp;id=3&amp;option="><img
src='images/arrowdown.gif'/></a></td></tr>
</table>
</td></tr>
<tr class='row2'><td>Date added</td><td>2003-09-24 00:00:00</td></tr>
</table>




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

Date: Mon, 17 Nov 2003 16:02:21 +0100
From: Stefan Weiss <spaceman-13187-20031106@ausgehaucht.sensenmann.at>
Subject: Signal handling in objects
Message-Id: <2786362.9ZsitlPHYq@weyoun.foo.at>

Hi.

I have a daemon class that needs to handle signals like USR1, USR2, INT,
and TERM depending on the internal state. The way I do it at the moment
is visible in the short demo script below. It works, but I have to admit
that I'm not exactly sure _why_ it works.

Can somebody please explain what happens with that anonymous sub that
gets assigned to $SIG{INT} and $SIG{TERM} in line 22? Where does it take
the value of "$self" from? If it's from the surrounding scope, then how
can it know (later on) that the "running" attribute has changed from 0
to 1? Is this the proper way to do signal handling in an OO context?

TIA,
stefan

------------------------------------------------------------------------
#!/usr/bin/perl

use strict;
use warnings;

my $Daemon = new MyModule;
$Daemon->mainLoop;


package MyModule;

use strict;
use warnings;

sub new {
    my $class = shift;
    my $obj = {
        name    => "MyName",
        running => 0,
    };
    my $self = bless $obj, $class;
    $SIG{TERM} = $SIG{INT} = sub { $self->handleSignal(shift) };
    return $self;
}

sub handleSignal {
    my ($self, $sig) = @_;
    $self->qlog("info", "caught signal $sig; running: $self->{running}");
    $self->qlog("notice", "$self->{name} controlled shutdown");
    exit 0;
}

sub qlog {
    my ($self, $lvl, $msg) = @_;
    print "[$lvl] $msg\n";
}

sub mainLoop {
    my $Xself = shift;
    $Xself->{running} = 1;
    print "in main loop\n";
    for (;;) { sleep 1 }
}


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

Date: Mon, 17 Nov 2003 10:03:36 -0500
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: Whitespace removal in html generated by cgi
Message-Id: <3FB8E348.5070005@gwu.edu>

Gregory Toomey wrote:
> It was a dark and stormy night, and Eric J. Roode managed to scribble:
> 
> 
>>-----BEGIN xxx SIGNED MESSAGE-----
>>Hash: SHA1
>>
>>Gregory Toomey <nospam@bigpond.com> wrote in
>>news:3072218.31r3eYUQgx@gregs- web-hosting-and-pickle-farming:
>>
>>
>>>People hate waiting for pages to load, especially for people on dialup.
>>
>>Have you verified that the extra time your CGI scripts take to execute is
>>less than the transfer time of the spaces you are eliminating?  :-)
>>
> 
> 
> The server I use for cgi is about 2.6GHz and averages 20% CPU utilisation.
> Running the script to remove whitespace takes under 1 second for 1000 lines of HTML, 
> and does not increase the load to any discernable extent.
> 
> The database-driven cgi I use is disk IO bound, not CPU bound.
> 
Which doesn't answer the question.  The question isn't "Are you overloading the
server?", the question is "Are your users waiting longer for you to remove the
whitespace than they would wait for the whitespace to download?"  Assuming there
is ten bytes of removable whitespace per line (which would be rather a lot),
then the whitespace in 1000 lines takes less than two seconds to download on
a 56K modem.  It would take a small fraction of a second with broadband.  It
scarcely seems worth the effort.

                  Chris Mattern



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

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


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