[21794] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3998 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 19 18:05:53 2002

Date: Sat, 19 Oct 2002 15:05:11 -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, 19 Oct 2002     Volume: 10 Number: 3998

Today's topics:
    Re: About to tear my hair out here ... (Newbie Question <wsegrave@mindspring.com>
        adding spaces using regexp (Cosmic Cruizer)
    Re: attr proposition: function call performed at compil <occitan@esperanto.org>
        coverting special characters <tednospam94107@yahoo.com>
    Re: coverting special characters <nospam@nospam.com>
    Re: extract char from string into an 2x2 array <krahnj@acm.org>
    Re: extract char from string into an 2x2 array (kit)
    Re: extract char from string into an 2x2 array (Jay Tilton)
        How to automate filling and submitting web forms. <noname@nospam.com>
        How to use wildcard with perl -pei file1.txt file2.txt  <chris@home.com>
    Re: How to use wildcard with perl -pei file1.txt file2. (Tad McClellan)
    Re: How to use wildcard with perl -pei file1.txt file2. <s_grazzini@hotmail.com>
    Re: How to use wildcard with perl -pei file1.txt file2. <chris@home.com>
    Re: How to use wildcard with perl -pei file1.txt file2. <chris@home.com>
    Re: icmp/udp question <troc@netrus.net>
        IO::Handle::setvbuf not implemented on this architectur <twanus@xs4all.nl>
        Making a server both standalone and tcpd <glenn-nntp@delink.net>
    Re: Making a server both standalone and tcpd <nospam@nospam.com>
    Re: mod_perl-1.99_05-3 and Apache::Constants <no@spam.please>
    Re: Perl tutorial for someone with C background (James E Keenan)
    Re: Pipelining (Tad McClellan)
        References to substrings (Peter Erl)
    Re: References to substrings <usenet@tinita.de>
    Re: References to substrings <wksmith@optonline.net>
    Re: References to substrings <Tassilo.Parseval@post.rwth-aachen.de>
        removing commas in an element of an array of csv file (Doggy)
    Re: removing commas in an element of an array of csv fi <s_grazzini@hotmail.com>
    Re: Using OLE in Perl (Jay Tilton)
    Re: using Perl & TXT as database <pilsl_use@goldfisch.at>
    Re: using Perl & TXT as database <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 19 Oct 2002 13:04:15 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: About to tear my hair out here ... (Newbie Question)
Message-Id: <aos6su$5bs$1@slb6.atl.mindspring.net>

"William Alexander Segraves" <wsegrave@mindspring.com> wrote in message
news:aoqji7$v3o$1@slb6.atl.mindspring.net...
> "Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
> news:Xns92ABD71D15C67sdn.comcast@216.166.71.239...
> > -----BEGIN xxx SIGNED MESSAGE-----
> > Hash: SHA1
<snip>
<snip>
> Yes. Indeed it is. OTOH, if I really wanted to know in detail the
appearance
> of the HTML, I could look at the HTML that CGI.pm generates.
>

While Mr. Roode's example of a one-line table illustrates his preference
well, my motivation to hand code the elements of an HTML table diminishes
rapidly as the size of the table grows.

For example, the Veggie table example at Dr. Stein's site produces the
following HTML code:

<table border><caption><strong>When Should You Eat Your
Vegetables?</strong></ca
ption> <tr valign="TOP" align="CENTER"><th></th> <th>Breakfast</th>
<th>Lunch</t
h> <th>Dinner</th></tr> <tr valign="TOP"
align="CENTER"><th>Tomatoes</th><td>no<
/td> <td>yes</td> <td>yes</td></tr> <tr valign="TOP"
align="CENTER"><th>Broccoli
</th><td>no</td> <td>no</td> <td>yes</td></tr> <tr valign="TOP"
align="CENTER"><
th>Onions</th><td>yes</td> <td>yes</td> <td>yes</td></tr></table>

and the Powers table example produces:

<table width="25%" border><caption><b>Wow.  I can multiply!</b></caption>
<tr><t
h>N</th> <th>N<sup>2</sup></th> <th>N<sup>3</sup></th></tr> <tr><td>1</td>
<td>1
</td> <td>1</td></tr> <tr><td>2</td> <td>4</td> <td>8</td></tr>
<tr><td>3</td> <
td>9</td> <td>27</td></tr> <tr><td>4</td> <td>16</td> <td>64</td></tr>
<tr><td>5
</td> <td>25</td> <td>125</td></tr></table>

See Dr. Stein's web site, link previously cited, for the example code that
uses CGI.pm.

IMO, the code fragments that generated the above HTML are easier to
understand than the raw HTML that is generated by them. But, hey! Beauty is
in the eye of the beholder.

> Let us hope the OP will learn to use that which is most comfortable for
him.
>

Hopefully, the lesson the OP will take from this is that although CGI.pm is
much to be preferred for writing HTML code, there is nothing in it that
precludes the HTML/Forms author from including hand-coded HTML, as well, if
said hand-coded HTML is easier to produce.

All of the above are my opinions, based on personal preference.

Bill Segraves




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

Date: Sat, 19 Oct 2002 19:14:12 GMT
From: XcosmicX.XcruizerX@sbcglobal.com (Cosmic Cruizer)
Subject: adding spaces using regexp
Message-Id: <Xns92AC7C631B636ccruizermydejacom@64.164.98.29>

After working through the following two code segments (modified from an 
earlier thread), I have a much better understanding of how to use a 
combination of regexp and Perl together. The 'e' modifier sure adds an 
impressive amount of power to the expressions.

$str = "now good-morn_2u to you and good23 and another 23good with _good";
$str =~ s/([-_a-z0-9]*good[-_a-z0-9]*\w*)/join ' ', (split \/\/, $1)/ge;
print "1. $str \n\n"; 

$str = "now good-morn_2u to you and good23 and another 23good with _good";
$str =~ s/([-_a-z0-9]*good[-_a-z0-9]*\w*)/my $x=$1; $x =~ s#(.)#$1 #g; 
$x/ge;
print "2. $str \n\n"; 

Now, even though it will probably generally be more logical to use '/ge', is 
it possible to craft an expression to accomplish the same task without using 
the 'e' modifier?


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

Date: Sat, 19 Oct 2002 12:09:43 +0200
From: Daniel Pfeiffer <occitan@esperanto.org>
Subject: Re: attr proposition: function call performed at compile time
Message-Id: <20021019120943.47476f24.occitan@esperanto.org>

Benjamin Goldberg <goldbb2@earthlink.net> skribis:
> Daniel Pfeiffer wrote:
> > Benjamin Goldberg <goldbb2@earthlink.net> skribis:
> > > This could probably be accomplished with a source filter.

> > Haven't come across those (only got 5.8 with SuSE 8.1 last week :-). 
> > How do they work?

> Look at the docs of Filter::Util::Call and Filter::Simple.

Wow, they are absolutely crazy!  This will have to settle in my mind before I consider using it for anything :-)

coralament / best Grötens / liebe Grüße / best regards / elkorajn salutojn
Daniel Pfeiffer

-- 
 -- http://dapfy.bei.t-online.de/sawfish/
  --


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

Date: Sat, 19 Oct 2002 12:46:07 -0700
From: "ted" <tednospam94107@yahoo.com>
Subject: coverting special characters
Message-Id: <aosch0$u88$1@slb7.atl.mindspring.net>

Hello,

Sorry for this cross-post. I posted a few days ago in comp.lang.perl but
haven't had a response.

How would I replace special characters like registration, trade or copyright
marks?

I'm reading text from Word docs and putting them in HTML files.

Are these Unicode characters?

How would I replace other characters so that they show up correctly in a
browser?

Any help appreciated. Thanks.

-Ted







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

Date: Sat, 19 Oct 2002 12:57:45 -0700
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: coverting special characters
Message-Id: <3db1b8ac_2@nopics.sjc>


"ted" <tednospam94107@yahoo.com> wrote in message
news:aosch0$u88$1@slb7.atl.mindspring.net...
> Hello,
>
> Sorry for this cross-post. I posted a few days ago in comp.lang.perl but
> haven't had a response.
>
> How would I replace special characters like registration, trade or
copyright
> marks?
>
> I'm reading text from Word docs and putting them in HTML files.
>
> Are these Unicode characters?
>
> How would I replace other characters so that they show up correctly in a
> browser?
>
> Any help appreciated. Thanks.
>
> -Ted

MS Word documents aren't plain-text format. You can't read them in the same
way you read text files. You might want to take a look at the OLE module for
accessing MS compound files.




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

Date: Sat, 19 Oct 2002 11:11:04 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: extract char from string into an 2x2 array
Message-Id: <3DB13D8D.C16ECCF9@acm.org>

kit wrote:
> 
> I have a 2 x 2 array,
> 
> # to initialize the 2 x 2 array with character,
> # my idea is from c++ point of view, it probably will have a better
> way..
> for $r (0..20){
>   for $c (0..50){
>     $myArray[$r][$c] = " ";
>   }
> }

my @myArray[0..20] = ();
@$_ = (' ') x 51 for @myArray;


> and I've tried the folloing from the book to extract the characters
> from a string and put the characters into an array.( put a string into
> an array )
> 
> @{$myArray[2]} [44..49] = "Hello";

@$_[44..49] = ('Hello') x 6 for @myArray;



John
-- 
use Perl;
program
fulfillment


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

Date: 19 Oct 2002 11:03:23 -0700
From: manutd_kit@yahoo.com (kit)
Subject: Re: extract char from string into an 2x2 array
Message-Id: <1751b2b5.0210191003.17bed306@posting.google.com>

tiltonj@erols.com (Jay Tilton) wrote in message news:<3db101cf.53047506@news.erols.com>...
> manutd_kit@yahoo.com (kit) wrote:
> 
> | I have a 2 x 2 array,
> 
> It looks more like a 21 x 51 array.
> 
> | # to initialize the 2 x 2 array with character, 
> | # my idea is from c++ point of view, it probably will have a better
> | way..
> | for $r (0..20){
> |   for $c (0..50){
> |     $myArray[$r][$c] = " ";
> |   }
> | }
> | 
> | and I've tried the folloing from the book 
> 
> What book?

From o'reilly programming perl p.272

> 
> | to extract the characters
> | from a string and put the characters into an array.( put a string into
> | an array )
> | 
> | @{$myArray[2]} [44..49] = "Hello";
> 
> That has six elements on the left of the list assignment, and one on
> the right.  
> $myArray[2][44] gets "Hello"
> $myArray[2][45] through $myArray[2][49] get undef
> 
> Split the string into characters to get those individual characters
> into individual cells.
> 
>     @{$myArray[2]}[44..49] = split //, "Hello";
>                        ^^
>                        ^^
> Might want to change that to 48, though.  "Hello" has only five
> characters.
>   
> | after that, when I print the whole array out, the compiler gives me
> | this error message (5 times, I believe it related to the length of the
> | string "hello"):
> 
> No, it's related to how many elements in that array slice assignment
> have no value in the list on the RHS.
> 
> | error message >> Use of uninitialized value in print at test.pl line
> | 52.
> 
> That's a warning, not an error.
> 
> | I need the first idea because I want to have one character only in
> | each cell from the array.
> 
> Seems like you're carrying some conceptual baggage from another
> programming language.  Consider using a 21-element array of
> 51-character strings.
> 
>     # Initialize
>     my @myarray = (' ' x 51) x 21;
> 
>     # Alter part of one string
>     substr($myarray[2], 44, 5) = "Hello";
> 
>     # print screen loop
>     for my $r (0..20) {
>         print "$myarray[$r]\n";
>     }

Is it mean that I can only access the 51 x 21 Array by using this:
      substr($myarray[2], 44, 1) = 'o';
Can I use another methods either?

Again, thanks for your help
Kit


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

Date: Sat, 19 Oct 2002 21:56:51 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: extract char from string into an 2x2 array
Message-Id: <3db1ce1d.105357331@news.erols.com>

manutd_kit@yahoo.com (kit) wrote:

| tiltonj@erols.com (Jay Tilton) wrote in message news:<3db101cf.53047506@news.erols.com>...
| > manutd_kit@yahoo.com (kit) wrote:
| > 
| > | and I've tried the folloing from the book 
| > 
| > What book?
| 
| From o'reilly programming perl p.272

I see.  That section is about array slices, and you got that part just
right.  I was only wondering if your book had given the
misapprehension that the string assignment would put separate
characters into the elements of the array slice.

| >     # Initialize
| >     my @myarray = (' ' x 51) x 21;
| > 
| >     # Alter part of one string
| >     substr($myarray[2], 44, 5) = "Hello";
| > 
| >     # print screen loop
| >     for my $r (0..20) {
| >         print "$myarray[$r]\n";
| >     }
| 
| Is it mean that I can only access the 51 x 21 Array by using this:
|       substr($myarray[2], 44, 1) = 'o';
| Can I use another methods either?

Any function that works on a string can be used on one of the array
elements.  substr, index, vec, unpack, regexes, lc, uc, reverse
 ...gobs of them.

But it's not necessarily an either/or choice.

It's possible to use a 2-D array of characters as the data structure,
then create a set of functions to use it like a set of strings.
Likewise, it's possible to use a 1-D array of strings as the data
structure, then create a set of functions to use it as a 2-D array of
characters.


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

Date: Sun, 20 Oct 2002 00:00:48 +0300
From: noname <noname@nospam.com>
Subject: How to automate filling and submitting web forms.
Message-Id: <3DB1C800.2040601@nospam.com>

I am newbie (not spammer) and may be this question is too trivial..

I have list of URL pointing to webforms, which I want to fill and 
submit. Of course, it is possible to go to each URL and fill and click 
"Submit".

My question is, it there any application, using which I can automate, 
it, i.e. by giving URLs and data to be filled on those webforms.

Or can it be done using Perl (I am yet to learn it)

Thanks in advance ;)

-E-



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

Date: Sat, 19 Oct 2002 15:32:03 GMT
From: chris <chris@home.com>
Subject: How to use wildcard with perl -pei file1.txt file2.txt > bigfile?
Message-Id: <fku2rugrai5e11hbu43l8uhumekq3ghknv@4ax.com>

How to use wildcard?
perl -pei file1.txt file2.txt > bigfile

something like
perl -pei *.txt > bigfile


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

Date: Sat, 19 Oct 2002 11:19:42 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to use wildcard with perl -pei file1.txt file2.txt > bigfile?
Message-Id: <slrnar31gu.3bu.tadmc@magna.augustmail.com>

chris <chris@home.com> wrote:

> How to use wildcard?


Sensible shells will do it for you, for unsensible shells
you must do it yourself:


   perldoc -f glob


> perl -pei file1.txt file2.txt > bigfile


Your "code" consists of nothing more than the letter "i" there.

Did you mean you use the -i switch and provide a code
argument for -e instead?

I hope not, because then the contents of "bigfile" will be
awfully uninteresting.


> something like
> perl -pei *.txt > bigfile


   perl -p -e 'print "code goes here\n"' *.txt >bigfile


works for me.

The answer to your question depends on the shell you are using,
and you have not shared what shell it is that you are using.

In case you are saddled with working in an unsensible shell,
you might try this:


   perl -p -e "BEGIN{@ARGV=glob $ARGV[0]} print qq(code goes here\n)" "*.txt"


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


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

Date: 19 Oct 2002 10:50:31 -0600
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: How to use wildcard with perl -pei file1.txt file2.txt > bigfile?
Message-Id: <3db18d56@news.mhogaming.com>

chris <chris@home.com> wrote:
> How to use wildcard?
> perl -pei file1.txt file2.txt > bigfile
> 
> something like
> perl -pei *.txt > bigfile

If you're really trying to concatenate the files, that 
should work on *nix or any shell that does wildcard 
globbing.

Of course cat(1) also works on Unix...

But your command line is rather misleading, since -i 
is also a switch.  I'd rather use -e1 for a no-op.

  $ perl -p -e1 *.txt > bigfile

And finally if your shell doesn't expand the wildcard 
you can do it in perl like this:

  $ perl -pe "BEGIN{ @ARGV = glob '*.txt' }" > bigfile

HTH
-- 
Steve

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


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

Date: Sat, 19 Oct 2002 18:05:24 GMT
From: chris <chris@home.com>
Subject: Re: How to use wildcard with perl -pei file1.txt file2.txt > bigfile?
Message-Id: <lj73rusd0vedlcgj51mgaf3pjvgq9eefdh@4ax.com>

This prints all the filenames, do I dare ask how to print file content
instead?

 perl -p -e "BEGIN{@ARGV=glob $ARGV[0]} print qq(<@ARGV>\n)" *.txt

On Sat, 19 Oct 2002 11:19:42 -0500, tadmc@augustmail.com (Tad
McClellan) wrote:

>In case you are saddled with working in an unsensible shell,
>you might try this:
>
>
>   perl -p -e "BEGIN{@ARGV=glob $ARGV[0]} print qq(code goes here\n)" "*.txt"
>



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

Date: Sat, 19 Oct 2002 18:17:53 GMT
From: chris <chris@home.com>
Subject: Re: How to use wildcard with perl -pei file1.txt file2.txt > bigfile?
Message-Id: <nc83ru84cgq1bj0p2tsflph365h4lq0jhf@4ax.com>

$ perl -pe "BEGIN{ @ARGV = glob '*.txt' }" > bigfile

Thank you for your help.

On 19 Oct 2002 10:50:31 -0600, Steve Grazzini <s_grazzini@hotmail.com>
wrote:

>chris <chris@home.com> wrote:
>> How to use wildcard?
>> perl -pei file1.txt file2.txt > bigfile
>> 
>> something like
>> perl -pei *.txt > bigfile
>
>If you're really trying to concatenate the files, that 
>should work on *nix or any shell that does wildcard 
>globbing.
>
>Of course cat(1) also works on Unix...
>
>But your command line is rather misleading, since -i 
>is also a switch.  I'd rather use -e1 for a no-op.
>
>  $ perl -p -e1 *.txt > bigfile
>
>And finally if your shell doesn't expand the wildcard 
>you can do it in perl like this:
>
>  $ perl -pe "BEGIN{ @ARGV = glob '*.txt' }" > bigfile
>
>HTH



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

Date: Sat, 19 Oct 2002 21:41:31 -0000
From: Rocco Caputo <troc@netrus.net>
Subject: Re: icmp/udp question
Message-Id: <slrnar3k9g.8ma.troc@eyrie.homenet>

On Sat, 19 Oct 2002 07:11:10 GMT, smackdab wrote:
> Thanks!
> 
> Just want to make sure on 1 point:
> 
>> Yes, you can include the sequence number in whatever you're
>> send()'ing via UDP.  No, you won't need to build raw packets.
>
> Since there is no room in a UDP header for the seq#, do I just put
> it in the body of the packet?  If so, does the receiver of my UDP
> packet always send it back to me?

I suppose yes, you do add it to the payload of the UDP packet.

Whether you get the sequence number back depends on the UDP service
you're pinging.  UDP echo will, of course, but the remote host needs
that service enabled.  Other services might or might not, depending on
the protocols they use.

-- Rocco Caputo / troc@pobox.com / poe.perl.org / poe.sf.net


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

Date: Sat, 19 Oct 2002 17:02:12 +0200
From: Antwan Reijnen <twanus@xs4all.nl>
Subject: IO::Handle::setvbuf not implemented on this architecture.
Message-Id: <3DB173F4.8070905@xs4all.nl>

Hi all,

I am experiencing problems while trying to run this Perl code on Redhet 
8.0. It worked before on Redhat 7.2 / 7.3:

STDOUT->setvbuf($nothing_here, _IONBF, 0)

It complains: IO::Handle::setvbuf not implemented on this architecture.

My uname -a:

Linux twanus 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686 i686 i386 
GNU/Linux

My perl -v:

This is perl, v5.8.0 built for i386-linux-thread-multi

Where or how should I look for an answer? Is it a faulty or missing C 
library, or is it a Perl problem?

Any help would be greatly appreciated, greetings, Antwan Reijnen.



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

Date: Sat, 19 Oct 2002 11:13:55 -0400
From: Brian T Glenn <glenn-nntp@delink.net>
Subject: Making a server both standalone and tcpd
Message-Id: <Pine.LNX.4.44.0210191103410.24022-100000@ziege.delink.net>

I am writing a server program that I would like to have the ability to
switch between having the program do its own sockets and having just use
STDIN/STDOUT for use with tcp wrappers.

The server will only handle one connection at a time, so forking or using
select() or poll() is not an issue.

Currently, it works doing its own sockets with the following code:

        our $dyndns;
        our %opt;
        # make this the session leader
        POSIX::setsid() or die "Cannot setsid";

        # signal handlers for daemon
        $SIG{INT} = "IGNORE";
        $SIG{CHLD} = sub { 1 until waitpid(-1,WNOHANG) == -1 };

        # this is a daemon so fork off instantly
        if (my $pid = fork) { exit; } else {

                # write pid to file
                if (open PID,"/var/run/dyndnsd.pid") {
                        print PID $pid;
                        close PID;
                }

                # set up the socket
                socket(DYNDNS, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
                setsockopt(DYNDNS,SOL_SOCKET,SO_REUSEADDR,1);
                bind(DYNDNS,sockaddr_in($opt{port},INADDR_ANY))
			or die "Couldn't bind to port $opt{port}: $!";
                listen(DYNDNS, SOMAXCONN) or die "Couldn't listen: $!";
                # loop forever, accepting connections
                while(accept(DD,DYNDNS)) {
                        $dyndns->sock(*DD);
                        $dyndns->HandleConnection();
                        close DD;
                }
        }


I assign the typeglob into the object using my sock method, which merely
assigns it into part of the blessed hash so that other methods can have
access to it. The HandleConnection method then does what it needs to do
with the connection.

Is there a way to possibly make *DD write output to STDOUT and read input
from STDIN? I would like to find a way to be able to reuse my existing
module without completely having to redo the IO that is working for
standard sockets.

I have looked up information on open() and found a reference to dup() in
the FAQ, but none of it seems to be what I need.

Any help would be appreciated.
-- 
Brian T Glenn
Admin, delink.net



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

Date: Sat, 19 Oct 2002 13:31:11 -0700
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: Making a server both standalone and tcpd
Message-Id: <3db1c081$1_4@nopics.sjc>


"Brian T Glenn" <glenn-nntp@delink.net> wrote in message
news:Pine.LNX.4.44.0210191103410.24022-100000@ziege.delink.net...
> I am writing a server program that I would like to have the ability to
> switch between having the program do its own sockets and having just use
> STDIN/STDOUT for use with tcp wrappers.
[snipped]
> Is there a way to possibly make *DD write output to STDOUT and read input
> from STDIN? I would like to find a way to be able to reuse my existing
> module without completely having to redo the IO that is working for
> standard sockets.
> I have looked up information on open() and found a reference to dup() in
> the FAQ, but none of it seems to be what I need.


Why don't you just use IO::Socket ? It's much nicer to look at the code.
Anyways, you might wan to check out pipe and dup to redirect input/output
streams.

>         if (my $pid = fork) { exit; } else {                 <== what
happens if fork fails. It returns undef for $pid

If all you want is just interacting with the socket connection, something
like this will do [untested]

use strict;
use IO::Socket;    # it doesn't make you God if you go with Perl built-in
functions ;-)

my $pid = undef;
defined($pid = fork) or die "forking server: $!\n";
exit 0 if $pid;
my $serv = new IO::Socket::INET(
                                                      Listen => 1,
                                                      LocalPort => 12345,
                                                      Proto => 'tcp',
                                                      ReuseAddr => 1
                                                    ) or die "new
IO::Socket::INET - $!\n";
while (my $conn = $serv->accept) {
       while (my $line = $conn->getline) {
               print $line, "\n";                # prints to stdout
               $conn->print(<>);           # wait for stdin input and write
to $conn
       }
       close $conn;
}
close $serv;
exit 0;

etc.....




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

Date: Sat, 19 Oct 2002 21:41:29 GMT
From: matt <no@spam.please>
Subject: Re: mod_perl-1.99_05-3 and Apache::Constants
Message-Id: <dkks9.17575$La5.45190@rwcrnsc52.ops.asp.att.net>

matt wrote:

> I just installed RedHat 8.0 running perl v5.8.0 with mod_perl-1.99_05-3.
> I am just starting to play with mod_perl, and I am having some problems.
> It looks like Apache::Constants doesn't exist in this release of
> mod_perl. There is a module called Apache::Const in my @INC at
> /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi/Apache/Const.pm.
> Is this the same (no, just reading the file tells me that)? So what's
> the scoop in Constants.pm. I have a calendar script that depends on it.
> 
> Thanks in advance for any help. -- Matt

I found the answer at :
http://perl.apache.org/docs/2.0/user/compat/compat.html#C_Apache__Constants_

--Matt




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

Date: 19 Oct 2002 09:44:39 -0700
From: jkeen@concentric.net (James E Keenan)
Subject: Re: Perl tutorial for someone with C background
Message-Id: <b955da04.0210190844.69184e57@posting.google.com>

Ian Johnson <ian_johnson@zdnet.com> wrote in message news:<MPG.181b21e4beb4eea098976c@news.hinet.hr>...
> I would like suggestions on complete and free online Perl tutorial, for 
> someone with a solid knowledge of C language.
> I could have scoured the net for one, but given that in my experience 
> good and accurate online tutorials on any given language are rare, I 
> thought asking the experts on the subject might be a better way to go.
> 
> Ian

Another suggestion:  Older Perl textbooks tended to assume that the
reader was approaching Perl from a C background and were written based
on that assumption.  You might, for example, try to pick up a used
copy of the *2nd* edition of Randal Schwartz's "Learning Perl" (or
"Learning Perl on Win32 Systems") which is replete with statements
such as "C programmers will recognize ...."

Since people now come to Perl from many backgrounds in addition to C,
Randal has rewritten the *3rd* edition of the book to remove most of
the C assumptions.  But if it's the C flavor you want, try to get a
copy of one of the first two editions.


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

Date: Sat, 19 Oct 2002 07:56:08 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Pipelining
Message-Id: <slrnar2lj8.2mm.tadmc@magna.augustmail.com>

Anirban Chakraborti <achakrab@nmsu.edu> wrote:

>         I have a perl program that generates huge amount of data which
> is then processed by another perl program.Since the data output is
> huge I wanted to use a pipe between the two program.


How are the two programs invoked?

Can't you just do the piping at the command line?

   program1 | program2

Then you won't need to do anything special at all in your Perl
code, p1 writes to STDOUT, p2 reads from STDIN.


> Although i am
> using a pipe but I am not able to make the second perl program to read
> from the pipe.


That depends on how the programs are called.

Do you want the p1 program to call p2?

If so, why not just have p2 do the calling of gzip?


> I am not sure how to do this.


I'm not even sure what "this" you mean...


> here is my program 
> // the follwing line unzips the file and pipes it


I doubt that.


> open(NEW,"gzip -d output.gz |);


Syntax error!

Please do not try and retype code, use copy/paste.


> now a another perl program should take input from the pipe 


Why can't the 2nd program do the open(gzip) call?


> and i need
> it to do it in a program

   # untested
   # unnecessary too, AFAICT

   # p1
   open(NEW,"gzip -d output.gz |") or die "problem running gzip: $!";
   open(PROG2,"| p2") or die "problem running p2: $!";
   print PROG2 while <NEW>;
   close(NEW) or die "problem running gzip: $!";
   close(PROG2) or die "problem running p2: $!";
   
   # p2
   while ( <STDIN> ) {
      # do stuff
   }

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


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

Date: 19 Oct 2002 09:43:42 -0700
From: p76e160a4@hotmail.com (Peter Erl)
Subject: References to substrings
Message-Id: <9fc0467f.0210190843.10ebfa83@posting.google.com>

I don't know if this is possible - web searches haven't helped and
my text books don't have a solution.

I have a large blob of readonly data that I want to process as 
records without actually creating the records, ie a split
operation that returns an array of references to the original
data rather than a new list:

$data = "sdklfjsdkfj\ndkdfg\ndfjkgdgjk\n";

@refs = splitref(/\n/, $data);

print "yes\n" if (\$data == $refs[0]);


It's probably a FAQ somewhere, any suggestions or pointers appreciated.

Thanks,
Pete


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

Date: 19 Oct 2002 17:24:00 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: References to substrings
Message-Id: <aos4fg$p4bgs$1@fu-berlin.de>

Peter Erl <p76e160a4@hotmail.com> wrote:

> I have a large blob of readonly data that I want to process as 
> records without actually creating the records, ie a split
> operation that returns an array of references to the original
> data rather than a new list:

> $data = "sdklfjsdkfj\ndkdfg\ndfjkgdgjk\n";
> @refs = splitref(/\n/, $data);
> print "yes\n" if (\$data == $refs[0]);

i actually don't understand what you want, but the subject
made me think about:
my $x = \substr($string, 1,3);

you can now print $$x and also change it, and then
the original string will be changed.

is that what you wanted?
-- 
http://www.tinita.de/        \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/      \     / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/   \    \ _,_\ __/\ __/_| /__/ perception


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

Date: Sat, 19 Oct 2002 18:25:45 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: References to substrings
Message-Id: <Jshs9.32884$eW3.29811@news4.srv.hcvlny.cv.net>


"Peter Erl" <p76e160a4@hotmail.com> wrote in message
news:9fc0467f.0210190843.10ebfa83@posting.google.com...
> I don't know if this is possible - web searches haven't helped and
> my text books don't have a solution.
>
> I have a large blob of readonly data that I want to process as

Perl variables do not have a 'readonly' attribute.

> records without actually creating the records, ie a split
> operation that returns an array of references to the original
> data rather than a new list:

It sounds like you are looking for the functionality of pointers in the
language 'C'.  String processing in Perl is quite diffferent.  A reference
points to a string, not a character.

>
> $data = "sdklfjsdkfj\ndkdfg\ndfjkgdgjk\n";
>
> @refs = splitref(/\n/, $data);

@strings = split("\n",$data)

>
> print "yes\n" if (\$data == $refs[0]);

This would never be true in Perl.

>
>
> It's probably a FAQ somewhere, any suggestions or pointers appreciated.
>

I would have to know more about your application in order to suggest a Perl
solution.

Bill







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

Date: 19 Oct 2002 19:59:37 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: References to substrings
Message-Id: <aosdj9$48v$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Bill Smith:

> "Peter Erl" <p76e160a4@hotmail.com> wrote in message
> news:9fc0467f.0210190843.10ebfa83@posting.google.com...
>> I don't know if this is possible - web searches haven't helped and
>> my text books don't have a solution.
>>
>> I have a large blob of readonly data that I want to process as
> 
> Perl variables do not have a 'readonly' attribute.

This is, technically speaking, not quite true. You can turn any
Perl-scalar into something readonly by setting the SVf_READONLY flag:
    
    SvFLAGS(get_sv("_", TRUE)) |= SVf_READONLY;

This would set $_ readonly. Of course, this only works on XS-level.
Strange that the language Perl itself does not have inbuilt means to
flag a variable readonly, especially since the internal infrastructure
is already there.

>> records without actually creating the records, ie a split
>> operation that returns an array of references to the original
>> data rather than a new list:
> 
> It sounds like you are looking for the functionality of pointers in the
> language 'C'.  String processing in Perl is quite diffferent.  A reference
> points to a string, not a character.
> 
>>
>> $data = "sdklfjsdkfj\ndkdfg\ndfjkgdgjk\n";
>>
>> @refs = splitref(/\n/, $data);
> 
> @strings = split("\n",$data)

    @strings = split /\n/, $data;

split() takes a regex as first parameter.

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: 19 Oct 2002 12:56:04 -0700
From: tru64dog@yahoo.com (Doggy)
Subject: removing commas in an element of an array of csv file
Message-Id: <18239c3a.0210191156.42841719@posting.google.com>

Below underneath my Perl code is a snip of a CSV file. I'm using the
split function of Perl to parse
the CSV file but one of the elements of the array has a 
comma in it ("Akel, Jason") and its throwing my program out of wack.
What
I'm trying to do is parse the first and last name and email address.
How do I
eliminate commas in an element of an array from a comma delimited
file.

open(IN, $mailfile) || die "can't open file: $!";
foreach $line ( <IN> ) {

chomp $line;
@values = split (/,/, $line);
$firstname = $values[1];
$lastname  = $values[2];
$email = $1 if $values[9] =~ m/^[^:]*:([^%]+)%/;
print "$email\n";
}
close IN;



Mailbox,Jason,Akel,"Akel,Jason",AkelJas,AkelJas,TRAVELPORTAL\AkelJas,TPX003,,X400:c=US;a=
;p=HFS;o=TRAVELPORTAL;s=Akel;g=Jason;%SMTP:Jason.Akel@trip.com,Distribution/cn=Travelportal%Distribution/cn=Travel
Portal - Marketing%/o=HFS/ou=TNI
Denver/cn=Recipients/cn=sitesum%/o=HFS/ou=TNI
Denver/cn=Recipients/cn=weeklydeploy,/o=HFS/ou=TRAVELPORTAL/cn=Recipients,


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

Date: 19 Oct 2002 14:53:12 -0600
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: removing commas in an element of an array of csv file
Message-Id: <3db1c638@news.mhogaming.com>

Doggy <tru64dog@yahoo.com> wrote:
> Below underneath my Perl code is a snip of a CSV file. I'm 
> using the split function of Perl to parse the CSV file but 
> one of the elements of the array has a comma in it 
> ("Akel, Jason") and its throwing my program out of wack.  
> What I'm trying to do is parse the first and last name and 
> email address.  How do I eliminate commas in an element of 
> an array from a comma delimited file.
> 

[ XY problem -- but at least you tell us the X. ]

There's a regex solution in the FAQ:

  $ perldoc -q delimited

But using one of the modules mentioned afterward
would probably be a better idea.

-- 
Steve

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


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

Date: Sat, 19 Oct 2002 11:45:19 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Using OLE in Perl
Message-Id: <3db13614.66430477@news.erols.com>

"mark wildey" <Mark@ecc-limited.com> wrote:

| Hi there
| 
| I have written a small number of scripts that use OLE and really struggle on
| the format/sequence of parms. I can use the Macro facility in Excel to
| generate some VBA code but converting this into Perl is not always straight
| forward.
| 
| Is there a document/url that describes how to convert OLE into Perl.

Besides the Win32::OLE documentation itself, not really.
An example or two (short ones) of some VBA code that's giving
difficulty in conversion might shed some light on things.

| P.S. If anyone has any code that deletes an Excel worksheet I would really
| appreciate it !

Say you had an Excel VBA sub like this,

    Sub foo()
        Application.DisplayAlerts = False 'No confirmation dialog
        Workbooks.Open ("c:\temp\test.xls")
        ActiveWorkbook.Worksheets("Sheet1").Delete
        ActiveWorkbook.SaveAs ("c:\temp\test_altered.xls")
    End Sub

Written in Perl, it might go like this,

    #!perl
    use warnings;
    use strict;
    use Win32::OLE;
    Win32::OLE->Option(Warn => 2); # Carp::carp on error

    my $app = Win32::OLE->new('Excel.Application')
        or die "Could not create OLE object";
    $app->{DisplayAlerts} = 0;
    my $wb = $app->Workbooks->Open('c:\temp\test.xls')
        or $app->Quit(), die('Workbook was not opened');
    $wb->Worksheets("Sheet1")->Delete;
    $wb->SaveAs('c:\temp\test_altered.xls');
    $app->Quit;

You could just skip the conversion gobbledegook and run the VBA macro
directly.

    $app->Workbooks->Open('c:\temp\mymacros.xla')
        or $app->Quit(), die('Could not open macros');
    $app->Run("mymacros.xla!foo");
    $app->Quit;



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

Date: Sat, 19 Oct 2002 15:42:52 +0200
From: peter pilsl <pilsl_use@goldfisch.at>
Subject: Re: using Perl & TXT as database
Message-Id: <3db16164$1@e-post.inode.at>

Boer wrote:

> Hi
> i recently built a Perl-driven relational database (just for the fun of
> programming), which uses text files to store records in. I actually have
> been using it now in a 'real life' situation, for a website with an
> average of 400 hits per day. It is very fast and doesn't seem to have
> problems.
> 
> My question: is it better to use a database like mySQL? I read somewhere
> that high traffic websites might cause problems when generating lots of
> disk access.
> The advantage of using Perl-n-TXT is its speed.
> 

SQL-Databases are optimized for loads of data, for loads of simultaneos 
access and different userrights and locks. 
If this is your situation then I doubt if a text-based db can competite 
against it.
SQL-Databases also speak SQL which makes the data migrateable and takes a 
lot of work from the programmer cause he can used standardized complex 
queries.

If you need high-speed-access to a certain type of data, then textfiles 
will be the winners.

In our system we store all the content in a SQL-database, but for searching 
and (reverse) indexing we use mod_perl with persistent indexhashes to 
textfiles :)

thnx,
peter


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



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

Date: Sat, 19 Oct 2002 14:48:58 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: using Perl & TXT as database
Message-Id: <3DB170B5.80600@rochester.rr.com>

Boer wrote:

> Bob Walton wrote:
> [ ... ]
 ...


> What would you qualify as 'fair sized chunk of data'?
 ...


> JW
> 
> 

Well, that will depend on your system.  I would say something that 
wouldn't fit in your disk drive's cache buffer -- maybe a megabyte or 
two these days.  If it doesn't have to actually read it from the 
physical disk, it will be "instant", at least in comparison to what 
happens when it does have to physically read it each time.  The other 
loads on the computer will also affect that big-time -- if it is a 
dedicated web server running only your application, everything might sit 
around in high-speed buffers all the time.  If it is doing a jillion 
other things, that won't happen.  If buffering is operating in your 
favor, you will notice your script is slower the first time, and faster 
after that.  HTH.

-- 
Bob Walton



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

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


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