[19547] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1742 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 13 18:06:09 2001

Date: Thu, 13 Sep 2001 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)
Message-Id: <1000418709-v10-i1742@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 13 Sep 2001     Volume: 10 Number: 1742

Today's topics:
    Re: Client Timeout (Chris Fedde)
        deleting items from array - better way? <djberge@qwest.com>
    Re: deleting items from array - better way? (Randal L. Schwartz)
    Re: deleting items from array - better way? (John J. Trammell)
    Re: deleting items from array - better way? <joe+usenet@sunstarsys.com>
    Re: File name to process from standard input? <mmynsted@prodigy.net>
        file output <kyi@psnw.com>
    Re: file output <rsherman@ce.gatech.edu>
    Re: Help on Perl parsing file to locate and replace Inc (Chris Fedde)
    Re: How to preallocate memory for my perl script (UNIX) (Chris Fedde)
        http server validation <herve.schlecht@wanadoo.fr>
    Re: http server validation (Chris Fedde)
    Re: http server validation <joe+usenet@sunstarsys.com>
    Re: http server validation <comdog@panix.com>
    Re: http server validation <comdog@panix.com>
        Interrupted Server Socket Connections (Lyle Goldman)
        Microsoft ACL <ben@ralph.demon.co.uk>
        mod_perl or PHP for database drive site? (kramer)
    Re: O Reilly online books <pne-news-20010913@newton.digitalspace.net>
        printing from an IO handle _to_ an IO handle <bernie@fantasyfarm.com>
    Re: printing from an IO handle _to_ an IO handle (Chris Fedde)
        Running perl scripts (katan8472)
    Re: Running perl scripts <kyi@psnw.com>
    Re: Running perl scripts <mjcarman@home.com>
    Re: scalar global search <gnarinn@hotmail.com>
        Server & shutdown calls <mark.riehl@agilecommunications.com>
    Re: Warning on adding hash element <pne-news-20010913@newton.digitalspace.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 13 Sep 2001 19:15:17 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Client Timeout
Message-Id: <9B7o7.376$Owe.259242496@news.frii.net>

In article <3BA0D25A.29291580@cs.man.ac.uk>,
Andrew Paul Gorton  <gortona@cs.man.ac.uk> wrote:
>Hi,
>
>I have a client/server  running, but I need the client to end the
>connection, if the server takes too long.
>
>I am using IO::Socket.  I have tried using the timeout function on the
>client side but it does not work.
>

Timeout in IO::Socket will abort from a slow connect but once the socket
is establised it is nolonger used.  Look at the alarm function and IO::Select
and see if there are ideas there that might help you.

good luck
-- 
    This space intentionally left blank


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

Date: Thu, 13 Sep 2001 14:56:26 -0500
From: "Daniel Berger" <djberge@qwest.com>
Subject: deleting items from array - better way?
Message-Id: <d78o7.450$x62.215233@news.uswest.net>

Hi all,

I want to delete all values from an array that match $val.  Note that I
don't want to merely replace them with null strings (defined or not).  I dug
around the "one-liners" section of TPJ, the cookbook and this newsgroup but
didn't see one.

e.g. Get rid of all values that match "one".
my @array = qw(one two three one one);
my $val = 'one';
# Begin 2 liner
my $n = 0;
map{ if($_ =~ /$val/){ splice(@array,$n,1); $n--; } } @array;

Can I cut this from a 2-liner to a 1-liner?  Is there a better way?

Thanks in advance.

Regards,

Mr. Sunblade





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

Date: 13 Sep 2001 12:59:23 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: deleting items from array - better way?
Message-Id: <m1adzy276s.fsf@halfdome.holdit.com>

>>>>> "Daniel" == Daniel Berger <djberge@qwest.com> writes:

Daniel> I want to delete all values from an array that match $val.  Note that I
Daniel> don't want to merely replace them with null strings (defined or not).

  @array = grep $_ ne $val, @array;

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 13 Sep 2001 20:05:31 GMT
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: deleting items from array - better way?
Message-Id: <slrn9q24cb.f75.trammell@haqq.hypersloth.net>

On Thu, 13 Sep 2001 14:56:26 -0500, Daniel Berger <djberge@qwest.com> wrote:
> Hi all,
> 
> I want to delete all values from an array that match $val.  Note that I
> don't want to merely replace them with null strings (defined or not).  I dug
> around the "one-liners" section of TPJ, the cookbook and this newsgroup but
> didn't see one.

perldoc -f grep



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

Date: 13 Sep 2001 16:17:31 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: deleting items from array - better way?
Message-Id: <m3y9nietgk.fsf@mumonkan.sunstarsys.com>

"Daniel Berger" <djberge@qwest.com> writes:

> Hi all,
> 
> I want to delete all values from an array that match $val.  Note that I
> don't want to merely replace them with null strings (defined or not).  I dug
> around the "one-liners" section of TPJ, the cookbook and this newsgroup but
> didn't see one.
> 
> e.g. Get rid of all values that match "one".
> my @array = qw(one two three one one);
> my $val = 'one';
> # Begin 2 liner
> my $n = 0;
> map{ if($_ =~ /$val/){ splice(@array,$n,1); $n--; } } @array;
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I doubt that does what you want- in fact I think it looks like

  @array = qw/two one/;

when you are done.

Here's some one-liners that should work:

  # mostly matching values
  @array = grep !/$val/, @array;

  # mostly non-matching values
  $array[$_] =~ /$val/ and splice @array, $_, 1 for reverse 0..$#array;

-- 
Joe Schaefer    "Few things are harder to put up with than the annoyance of a
                                        good example."
                                               --Mark Twain



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

Date: Thu, 13 Sep 2001 19:00:54 GMT
From: Mark Mynsted <mmynsted@prodigy.net>
Subject: Re: File name to process from standard input?
Message-Id: <m2r8taudc4.fsf@mmynsted.corp.vha.com>

tadmc@augustmail.com (Tad McClellan) writes:

> Mark Mynsted <mmynsted@prodigy.net> wrote:
> >
> >Why won't the following work?  It does nothing...
> >
> >find . -name '*.[jJ][sS][pP]' -print0 | xargs -r -0 perl -ip -e
>                                                           ^^^
> 
> -i takes an argument. You gave it a one character (p) argument.
> 
> Do you have some *.jspp files around now?
> 
> Use "-pi " instead if you want no backups made.
> 
> 
> >'s!\</?font.*?\>!!ig' 
>     ^          ^
>     ^          ^ useless use of backslashes, angle brackets aren't meta
> 
> 
> >I would think that would work fine 
> 
> 
> Attempting to process HTML with regular expressions is doomed to failure.
> 
>    <font
> >
> 
> is legal HTML that will break your code, since you are reading
> line-by-line.
> 
> There are a few dozen other gotchas to work out too. "perldoc -q HTML"
> shows several more of them.
> 
> 
> 
> >The
> >perl command works fine if I tell it what file to process...
> 
> 
> Not the same perl command that you showed us. Maybe you got
> the order right that time?
> 
> 
> -- 
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas

Ok.  Thank you.

-- 
-MM
                                               /"\
(No un-solicited email please.)                \ /     ASCII Ribbon Campaign
See following url,                              X      Against HTML Mail
http://pages.prodigy.net/mmynsted/spamoff.htm  / \


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

Date: Thu, 13 Sep 2001 12:39:10 -0700
From: "kyi" <kyi@psnw.com>
Subject: file output
Message-Id: <tq22n7j4u2cl00@corp.supernews.com>

Hello Group;

    I have a small perl app that I wrote. It take a text file that is
captured from the serial port, named capture.txt. My app takes this
captured.txt file and prases all of the info I want in the file and produces
an output file that if formatted the way I want. My question is how can I
have this output file named to what ever the current system date is, like
(date +%x). Instead of the hard coded filename I have given it. Below is the
last few line of my app, where the file is being writen out.

open (OUTPUT_FILE, ">/home/Administrator/phonelogs/phonelog.txt");

while (<INPUT_FILE>) {
        if (m/09/) {s/^\s+//;
         print OUTPUT_FILE "$_";}

        }

print "\n\n\nPress <Enter> to continue...";


<STDIN>;

So how do I make the output file the current date in, date +%x, format?
Instead of my phonelog.txt.name.

Any help is greatly apperciated.

-Jayson Garrell
Fresno Linux User Group
http://linux.microbsys.com
lugadmin@microbsys.com





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

Date: Thu, 13 Sep 2001 15:58:32 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: file output
Message-Id: <3BA09158.6A7DF125@ce.gatech.edu>

kyi wrote:
> 
> Hello Group;
> 
>     I have a small perl app that I wrote. It take a text file that is
> captured from the serial port, named capture.txt. My app takes this
> captured.txt file and prases all of the info I want in the file and produces
> an output file that if formatted the way I want. My question is how can I
> have this output file named to what ever the current system date is, like

perldoc -f localtime

-- 
robert sherman
css, cee
georgia institute of technology
atlanta, ga, usa


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

Date: Thu, 13 Sep 2001 19:01:06 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Help on Perl parsing file to locate and replace Include files in CGI app
Message-Id: <Sn7o7.375$Owe.256333824@news.frii.net>

In article <e836199f.0109130824.43745dd4@posting.google.com>,
Jennifer <jennlee.2@eudoramail.com> wrote:
>Hi all,
>
>I know that if I just output the HTML from the template files, the
>server will not parse for SSI and so the pages aren't working.
>

There are some modules on CPAN that allow you to process SSI tags from CGI
applications.  CGI::SSI and Apache::SSI are possible options for you.

You might also consider talking over the use of style sheets with the web
designer and going to something like Text::Template or Mason that can
allow both you and the web designer to collaborate more usefully.

As a third option you might consider "inverting" your model and use the SSI
exec tag to call out to perl code that returns the computed fragment of the
page.

As always TIMTOWTDI
chris
-- 
    This space intentionally left blank


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

Date: Thu, 13 Sep 2001 20:12:50 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: How to preallocate memory for my perl script (UNIX)
Message-Id: <6r8o7.382$Owe.252165632@news.frii.net>

In article <slrn9q1ckj.eec.tadmc@tadmc26.august.net>, Tad McClellan
<tadmc@augustmail.com> wrote:
>Stan Brown <stanb@panix.com> wrote:
>>
>>I beleive that a part of this is because perl has to make many small
>>requests to the OS for emeory, the first time. So I would like to do
>>something, before the first fetch to get perl to request a large chunk of
>>memory from the OS, the undefine whatever is using this memeory, thus
>>making that memory available to perl for reuse.
>>
>>Sugestions?
>
>
>You can preallocate memory:
>
>   my @array;
>   $#array = 1_000_000;  # a million elements
>or
>   my %hash;
>   keys %hash = 1_000_000;  # a million buckets (perldata.pod)
>

While there are often good reasons for holding a large dataset in
memory. There are often alternatives that can use much less memory.
For example processing one row at a time using the DBI::fetchrow_* methods 
rather than loading the whole result using the DBI::fetchall_* into memory just to walk it and then throw it away.

YMMV
chris
-- 
    This space intentionally left blank


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

Date: Thu, 13 Sep 2001 21:16:16 +0200
From: "Herve Schlecht" <herve.schlecht@wanadoo.fr>
Subject: http server validation
Message-Id: <9nr0gh$fiq$1@wanadoo.fr>

I search a solution to validate remotly that a http server is alive.

Thanks for your help

Herve




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

Date: Thu, 13 Sep 2001 19:20:55 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: http server validation
Message-Id: <rG7o7.377$Owe.256334848@news.frii.net>

In article <9nr0gh$fiq$1@wanadoo.fr>,
Herve Schlecht <herve.schlecht@wanadoo.fr> wrote:
>I search a solution to validate remotly that a http server is alive.
>
>Thanks for your help
>
>Herve
>
>

perl -MLWP::Simple -le 'print head "http://www.cpan.org"'
-- 
    This space intentionally left blank


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

Date: 13 Sep 2001 15:36:32 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: http server validation
Message-Id: <m33d5qg9xb.fsf@mumonkan.sunstarsys.com>

"Herve Schlecht" <herve.schlecht@wanadoo.fr> writes:

> I search a solution to validate remotly that a http server is alive.

  % perldoc `which HEAD`
  % HEAD my.http.server

> Thanks for your help

Be sure LWP is installed.

-- 
Joe Schaefer         "Experience is one thing you can't get for nothing."
                                               -- Oscar Wilde



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

Date: Thu, 13 Sep 2001 15:56:06 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: http server validation
Message-Id: <comdog-F52A6E.15560613092001@news.panix.com>

In article <rG7o7.377$Owe.256334848@news.frii.net>, 
cfedde@fedde.littleton.co.us (Chris Fedde) wrote:

> In article <9nr0gh$fiq$1@wanadoo.fr>,
> Herve Schlecht <herve.schlecht@wanadoo.fr> wrote:

> >I search a solution to validate remotly that a http server is alive.

> perl -MLWP::Simple -le 'print head "http://www.cpan.org"'

you don't need to print the response since head() in
scalar context tells you if it were successful or not.

perl -MLWP::Simple -le 'print "Alive!" if head "http://www.cpan.org"'

however, this can only tell you that the server is alive.  you
have to work harder to check if the server is not alive since
some servers do not handle HEAD correctly. ;)

-- 
brian d foy <comdog@panix.com> - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html



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

Date: Thu, 13 Sep 2001 15:52:46 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: http server validation
Message-Id: <comdog-08DBE6.15524613092001@news.panix.com>

In article <m33d5qg9xb.fsf@mumonkan.sunstarsys.com>, Joe Schaefer 
<joe+usenet@sunstarsys.com> wrote:

> "Herve Schlecht" <herve.schlecht@wanadoo.fr> writes:
> 
> > I search a solution to validate remotly that a http server is alive.
> 
>   % perldoc `which HEAD`
>   % HEAD my.http.server

this won't necessarily work since some servers do not
respond properly to a HEAD request.  if HEAD indicates that
the server is not running, then you have to try GET.

furthermore, even if the request fails you still get output
with HEAD.  you need to check the return value which indicates
the number of URLs that failed.

-- 
brian d foy <comdog@panix.com> - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html



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

Date: 13 Sep 2001 12:00:42 -0700
From: Lyle_Goldman@ibi.com (Lyle Goldman)
Subject: Interrupted Server Socket Connections
Message-Id: <ed639144.0109131100.3f63899e@posting.google.com>

-
	Hello. I am trying to write a client-server system using sockets. In the
code that I have written, the client reads lines of text from standard input and
sends them to the server, which prints the lines to standard output. Under
normal situations, it work fine. However, when I interrupt the server process,
the client does not realize that the server has disconnected until it sends
two (not one, but two!) more lines of output. Why is this happening, and how
can I detect when the connection has closed sooner?

	The code follows. I am running under Solaris 5.6. Thank you for any help
you can provide me.


Here is the server code (testserver.pl):

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

use sigtrap;
use Socket;

$SIG{PIPE} = sub { die "Broken Pipe.\n"; };

$| = 1;

my $port = $ARGV[0] || 2345;
socket SERVER, PF_INET, SOCK_STREAM, getprotobyname 'tcp' or die "socket: $!";
setsockopt SERVER, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)
	or die "setsockopt: $!";
bind SERVER, sockaddr_in($port, INADDR_ANY) or die "bind: $!";
listen SERVER, SOMAXCONN or die "listen: $!";

my $paddr;
while($paddr = accept CLIENT, SERVER) {
	my ($port, $iaddr) = sockaddr_in $paddr;
	my $name = gethostbyaddr $iaddr, AF_INET;

	while(<CLIENT>) {
		print;
	};

	close CLIENT;
};

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

Here is the client code (testclient.pl):

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

use sigtrap;
use Socket;

my ($remote, $port, $iaddr, $paddr);

$SIG{PIPE} = sub { die "Broken Pipe.\n"; };

$remote = shift || 'localhost';
$port = shift || 2345;  # random port
$port =~ /\D/ and $port = getservbyname $port, 'tcp';
die "No port" unless $port;
$iaddr = inet_aton($remote) or die "No host: $remote";
$paddr = sockaddr_in($port, $iaddr);

socket SOCKET, PF_INET, SOCK_STREAM, getprotobyname 'tcp' or die "socket: $!";
connect SOCKET, $paddr or die "connect: $!";
select SOCKET;
$| = 1;
select STDOUT;

while(<STDIN>) {
	print SOCKET or die "print: $!";
}

close SOCKET or die "close: $!";

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

						- Lyle Goldman


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

Date: Wed, 12 Sep 2001 19:45:26 +0100
From: "Ben Ralph" <ben@ralph.demon.co.uk>
Subject: Microsoft ACL
Message-Id: <1000406317.22566.0.nnrp-07.c2de4ac6@news.demon.co.uk>

Is it possible to edit ACLs with Perl?  If so any example scripts would be
appreciated.

Cheers
Ben




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

Date: 13 Sep 2001 14:45:51 -0700
From: zoaraster@mailcity.com (kramer)
Subject: mod_perl or PHP for database drive site?
Message-Id: <9e811fcc.0109131345.2f40a281@posting.google.com>

I am creating a high traffic MySQL based database site (kind of like
one of those dating sites but different).  Anyway which is better PHP
or mod_perl in terms of speed, stability, and development time.

thanks...
kramer


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

Date: Thu, 13 Sep 2001 21:12:01 +0200
From: Philip Newton <pne-news-20010913@newton.digitalspace.net>
Subject: Re: O Reilly online books
Message-Id: <7612qtci6nael2dukdhr8q654jb39taaqm@4ax.com>

On 12 Sep 2001 15:50:12 -0700, merlyn@stonehenge.com (Randal L.
Schwartz) wrote:

> If you want HTML files, you can get access to them legitimately at
> http://safari.oreilly.com for an appropriate fee.

Or, for some titles, buy a CD-ROM such as the Perl CD Bookshelf.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Thu, 13 Sep 2001 15:15:49 -0400
From: Bernard Cosell <bernie@fantasyfarm.com>
Subject: printing from an IO handle _to_ an IO handle
Message-Id: <dd12qtspocb1nvaovkl97d6ohfghao1rmc@4ax.com>

I was wondering why I get a syntax error in this:

===========================
use IO::File;

my $s = new IO::File('/dev/null') or die "No file!" ;
my $t = new IO::File('>/dev/null') or die "No file!" ;
print $t <$s> ;
============================
syntax error near "$s>"

This with perl 5.004.  It apparently has to do with having *two* IO
handles in the print statement --- either print $t ARRAY or print
HANDLE <$s> both work, but I can't do the IOhandle->IOhandle copy in
one step this way, as far as I can figure...

  /Bernie\
-- 
Bernie Cosell                        mailto:bernie@rev.net
Roanoke Electronic Village


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

Date: Thu, 13 Sep 2001 19:26:47 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: printing from an IO handle _to_ an IO handle
Message-Id: <XL7o7.378$Owe.259242496@news.frii.net>

In article <dd12qtspocb1nvaovkl97d6ohfghao1rmc@4ax.com>,
Bernard Cosell  <bernie@fantasyfarm.com> wrote:
>I was wondering why I get a syntax error in this:
>
>===========================
>use IO::File;
>
>my $s = new IO::File('/dev/null') or die "No file!" ;
>my $t = new IO::File('>/dev/null') or die "No file!" ;
>print $t <$s> ;
>============================
>syntax error near "$s>"
>

Indirect object notation is confusing the DWIMer in perl.
Try

    $t->print(<$s>);

>This with perl 5.004.  It apparently has to do with having *two* IO

You should consider upgrading your perl to 5.6.1.

-- 
    This space intentionally left blank


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

Date: 13 Sep 2001 12:58:32 -0700
From: katan8472@yahoo.com (katan8472)
Subject: Running perl scripts
Message-Id: <6e2513f5.0109131158.316c5caa@posting.google.com>

This is a stupid question, I am quite sure.
Say I just wrote up a perl script, hello.pl. From my unix shell
interface, how do I run the script? I've searched all over the
internet for an answer to this seemingly simple question, I just can't
seem to figure it out.

The best I can seem to do is to type perl, hit enter, paste the
script, hit control-d and then it works. Obviously, there has got to
be run a saved perl script, right?

So, I'm in my home directory where the file is saved.
I type:
%hello.pl
I get the responce:
hello.pl: Command not found.

I saw somewhere that you have to chmod +x it, but that didn't help at
all.
What haven't I done?

Please flame me if it will make your day any better.

Katan8472


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

Date: Thu, 13 Sep 2001 13:08:16 -0700
From: "kyi" <kyi@psnw.com>
Subject: Re: Running perl scripts
Message-Id: <tq24dpmbuva72f@corp.supernews.com>

Yes you need to 'chmod +x hello.pl' and then from the directory where the
hello.pl is located do a './hello.pl' or 'perl hello.pl' (w/out quotes).

-Jayson Garrell

"katan8472" <katan8472@yahoo.com> wrote in message
news:6e2513f5.0109131158.316c5caa@posting.google.com...
> This is a stupid question, I am quite sure.
> Say I just wrote up a perl script, hello.pl. From my unix shell
> interface, how do I run the script? I've searched all over the
> internet for an answer to this seemingly simple question, I just can't
> seem to figure it out.
>
> The best I can seem to do is to type perl, hit enter, paste the
> script, hit control-d and then it works. Obviously, there has got to
> be run a saved perl script, right?
>
> So, I'm in my home directory where the file is saved.
> I type:
> %hello.pl
> I get the responce:
> hello.pl: Command not found.
>
> I saw somewhere that you have to chmod +x it, but that didn't help at
> all.
> What haven't I done?
>
> Please flame me if it will make your day any better.
>
> Katan8472




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

Date: Thu, 13 Sep 2001 16:31:30 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Running perl scripts
Message-Id: <3BA125B2.A69695F@home.com>

katan8472 wrote:
> 
> This is a stupid question, I am quite sure.

It's a novice question. It's also a *nix question, not a Perl one. We'll
let the off-topicness slide this time. :)

> Say I just wrote up a perl script, hello.pl. From my unix shell
> interface, how do I run the script?
> [...] 
> The best I can seem to do is to type perl, hit enter, paste the
> script, hit control-d and then it works. Obviously, there has got to
> be run a saved perl script, right?

Of course. :)
 
> So, I'm in my home directory where the file is saved.
> I type:
> %hello.pl
> I get the responce:
> hello.pl: Command not found.

That's a response from your shell. It means that the program 'hello.pl'
was not found in your path. The current directory '.' is usually not in
your path by default because it's a potential security problem. You can
do one of three things:

  1) run scripts by passing them to perl:
     % perl hello.pl
  2) Specify the path to the script:
     % ./hello.pl
  3) Add '.' to your path:
     % hello.pl

If you do (3), make sure to make '.' the *last* thing in your path.
 
> I saw somewhere that you have to chmod +x it, but that didn't help at
> all.

It did help, if you want to be able to run the script without passing it
to perl as in (1). You just haven't gotten to the part where it matters
yet.

> Please flame me if it will make your day any better.

Not particularly.

-mjc


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

Date: Thu, 13 Sep 2001 19:39:55 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: scalar global search
Message-Id: <1000409995.188523745164275.gnarinn@hotmail.com>

In article <3ba09896$1@e-post.inode.at>,
peter pilsl  <pilsl_@goldfisch.at> wrote:
>
>Can anyone point me in deeper information about the g-option for the m//-op.
>I use m//g in scalar context very frequently, but dont know which factors 
>influence the internal counter for this 'incremental' search. Is this 
>counter bound to the current namespace or maybe to the search variable.
>In the latter case I would be able to do m//g parallel on different strings.

(snip)

>While this example works fine here, I'd like to know more and for sure, 

the search position is bound to the variable, and can be read/written
by the function pos(), and is reset by setting the variable

>cause I write mod_perl scripts and always have the paranoia that different 
>tasks access the same namespace ..

hold on. if you are talking about 2 simultaneous requests (2 different
tasks), then you do not have to worry, as they do not share memory.
if you are talking about successive requests, then you should never rely
on state beeing kept between requests.

>
>perlop and perlre didnt give me the info what I need, but maybe I'm just 
>thinking the wrong way.

perlop seemed clear to me

gnari


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

Date: Thu, 13 Sep 2001 19:51:51 GMT
From: "Mark Riehl" <mark.riehl@agilecommunications.com>
Subject: Server & shutdown calls
Message-Id: <r78o7.84$Cn4.131528@typhoon1.gnilink.net>

All - I'm trying to write a client and a server.  The client will be sending
an XML file to the server, and to indicate that it is finished, I wanted to
call shutdown (1) on the socket.  From the client's point of view, the
socket is closed for writing, but open for writing.

I'm using a sample server from the Perl Cookbook as a starting point.  My
problem is that the server can't seem to distinguish between a full close,
and a half close using shutdown (in the unless statement shown below).

Questions -
1. If I call shutdown from the client, will select return the socket as
being valid?
2. If I call shutdown (1) from my client, I assumed that the socket should
still be valid ($rv), however, there won't be any data to read.  If that's
the case, then I shouldn't fall into the unless{} block, correct?

Thanks,
Mark


####################################################################
Here's a snippet of the code I'm trying to use (O removed some extraneous
code).
while (1) {
    # can_read() returns an array of handles that are ready for reading.
    foreach $client ($select->can_read(1)) {

        if ($client == $server) {
            # Accept a new connection
            $client = $server->accept();
            $select->add($client);
        }
        else {
            # Data is waiting on one of the sockets, read the data
            $data = '';
            $rv = $client->recv($data, POSIX::BUFSIZ, 0);

            unless (defined($rv) && length ($data)) {
                # closing the socket
                print "\nReceived a full close\n";
                $select->remove($client);
                close $client;
                next;
              }
        }
    }
}





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

Date: Thu, 13 Sep 2001 21:12:04 +0200
From: Philip Newton <pne-news-20010913@newton.digitalspace.net>
Subject: Re: Warning on adding hash element
Message-Id: <kv02qt8pnpl2p3fm20su584qk4unpssg78@4ax.com>

On 12 Sep 2001 04:59:09 -0700, soosterh@my-deja.com (so) wrote:

> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<9nl1g9$74b$1@mamenchi.zrz.TU-Berlin.DE>...
> [first part snipped]
> > According to so <soosterh@my-deja.com>:
> > > What I was actually doing was this...
> > > $sInfo->{ '-script' } = {-language=>'javascript',-src=>'/macros_so.js' };

This looks as if $sInfo is a hashref.

> > > print start_html( $sInfo ), "\n";
> > > 
> Actually all I did was modify an example from the CGI page:
> 
>       print $q->start_html(-title=>'The Riddle of the Sphinx',
> 			   -script=>{-language=>'JavaScript',
>                                    -src=>'/javascript/sphinx.js'}
>                               );

And here the example passes an unrolled hash, not a hashref. The
equivalent in your case would be

    print start_html( %$sInfo );

and not

    print start_html( $sInfo );

So you can't really compare the example code with your code, since they
do different things.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

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


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