[11395] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4998 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 26 16:17:48 1999

Date: Fri, 26 Feb 99 13:16:01 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 26 Feb 1999     Volume: 8 Number: 4998

Today's topics:
        removing duplicate items from an array... <jaybyrd@macs.net>
    Re: removing duplicate items from an array... <smiles@wfubmc.edu>
    Re: removing duplicate items from an array... <jdf@pobox.com>
    Re: removing duplicate items from an array... (Ronald J Kimball)
    Re: removing duplicate items from an array... (Larry Rosler)
    Re: removing duplicate items from an array... dturley@pobox.com
    Re: removing duplicate items from an array... (Tad McClellan)
    Re: removing duplicate items from an array... (Larry Rosler)
        Require file error -> did not return a true value <jalil@corp.home.net>
    Re: Require file error -> did not return a true value <gsx97@usa.net>
    Re: Require file error -> did not return a true value <rick.delaney@home.com>
    Re: Returning file tests under Win95 and WinNT <disco181@my-dejanews.com>
    Re: Returning file tests under Win95 and WinNT <Allan@due.net>
    Re: Returning file tests under Win95 and WinNT <disco181@my-dejanews.com>
        Runing a perl script on one WEB Server and Writing a fi <cm_morgado@hotmail.com>
        running commands on a remote host <michaelr@lndn.tensor.pgs.com>
    Re: running commands on a remote host <Tony.Curtis+usenet@vcpc.univie.ac.at>
    Re: running commands on a remote host <wmwilson1@go.com>
        Script Security with Crontab <mwatkins@promotion4free.com>
    Re: Script Security with Crontab (I R A Aggie)
    Re: Script Security with Crontab <Arnold_Mueller@csi.com>
    Re: Search engine <kjcox@vii.com>
        searching a database <noll@caesar.elte.hu>
        Serial port comm with perl? <jjacobs@securetty.org>
    Re: Serial port comm with perl? <root@redbox.caroline.net>
        SETUID Script & Permissions. <ccyr@home.com>
        simple way to alter html head <harrys@slip.net>
    Re: simple way to alter html head <jdf@pobox.com>
        Socket strangeness with Perl code <darreld@his.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Thu, 25 Feb 1999 21:26:36 -0500
From: "Bill Chase" <jaybyrd@macs.net>
Subject: removing duplicate items from an array...
Message-Id: <7b50p8$do7$1@news0-alterdial.uu.net>

What is the easiest way to remove duplicate items from an array. I can find
virtually nothing on this subject. Its probably called something else which
would explain why I can't seem to find anything on it.

TIA
-Bill


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

Date: Wed, 24 Feb 1999 22:39:39 -0500
From: Steve Miles <smiles@wfubmc.edu>
Subject: Re: removing duplicate items from an array...
Message-Id: <36D4C5FA.824B277C@wfubmc.edu>

I had a similar question, sorting and counting unique IPs from an array - thus
removing duplicate entries.
The best solution was to push each of the array variables into a hash key, a
hash never has duplicate keys, so in doing so you remove the duplicate items:

foreach $item (@array) {
    $hash{$item};
}

then if you want to have an array of the unique items:

foreach $key (keys %hash) {
    push (@newlist, $key);
}

@newlist will contain no duplicates.

Steve

=============================================
Steve Miles (smiles@wfubmc.edu)
Wake Forest University School of Medicine
5019 Hanes, Medical Center Blvd.
Winston-Salem, NC 27157
Phone: 336.716.0454     FAX: 336.716.7200
=============================================

Bill Chase wrote:

> What is the easiest way to remove duplicate items from an array. I can find
> virtually nothing on this subject. Its probably called something else which
> would explain why I can't seem to find anything on it.
>
> TIA
> -Bill







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

Date: 25 Feb 1999 23:08:22 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: "Bill Chase" <jaybyrd@macs.net>
Subject: Re: removing duplicate items from an array...
Message-Id: <m3ww15st6x.fsf@joshua.panix.com>

"Bill Chase" <jaybyrd@macs.net> writes:

> What is the easiest way to remove duplicate items from an array. I
> can find virtually nothing on this subject.

perlfaq4, "How can I extract just the unique elements of an array?"

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: Thu, 25 Feb 1999 23:35:01 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: removing duplicate items from an array...
Message-Id: <1dnt2o9.30c46vlnlkoeN@bay2-368.quincy.ziplink.net>

Bill Chase <jaybyrd@macs.net> wrote:

> What is the easiest way to remove duplicate items from an array. I can find
> virtually nothing on this subject. Its probably called something else which
> would explain why I can't seem to find anything on it.

Hint: If you extract the duplicate items, what are you left with?
The _unique_ items...

Take look at perlfaq4 with that in mind.

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Thu, 25 Feb 1999 21:27:11 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: removing duplicate items from an array...
Message-Id: <MPG.113fd088e435ddb798968f@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7b50p8$do7$1@news0-alterdial.uu.net>, on Thu, 25 Feb 1999 
21:26:36 -0500 jaybyrd@macs.net says...
> What is the easiest way to remove duplicate items from an array. I can find
> virtually nothing on this subject. Its probably called something else which
> would explain why I can't seem to find anything on it.

It is called 'unique'.  Perlfaq4:  "How can I extract just the unique 
elements of an array?"

-- 
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 26 Feb 1999 13:15:19 GMT
From: dturley@pobox.com
Subject: Re: removing duplicate items from an array...
Message-Id: <7b66p0$2ug$1@nnrp1.dejanews.com>

In article <7b50p8$do7$1@news0-alterdial.uu.net>,
  "Bill Chase" <jaybyrd@macs.net> wrote:
> What is the easiest way to remove duplicate items from an array. I can find
> virtually nothing on this subject.

Hmmm, it's in the FAQ. Perlfaq4
How can I extract just the unique elements of an array?

If you couldn't find it, you have a bad Perl installation since the FAQ is
installed onyour system along with Perl.

Seaching dejanews also turned up multiple refs to this FAQ. See your sys admin
about getting Perl properly installed.

--

____________________________________
David Turley

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 26 Feb 1999 02:08:50 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: removing duplicate items from an array...
Message-Id: <2ah5b7.qg4.ln@magna.metronet.com>

Steve Miles (smiles@wfubmc.edu) wrote:

: The best solution was to push each of the array variables into a hash key, a
: hash never has duplicate keys, so in doing so you remove the duplicate items:


: then if you want to have an array of the unique items:

: foreach $key (keys %hash) {
:     push (@newlist, $key);
: }


   Since push() takes a list, you don't need the temp variable
   and explicit loop:


          push (@newlist, keys %hash);


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Fri, 26 Feb 1999 07:07:11 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: removing duplicate items from an array...
Message-Id: <MPG.1140587482e7182989691@nntp.hpl.hp.com>

In article <36D4C5FA.824B277C@wfubmc.edu>, on Wed, 24 Feb 1999 22:39:39 
-0500 smiles@wfubmc.edu says...
> I had a similar question, sorting and counting unique IPs from an array - thus
> removing duplicate entries.
> The best solution was to push each of the array variables into a hash key, a
> hash never has duplicate keys, so in doing so you remove the duplicate items:
> 
> foreach $item (@array) {
>     $hash{$item};
> }

Unfortunately, this loop does nothing whatever except produce warnings 
from '-w' about 'Useless use of hash elem in void context at ...'  You 
must assign something (even 'undef') to a simple hash element to create 
it.

In the FAQ, this is shown *much* more effectively and efficiently as:

    @hash{@array} = ();

> then if you want to have an array of the unique items:
> 
> foreach $key (keys %hash) {
>     push (@newlist, $key);
> }
> 
> @newlist will contain no duplicates.
> 
> Steve

True.  It will contain nothing at all, hence no duplicates.  :-)

However, assuming %hash has been populated correctly...

In the FAQ, this is shown *much* more effectively and efficiently as:

    @newlist = sort keys %hash;  # remove sort if undesired

The FAQ also shows several other effective approaches, including how to 
preserve the input order if desired.  Go with the FAQ, Steve!

-- 
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 23 Feb 1999 02:11:39 GMT
From: "Jalil Feghhi" <jalil@corp.home.net>
Subject: Require file error -> did not return a true value
Message-Id: <919735899.327685@zeppelin.svr.home.net>

I am using require $file to load a perl file I have from another file. I
have a simple test function in this file I want to load and I keep getting
the above message when my file gets loaded. Is there anything else I need to
do to make it work?

Thanks,

-Jalil





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

Date: Tue, 23 Feb 1999 00:45:19 -0500
From: "J. Parsons" <gsx97@usa.net>
Subject: Re: Require file error -> did not return a true value
Message-Id: <7atf9u$rs6@news1.snet.net>

at the end of the file being required, type:

1;

that should give you a true value.

Good luck



Jalil Feghhi wrote in message <919735899.327685@zeppelin.svr.home.net>...
>I am using require $file to load a perl file I have from another file. I
>have a simple test function in this file I want to load and I keep getting
>the above message when my file gets loaded. Is there anything else I need
to
>do to make it work?
>
>Thanks,
>
>-Jalil
>
>
>




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

Date: Tue, 23 Feb 1999 02:42:54 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Require file error -> did not return a true value
Message-Id: <36D21796.B60075D0@home.com>

[posted & mailed]

Jalil Feghhi wrote:
> 
> I am using require $file to load a perl file I have from another file. 
> I have a simple test function in this file I want to load and I keep 
> getting the above message when my file gets loaded. Is there anything 
> else I need to do to make it work?

All perl errors are documented in perldiag.  If you search for this
error there it tells you exactly what to do.  Or let a module search for
you by putting

    use diagnostics;

in your script.

When you are confused about why a function is "not working", you can
look it up in perlfunc.  The answer is right there too.

perldoc -f require

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Tue, 23 Feb 1999 10:55:38 GMT
From: Disco <disco181@my-dejanews.com>
Subject: Re: Returning file tests under Win95 and WinNT
Message-Id: <7au1f7$1m6$1@nnrp1.dejanews.com>

In article <7akocu$53v$1@fir.prod.itd.earthlink.net>,
  "Ken Hirsch" <kenhirsch@myself.com> wrote:
>
> david.willingham@fernhart.com wrote
> >The code is as follows:
> >
> >my $news_dir = "C:/temp";
> >my $news="", $created="", $modified="", $accessed="";
> >my $cnt=0;
> >opendir (NEWS, $news_dir) || die "Cannot open $!";
> >while($news[$cnt] = readdir(NEWS)) {
> > open(NEWS);
> > $created = (-C $news[$cnt]);
> > $modified = (-M $news[$cnt]);
> > $accessed = (-A $news[$cnt]);
> > print("Filename:$news[$cnt], Created:$created, Modified:$modified,
> >Accessed:$accessed\n");
> > close(NEWS);
> > $cnt++;
> >}
> >closedir(NEWS);
> >
> >Is the problem with my coding or is it environment specific? Can anyone
> >suggest a way forward?
>
> The problem is with your code.
> 1. take out "open(NEWS)" and "close(NEWS)".
> 2. read the manual entry on readdir again, specifically,
> "If you're planning to filetest the return values out of a readdir(), you'd
> better prepend the directory in question"
>
> or chdir()
>
> Ken Hirsch
> Carrboro, NC
>
>
Thanks, it now works a treat.

I don't suppose you'd know where I could find good, simple working examples of
code that are actually of some use i.e file copying, using modules. I've got
Learning Perl on Win32 Systems and Perl in a Nutshell by O'Reilly but both are
lacking in decent examples. I could do with code that I can tear apart to see
how it works.

Thanks again

DJW


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Tue, 23 Feb 1999 08:24:34 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: Returning file tests under Win95 and WinNT
Message-Id: <7au9q7$1tr$1@camel0.mindspring.com>

Disco wrote in message <7au1f7$1m6$1@nnrp1.dejanews.com>...
:In article <7akocu$53v$1@fir.prod.itd.earthlink.net>,
:  "Ken Hirsch" <kenhirsch@myself.com> wrote:
:>
:> david.willingham@fernhart.com wrote
:> >The code is as follows:


[snip code]


:Thanks, it now works a treat.
:
:I don't suppose you'd know where I could find good, simple working examples
of
:code that are actually of some use i.e file copying, using modules. I've
got
:Learning Perl on Win32 Systems and Perl in a Nutshell by O'Reilly but both
are
:lacking in decent examples. I could do with code that I can tear apart to
see
:how it works.


Check out the excellent O'reilly publication "Perl Cookbook" by Christiansen
& Torkington.  It is a must have.

HTH

AmD

--
$email{Allan M. Due} => 'Allan@Due.net';
--random quote --
If the automobile had followed the same development cycle as the
computer, a Rolls-Royce would today cost $100, get one million miles
to the gallon, and explode once a year, killing everyone inside.
  Robert X Cringely





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

Date: Tue, 23 Feb 1999 17:22:09 GMT
From: Disco <disco181@my-dejanews.com>
Subject: Re: Returning file tests under Win95 and WinNT
Message-Id: <7auo3p$l26$1@nnrp1.dejanews.com>

In article <7au9q7$1tr$1@camel0.mindspring.com>,
  "Allan M. Due" <Allan@due.net> wrote:
> Disco wrote in message <7au1f7$1m6$1@nnrp1.dejanews.com>...
> :In article <7akocu$53v$1@fir.prod.itd.earthlink.net>,
> :  "Ken Hirsch" <kenhirsch@myself.com> wrote:
> :>
> :> david.willingham@fernhart.com wrote
> :> >The code is as follows:
>
> [snip code]
>
> :Thanks, it now works a treat.
> :
> :I don't suppose you'd know where I could find good, simple working examples
> of
> :code that are actually of some use i.e file copying, using modules. I've
> got
> :Learning Perl on Win32 Systems and Perl in a Nutshell by O'Reilly but both
> are
> :lacking in decent examples. I could do with code that I can tear apart to
> see
> :how it works.
>
> Check out the excellent O'reilly publication "Perl Cookbook" by Christiansen
> & Torkington.  It is a must have.
>
> HTH
>
> AmD
>
> --
> $email{Allan M. Due} => 'Allan@Due.net';
> --random quote --
> If the automobile had followed the same development cycle as the
> computer, a Rolls-Royce would today cost $100, get one million miles
> to the gallon, and explode once a year, killing everyone inside.
>   Robert X Cringely
>
>
Like the quote, it sounds about right, but shouldn't the Rolls prompt you with
"I'm about to explode", "OK" before exploding?

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Thu, 25 Feb 1999 16:00:55 -0000
From: "Cristovao Morgado" <cm_morgado@hotmail.com>
Subject: Runing a perl script on one WEB Server and Writing a file on another Web Server ??
Message-Id: <7b3s20$gn6$1@duke.telepac.pt>

Is it possible to execute a perl script on a web server A and to write the
results of the script on a file on web server B , instead of writing it on
the same server where the script was executed ??

Thx A lot
Bye Bye
Cris.




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

Date: Thu, 25 Feb 1999 17:31:19 +0000
From: Michael Renshaw <michaelr@lndn.tensor.pgs.com>
Subject: running commands on a remote host
Message-Id: <36D588E7.3703@lndn.tensor.pgs.com>

can anyone think of a neater way to emulate running
a command remotely.....

system("rsh hostname prog arg0 arg1");

on our local network.

I could use the expect module but that seems like
overkill.

thanx

Mike


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

Date: 25 Feb 1999 20:03:14 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: running commands on a remote host
Message-Id: <837lt6b91p.fsf@vcpc.univie.ac.at>

Re: running commands on a remote host, Michael
<michaelr@lndn.tensor.pgs.com> said:

Michael> can anyone think of a neater way to emulate
Michael> running a command remotely.....

Michael> system("rsh hostname prog arg0 arg1");

Michael> on our local network.

A maybe-heavy solution that doesn't rely on the r*
commands is to implement your own server/client.
For a little bit of effort initially, you get a nice
way of doing remote execution.

You can do the client side with a Net::Cmd, or even
you might consider using a minimal HTTP server with
LWP for the client.

This separates out access rights for these
applications from other r* considerations.

You can then separately do access control with
e.g. tcp_wrappers on known ports and services.

Anohter way that just popped into my head is to use
java's RMI and exec() out of the Runtime.

TMTOWTDI.

hth
tony
-- 
Tony Curtis, Systems Manager, VCPC,    | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien.  | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds!  | private email:
    Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>


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

Date: Thu, 25 Feb 1999 20:10:29 GMT
From: Mike Wilson <wmwilson1@go.com>
Subject: Re: running commands on a remote host
Message-Id: <7b4anb$fhg$1@nnrp1.dejanews.com>

In article <36D588E7.3703@lndn.tensor.pgs.com>,
  Michael Renshaw <michaelr@lndn.tensor.pgs.com> wrote:
> can anyone think of a neater way to emulate running
> a command remotely.....
>
> system("rsh hostname prog arg0 arg1");
>
> on our local network.
>
> I could use the expect module but that seems like
> overkill.
>
> thanx
>
> Mike

  I probably speak for everyone when I say, more information would be nice,
for instance, how many times are you going to rsh to the machine?  If you're
only doing it a few times, then I personally think there's nothing at all
wrong with doing it with a system call (Perl, after all, is a "glue"
language, or at least that's how it's often used, you have to expect that). 
On the other hand, if you're doing a system call several times you can say
$mycall = system("...."); and then to make the system call again (without the
overhead), simply say $mycall.	I would suggest you look at the perlsec
manpage for starters and check out the list form of system.  There of course
is also the qx// operator that may do you some good, but all in all, it's the
same answer to the same question.

>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 24 Feb 1999 14:30:29 -0000
From: "Mike Watkins" <mwatkins@promotion4free.com>
Subject: Script Security with Crontab
Message-Id: <eAlk8JAY#GA.290@nih2naae.prod2.compuserve.com>

Hi there,

I was just wondering, is there anyway in perl to tell if Crontab is running
the script or not?  So if Crontab isn't running the script, the script can
give off an error.

Thanks alot,
Mike





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

Date: 24 Feb 1999 16:05:21 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Script Security with Crontab
Message-Id: <slrn7d88ur.9t5.fl_aggie@enso.coaps.fsu.edu>

On Wed, 24 Feb 1999 14:30:29 -0000, Mike Watkins
<mwatkins@promotion4free.com> wrote:

+ I was just wondering, is there anyway in perl to tell if Crontab is running
+ the script or not?  So if Crontab isn't running the script, the script can
+ give off an error.

Why is that a problem? cron (1) reports STDERR (and STDOUT?? I don't
know for sure, but I think it will) to the account submitting the
program to the crontab via email. You may also handle STDOUT/STDERR in
your crontab submission:

0 * * * * accesswatch.pl > /dev/null 2>&1

This throws away STDOUT/STDERR by redirecting it into /dev/null, but
it could just as easily be sent to a file.

James


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

Date: Wed, 24 Feb 1999 17:15:18 +0100
From: "Arnold M|ller" <Arnold_Mueller@csi.com>
Subject: Re: Script Security with Crontab
Message-Id: <ucxM5BBY#GA.348@nih2naac.prod2.compuserve.com>

Hmm. seems like you're not the only one worrying about crontab...
Perhaps your script checks each time when it was run the last time. Then you
do some day-and-time calculations and see whether everything worked fine or
not...

On the other hand: this solution looks ugly :)))

Arnold M|ller

Mike Watkins wrote in message ...
>Hi there,
>
>I was just wondering, is there anyway in perl to tell if Crontab is running
>the script or not?  So if Crontab isn't running the script, the script can
>give off an error.
>
>Thanks alot,
>Mike
>
>
>




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

Date: Mon, 22 Feb 1999 15:50:13 +0000
From: "Kerry J. Cox" <kjcox@vii.com>
To: Adam Rudnick <arudnick@inet.net>
Subject: Re: Search engine
Message-Id: <36D17CB5.F9C1BBE4@vii.com>

Adam,
Thanks for the info.  I am very familiar with Selenea Sol's scripts, but I was
hoping to find somethng that would not require a cgi-bin.  Rather a simple
script that would sit on the CD-ROM and would run independantly of the user's
computer or an alternative site's cgi-bin.
Thanks again.
KJ

--
 .-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-.
| Kerry J. Cox          Vyzynz International Inc.       |
| kjcox@vii.com         Systems Administrator           |
| (801) 596-7795        http://vii.com                  |
| All Things Linux      http://quasi.vii.com/linux/     |
`-------------------------------------------------------'






Adam Rudnick wrote:

> Go to http://www.extropia.com/download.html
> In the form, where it asks you what application you want, choose SiteSearch
> on the pulldown menu.
>
> Kerry J. Cox wrote in message <36CDC19C.32584377@vii.com>...
> >Just wondering if anyone could point me to a nice Perl script that
> >searches out words or keywords





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

Date: Mon, 22 Feb 1999 15:52:15 +0100
From: "NOLL Krisztian" <noll@caesar.elte.hu>
Subject: searching a database
Message-Id: <7arqqp$bor$1@goliat.eik.bme.hu>

Hi!

My name is Krisztian, I am writing from Hungary.
Currently I am working on a cgi which searches more than one field in simple
flat text file. It works a little bit wrong, because it returns all the
records regarding that the related fields in the html page are filled or
not.
Does anyone help me how to skip the unfilled fields and search only for the
filled ones?

Thanx:

Krisztian




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

Date: Thu, 25 Feb 1999 07:05:45 +0000
From: Jay Jacobs <jjacobs@securetty.org>
Subject: Serial port comm with perl?
Message-Id: <36D4F649.C2677DA7@securetty.org>

I've been doing some looking around on using perl to communicate with
the serial port... not much luck.  I've found one example that just does
a simple:

$port = "/dev/cua1";
open("portfh","+<$port") || die "opening $port for input: $!";
system("stty 2400 -echo parodd parenb cs8 -cstopb raw < $port");
( reference: http://hamjudo.com/rcx/talkrcx.txt )

then uses syswrite/sysreads to communicate... haven't tested it... is it
really that simple?  I've done a lot of inet socket work, but nothing
with serial communications.  I'm trying to write an interface for X10
stuff in perl (I've found an app in C, but I'm not as strong in C).

Anyway, to make a long story short, What different methods are there for
working with the serial port? I'm working with linux on intel - probably
porting to sparc, and BSD, so I'd like to limit system calls... 

Thanks,
Jay Jacobs
jjacobs@securetty.org


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

Date: 25 Feb 1999 04:57:10 -0500
From: root <root@redbox.caroline.net>
Subject: Re: Serial port comm with perl?
Message-Id: <iucqdcw9.fsf@redbox.caroline.net>

Yes it's that easy.  Though I should ask what you are trying to
do... are you trying to communicate with a modem?  I think I just used 
a print, with a funky open command.  I'd give you the code, but the
system with the script on it is down.  I think you have to use the
"\r" escape character instead.  I wrote a script to make the
computer make phone calls and talk to people in no time at all, in
conjunction with festival. (NOT TELEMARKETING!, notification of server 
problems on the project I'm working on, so please no flames)

Good Luck,
Shane


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

Date: Thu, 25 Feb 1999 14:53:36 GMT
From: Colin Cyr <ccyr@home.com>
Subject: SETUID Script & Permissions.
Message-Id: <36D56439.EAB400AF@home.com>

Well, I have a slight dilemma...

I have a script that I need to have SETUID such that it can access all
of it's required dbm files etc.

I need to provide the user with a '~/.progrc' functionality so that
users can set some of their default preferences.

Seeing as the script is SETUID, it cannot see this preferences file
unless they make their home_dir and the file world readable (Or group,
but I doubt the script would every be grouped with them).

Is there a method around this?

There are other files the user might have permissions to but not the
account the script is setuid to.  I am currently dealing with this by
saying ohwell, set both the directory you want and the file you want
world readable, this can sometimes be unacceptable though.

Your help is greatly appreciated.

Oh, one last thing.

Is there any politically correct method to do ~ directory expansion
(I.e. Is guarenteed to work on UNIX's and those other unnamed OS's)?

I am currently doing the following (psuedo):
1. Starts with '~/' replace '~' with (getpwent($<))[7];
2. Starts with '~(.*?)/' replace '~(.*?)' with (getpwnam($1))[7] as long
as it is defined.

There are appropriate checks for user existence etc..

Thanks Again.


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

Date: Thu, 25 Feb 1999 16:18:15 -0800
From: Harry Slaughter <harrys@slip.net>
Subject: simple way to alter html head
Message-Id: <Pine.GSO.4.10.9902251610300.16136-100000@slip-3.slip.net>

goal: take any given html page, alter and/or remove and/or add tags to the
<HEAD> section, store this in one scalar and the body of the html (unaltered).
in a second scalar.

HTML::HeadParser easily gives me access to the headers, but it disregards
the body of the html. i don't want to have to parse the html twice (once
for head, again for body) if possible. 

i thought i'd check here before spending a lot of time hacking my own
version of HTML::Parser.

thanks a lot

harry





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

Date: 25 Feb 1999 23:04:29 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: Harry Slaughter <harrys@slip.net>
Subject: Re: simple way to alter html head
Message-Id: <m3zp61stde.fsf@joshua.panix.com>

Harry Slaughter <harrys@slip.net> writes:

> HTML::HeadParser easily gives me access to the headers, but it disregards
> the body of the html. i don't want to have to parse the html twice (once
> for head, again for body) if possible. 
> 
> i thought i'd check here before spending a lot of time hacking my own
> version of HTML::Parser.

The following little program should demonstrate that HTML::Parser
parses the head just fine.  Remember that HTML::HeadParser is just a
subclass of HTML::Parser.

    #!/usr/bin/perl -w
    BEGIN {
      package myparser;
      use base HTML::Parser;
      sub start {print "START: $_[1]\n"}
      sub text {print "TEXT: $_[1]\n"}
      sub end {print "END: $_[1]\n"}
    }
    package main;
    my $p = new myparser;
    { local $/; $p->parse(<DATA>) }
    __DATA__
    <html><head><title>test</title></head>
    <body><p>foo</p></body></html>

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: Thu, 25 Feb 1999 09:07:24 -0500
From: "Darrel Davis" <darreld@his.com>
Subject: Socket strangeness with Perl code
Message-Id: <36d558ac.0@news4.his.com>

I am working through some sample perl code and have modified
it to make it relevant to my usage.  I am trying to converse with a
server via a socket.  I send a string, the server does stuff and sends
me back another string.  THe client (Perl) reads it as two different
strings.

Here is the code:
use strict;
use IO::Socket;
my $host = shift || '12.4.33.141';
my $port = shift || 4271;
my $sock = new IO::Socket::INET(
                  PeerAddr => $host,
                  PeerPort => $port,
                  Proto    => 'tcp');
$sock or die "no socket :$!";
autoflush $sock;
# send message to server
print $sock "0000000058LOGIN     02000000001901darvvis000000001701loopy";
# print server response to STDOUT
my $bufr = '';
my $mRec;
$mRec =sysread( $sock, $bufr, 100);
print "Got a response from server: mRec = $mRec\n";
print "$bufr\n";
$mRec =sysread( $sock, $bufr, 100);
print "Got a response from server: mRec = $mRec\n";
print "$bufr\n";

This code sends the login string to the server. The server responds with:
Got a response from server:  mRec = 1
0
Got a response from server: mRec = 34
000000035ACK       01000000001301Y

This string leaves the server at once.  Code written in other languages
gets the string correct.  Why is perl reading 1 byte and then 34?

ANy help appreciated.
-darrel




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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 4998
**************************************

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