[18170] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 338 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 22 18:10:56 2001

Date: Thu, 22 Feb 2001 15:10:21 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <982883420-v10-i338@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 22 Feb 2001     Volume: 10 Number: 338

Today's topics:
    Re: Is this taint example correct? <ddunham@redwood.taos.com>
        newbi :starting a dialup conection  <jgross@montenaybay.com>
    Re: newbi :starting a dialup conection <Jonathan.L.Ericson@jpl.nasa.gov>
        Newbie needs help <sushil@www.rscregal.com>
    Re: processes monitoring (Charles DeRykus)
        Question.about s/// <snef@soneramail.nl>
    Re: Question.about s/// egwong@netcom.com
        Reading from __DATA__ <mitiaNOSPAM@northwestern.edu.invalid>
    Re: Reading from __DATA__ egwong@netcom.com
    Re: Reading from __DATA__ (Abigail)
    Re: Reading from __DATA__ <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: Remote Printer configuration: for (AIX, SUNOS lp, l <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: Ripping apart a scalar - Important! <mischief@velma.motion.net>
    Re: Ripping apart a scalar - Important! <c_clarkson@hotmail.com>
        Sessions in webaps with perl <wayne@penguinpowered.org.uk>
    Re: Sessions in webaps with perl <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: Specifying the length of regular expression (Greg Bacon)
        system() and cgi (erb)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 22 Feb 2001 20:42:43 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Is this taint example correct?
Message-Id: <7Rel6.41$aj6.45675@news.pacbell.net>

Michael Fuhr <mfuhr@dimensional.com> wrote:
> Argv[0] may be supplied from static text in script, but it isn't
> taint-clean if PATH could be applied to it and PATH isn't taint-clean.
> By adding the leading '/' you're precluding PATH from being applied,
> so the argument now passes the taint check.

But there is *no* difference between argv[0] and argv[1] to perl.
Neither of them will be used by it to launch anything directly.  Either
could be used in any capacity by the called program (and could be
affected by a bad PATH).

The difference was that perl cared about argv[0] and not argv[1].

> As I said, this is just a guess, but it does make sense if you
> understand what's going on.

Anyway, further tests reveal that it was much worse than what I
thought.  All tests that should be done on the pathname were simply done
on argv[0] instead...

% perl -wT -e 'system {"echo"} ("/Arg0", "Arg1", "Arg2")'
Arg1 Arg2

Note that although the called program (echo) depends on the path, taint
doesn't care.  It's busy checking argv[0] instead.

This is definitely a bug, and someone has now fixed it in a development
build.

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
      < Please move on, ...nothing to see here,  please disperse >


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

Date: Thu, 22 Feb 2001 15:36:16 -0600
From: "Jerry Gross" <jgross@montenaybay.com>
Subject: newbi :starting a dialup conection 
Message-Id: <3Afl6.4708$fk5.139735@e3500-chi1.usenetserver.com>

I have put together a script to send a SMTP email but I can't figure out how
to establish a dial up connenction.  If I start  windows dial-up networking
to make the connection the script work fine.  Any suggestions.

Thanks for the help

Jerry





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

Date: 22 Feb 2001 22:08:19 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: newbi :starting a dialup conection
Message-Id: <86itm2bcbw.fsf@jon_ericson.jpl.nasa.gov>

"Jerry Gross" <jgross@montenaybay.com> writes:

> Subject: newbi :starting a dialup conection
           ^^^^^ 
You mispelled "Please don't read this post".  (Many people score down
subjects with the word "newbie".)

> I have put together a script to send a SMTP email but I can't figure out how
> to establish a dial up connenction.  If I start  windows dial-up networking
> to make the connection the script work fine.  Any suggestions.

I assume that you are talking about MS Windows and that there is an
API to do this.  If so, http://search.cpan.org/search?dist=libwin32 or
http://search.cpan.org/search?dist=Win32-API is the answer.  (Note:
you too can use search.cpan.org.)

Jon


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

Date: Thu, 22 Feb 2001 17:53:51 -0800
From: sushil <sushil@www.rscregal.com>
Subject: Newbie needs help
Message-Id: <3A95C2AE.82ADCC70@www.rscregal.com>

O Knowledgeable Souls,

I am trying to get perl to work for me but alas in Vain, my attempt is
to be able to run a perl script that accepts input from the user via a
web page and depending on the name of the user will carry out file moves
on a unix box:

My test script works fine on its own when I run the script directly from
the console of the unix box (BSD) but when I try and run the same code
as a function, it does not respond with an error or a decent output, I
can tell its gone into the function but nothing more.

the code is:

sub file_move {
            $Config{'recipient'}="mememei";
            #print "cp /home/sushil
/www/cgi-bin/ma/formmail/aliases.txt";
            system "cp -f /home/dmog/aliases /www/cgi-bin/ma/formmail";


}

Any help will be highly appreciated.

Sushil



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: Thu, 22 Feb 2001 21:46:14 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: processes monitoring
Message-Id: <G96Ht3.9G2@news.boeing.com>

In article <x2%k6.8323$LE1.639188@news.uswest.net>,
Mitchell B. <hagertymitchell@[nospam]uswest.net> wrote:
>Hello,
>    I'm a novice programmer at best and  proud of this little perl
>program I wrote, but it needs to do some growing up. Its fairly simply
>really, grabs some info from a remote database, does some crunching,
>then puts it back and grabs another chuck to chew on.
>
>It needed to run continuously, so now its a daemon (thank you perl
>cookbook) which reads from a config,  starts (n) number of itself,
>starts and stops nice (sorta :) ).  This has added some problems which
>are a bit out of my reach.  It need to be much more ... something.  I'm
>not sure what to call it because its not more efficient but should get a
>lot more work done.
>
>What I would like it to do is start a daemon that monitors how much
>physical ram is available and keep it 90% full of processes. We are
>talking several hundred to several thousand depending on the size of the
>data coming in and the machine it is running on.
>
>Where to start isn't obvious to me referencing CPAN, the Camel book, and
>Cookbook. The processes need to talk to the daemon so then can be exited
>gracefully and not in the middle of crunching (process: should I
>continue or should i stop? daemon: continue)
>
>The question is: on a Solaris or FreeBSD box how would it monitor the
>physical memory and how would  it communicate with other processes so
>they continue/die gracefully?
>
>pointing towards a reference or example is fine, a starting point is
>what i need...
>
>thanks for your time
>mitch
>

A couple of modules and their families may be useful:

  http://search.cpan.org?dist=Proc-ProcessTable
  http://seach.cpan.org?dist=Net-Daemon

hth,
--
Charles DeRykus


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

Date: Thu, 22 Feb 2001 20:25:56 +0100
From: snef <snef@soneramail.nl>
Subject: Question.about s///
Message-Id: <MPG.14ff862fdaa946bf989711@news.soneraplaza.nl>

Hi!

I want to make a simple substitution.

I need te replace all accented characters (ö é .....) to their 'normal' 
characters.
I wrote a little program in Windows with this line in it:

$sometext =~ s/{ö|ó|ò|õ}/o/ig;

When I run it on a windows machine this will give the wanted result, but 
when I run this on a linux machine it fails....
It has got something to do with a character set or so?

Can please somebody help me?????

Snef.


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

Date: 22 Feb 2001 19:48:26 GMT
From: egwong@netcom.com
Subject: Re: Question.about s///
Message-Id: <973qe9$1k6c$1@newssvr06-en0.news.prodigy.com>

snef <snef@soneramail.nl> wrote:
> Hi!

> I want to make a simple substitution.

> I need te replace all accented characters ( ? ? .....) to their 'normal' 
> characters.
> I wrote a little program in Windows with this line in it:

> $sometext =~ s/{?|?|?|?}/o/ig;

> When I run it on a windows machine this will give the wanted result, but 
> when I run this on a linux machine it fails....
> It has got something to do with a character set or so?

Offhand, it looks almost right to me.  I'm positive that you don't want
the curly braces around your alternation series (which may be why your
first and last characters fail).  Something like

  $sometext =~ s/a|b|c/o/ig;

will do just fine.

Also, consider using tr// (see perlop) instead of s//, it may be
faster.

[had to delete high-characters, tin won't let me post with 'em]


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

Date: Thu, 22 Feb 2001 14:46:04 -0600
From: Dmitry Epstein <mitiaNOSPAM@northwestern.edu.invalid>
Subject: Reading from __DATA__
Message-Id: <3A957A8C.A8A9C70C@northwestern.edu.invalid>

How can I read read the entire __DATA__ block several times?  Opening
and closing DATA filehandle doesn't do the job.  I tried seek:

seek(DATA, 0, 0)

but that rewinds to the top of the module, that is next time I read from
DATA it starts reading from the first line of the file, rather than from
the first line after __DATA__

(I have Perl 5.6.1 built for Cygwin)

Thanks

-- 

Dmitry Epstein
Northwestern University, Evanston, IL.  USA
mitia<at>northwestern<dot>edu


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

Date: 22 Feb 2001 21:56:57 GMT
From: egwong@netcom.com
Subject: Re: Reading from __DATA__
Message-Id: <9741v9$7gr8$1@newssvr05-en0.news.prodigy.com>

Dmitry Epstein <mitiaNOSPAM@northwestern.edu.invalid> wrote:
> How can I read read the entire __DATA__ block several times?  Opening
> and closing DATA filehandle doesn't do the job.  I tried seek:

> seek(DATA, 0, 0)

> but that rewinds to the top of the module, that is next time I read from
> DATA it starts reading from the first line of the file, rather than from
> the first line after __DATA__

Use "tell" to get the start position of DATA before you read from it.

  my $data_start = tell( DATA );

  ... read DATA ...

  seek( DATA, $data_start, 0 );

  ... re-read DATA ...
  etc.


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

Date: 22 Feb 2001 22:54:46 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Reading from __DATA__
Message-Id: <slrn99b65m.70h.abigail@tsathoggua.rlyeh.net>

Dmitry Epstein (mitiaNOSPAM@northwestern.edu.invalid) wrote on MMDCCXXXII
September MCMXCIII in <URL:news:3A957A8C.A8A9C70C@northwestern.edu.invalid>:
][ How can I read read the entire __DATA__ block several times?  Opening
][ and closing DATA filehandle doesn't do the job.  I tried seek:
][ 
][ seek(DATA, 0, 0)
][ 
][ but that rewinds to the top of the module, that is next time I read from
][ DATA it starts reading from the first line of the file, rather than from
][ the first line after __DATA__


After the seek, do:

    1 until <> eq "__DATA__\n";


Abigail


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

Date: 22 Feb 2001 22:36:20 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Reading from __DATA__
Message-Id: <86elwqbb17.fsf@jon_ericson.jpl.nasa.gov>

Dmitry Epstein <mitiaNOSPAM@northwestern.edu.invalid> writes:

> How can I read read the entire __DATA__ block several times?  Opening
> and closing DATA filehandle doesn't do the job.  I tried seek:
> 
> seek(DATA, 0, 0)
> 
> but that rewinds to the top of the module, that is next time I read from
> DATA it starts reading from the first line of the file, rather than from
> the first line after __DATA__

Here's one solution (you were on the right track):

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

my $data_start = tell DATA;
print <DATA>;
seek DATA, $data_start, 0;
print <DATA>;

__DATA__
Hello (twice)


Jon


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

Date: 22 Feb 2001 20:47:45 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Remote Printer configuration: for (AIX, SUNOS lp, lpr etc)
Message-Id: <86u25mbg26.fsf@jon_ericson.jpl.nasa.gov>

wtautz@math.uwaterloo.ca (Walter Tautz [MFCF]) writes:

> Has anyone ever dealt with these type of problems and solved them using
> perl or some other language?

I'm sorry, but the question (as phrased) is *off-topic* for this
group.  The tip-off is that the problem you describe can be solved
with languages beside perl.  Once you have an algorithm for solving the
problem, tried to solve it in perl, and checked the relevant
documentation, FAQs, and archives, then you could ask an on-topic
question.  You should be prepared to show some code, describe inputs
and expected outputs, and include any unexpected warnings, errors or
outputs.  While you're at it, it would help if you used strict and
warnings, and checked the results of system calls.  You have a long
road ahead.

Jon


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

Date: Thu, 22 Feb 2001 19:19:42 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Ripping apart a scalar - Important!
Message-Id: <t9apie7nrdtlbd@corp.supernews.com>

Jonas Nilsson <jonni@ifm.liu.se> wrote:
>> How would I take a scalar, say from a text field, and attempt to insert
>> characters into it.  For example:  I have a phone number field, but I want
>> to make sure that the area code has parenthesis around it. Any ideas?

> Depends on how your scalar looks. You should check into perldoc perlop and
> perldoc perlre. Examples:

> $scalar=~s/(\d{2,3}-)/\($1\)/;
> Would change the first appearance of two or three digits followed by an - to
> include paranthesis

Slightly better would be to mathc before non-digit instead of just dash, and
perhaps, depengding on location, not make the part following the first group
part of the capture.

$scalar =~ s/(\d{2,3})\D/(\($1\)/;

573-221-0987 becomes (573)221-0987
573.221.0987 becomes (573)221.0987
573 221 0987 becomes (573)221 0987

> $scalar=~s/\b(\d*)\b/\($1\)/;
> Would change the first cluster of digits to include parenthisis:
> 123-123 123 123 => (123)-123 123 123
> 1234567 => (1234567)
> 123 123123 => (123) 123123
> 123 123-123 => (123) 123-123

This works well except in the case (as you point out) that someone
enters all digits with no delimiting marks at all.

Chris

-- 
Christopher E. Stith
The purpose of a language is not to help you learn the
language, but to help you learn other things by using the
language. --Larry Wall, The Culture of Perl, August 1997



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

Date: Thu, 22 Feb 2001 13:30:30 -0600
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: Ripping apart a scalar - Important!
Message-Id: <CEBBA1DCC83E7FBF.520848EBCFB92EB7.2F7443B704119331@lp.airnews.net>


"Liam" <radioliam@charter.net> wrote:
: I'm in a desperate bind and need an application built by the end of the
day,
: so I beg of you all for some help.
:
: How would I take a scalar, say from a text field, and attempt to insert
: characters into it.  For example:  I have a phone number field, but I want
: to make sure that the area code has parenthesis around it. Any ideas?
:
: Much appreciated, and I would love an e-mail response but I will keep
: checking back here.
:

my @phone_list = ('1 800 5559292', '(877)345+3459', '7279890');
print "$_\n" foreach @phone_list;
print "$_\n" foreach phone_format(@phone_list);

sub phone_format {
    my @formatted;
    my @phone_numbers = ref(@_) eq 'ARRAY' ? @{$_[0]} :  @_;
    foreach (@phone_numbers) {

        # reduce to digits only
        s/\D//g;

        # check for area code
        s/(\d{3})(\d{7})$/ \($1\) $2/ if length > 9;

        # last 4 digits
        s/(\d{4})$/-$1/;

        # trim leading space on 10 digit numbers
        s/^\s//;

        push @formatted, $_;
    }
    # call with a reference for long phone lists
    return wantarray ? @formatted : \@formatted;
}

HTH,
Charles K. Clarkson





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

Date: 22 Feb 2001 20:22:08 +0000
From: Wayne Pascoe <wayne@penguinpowered.org.uk>
Subject: Sessions in webaps with perl
Message-Id: <m31ysqh3in.fsf@zaphod.realtime.co.uk>

I am trying to build sessions into a web application to achieve
similar functionality that PHP offers.

With PHP I am able to start sessions, register variables as session
variables (so that they are stored on the server, not passed back and
forth to the user) and destroy sessions.

In PHP, I can't do lots of other things that I want to and that I can
in Perl though.

Is it possible to achieve this same functionality in Perl? I am
currently looking at 2 options.

1. Use the Apache::Session module from CPAN. I haven't heard too much
about this module, and I'd appreciate any comments on how good it
is. Particularly I am interested in how much load it adds to an
application and what the available storage modules are (MySQL, flat
file, etc.

2. Using cookies to store an MD5 hash that is the session key on the
user's machine. Then build temporary tables in a database to store
form data or session variables. This way lies madness methinks.

Please don't flame me for not reading the group properly before
posting. I looked through 893 messages in this group today looking for
enlightenment and found none. I would search deja, but... :)

-Wayne
-- 
Making numberplates                      | wayne@penguinpowered.org.uk
                                         | www.penguinpowered.org.uk


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

Date: 22 Feb 2001 22:54:09 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Sessions in webaps with perl
Message-Id: <86ae7eba7i.fsf@jon_ericson.jpl.nasa.gov>

Wayne Pascoe <wayne@penguinpowered.org.uk> writes:

> 1. Use the Apache::Session module from CPAN. I haven't heard too much
> about this module, and I'd appreciate any comments on how good it
> is. Particularly I am interested in how much load it adds to an
> application and what the available storage modules are (MySQL, flat
> file, etc.
> 
> 2. Using cookies to store an MD5 hash that is the session key on the
> user's machine. Then build temporary tables in a database to store
> form data or session variables. This way lies madness methinks.

The mod_perl mailing list is likely to have better opinions then
people here (but be sure to search the archives).
http://modperl.com/hangman.html illustrates 7 different solutions
(though Apache::Session is not one of them) to this problem.

Jon


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

Date: Thu, 22 Feb 2001 21:32:48 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Specifying the length of regular expression
Message-Id: <t9b1c0s3tdl1eb@corp.supernews.com>

In article <3A93ABD6.90E1851@ot.com.au>,
    Ian Boreham  <ianb@ot.com.au> wrote:

: Greg Bacon wrote:
: 
: > I know you objected to the distinction before, but matching strings of
: > the form A+B*C+ that are at least ten characters in length is an
: > academic problem.  Introduce concatenations, character classes,
: > alternations, lookaheads, and so forth to severely complicate the
: > problem.
: 
: As it happens, this was posed as a real, practical problem by the original
: poster (see the parallel thread "Regular Expression Question" for more
: information on the actual problem), although it turned out that it was the
: wrong question. However, the right question was similar, and it was still
: heavily biased towards a regex solution, since it had to be used in "split".
: Yes, other solutions are possible, but in this case probably not better.

If I said "Hey, I have to use split to tokenize HTML" or "Hey, I need to
drive these 16d nails, but all I have is this stubby screwdriver",
what's the best advice?  Would you suggest that I leave my tool's design
limits or that I use a more appropriate tool that will make my life
easier in the long run?

The Road to Perl is paved with string manipulation libraries written
in C.

: > I would argue the a module like the one you've described is
: > unnecessarily limited.
: 
: As are about 99% of third-party products you'll ever be required to use.

I like to use my head in manners other than as a brute force implement.
If a tool is too limited for my intended use, then I either accept the
limitation or find (or write!) a better tool.

: > Maybe I'm just unimaginative, but what's wrong with
: >
: >     for (@strings) {
: >         if (/$monster_regular_expression/o) { ... }
: >         elsif (/^(A+B*C+)$/ && length($1) > 10) { ... }
: >     }
: 
: Well, you're hard-coding your special logic into your program, for a start.
: Having to edit the program logic every time you want to change what matches
: makes the program more error-prone and harder to maintain.

That's why they pay us the big bucks, friend.

:                                                            I was considering a
: system in which you just added regexes to a file (possibly paired with other
: data, depending on what the program does). Think of lex, for example. It's
: designed to allow you to specify input in a regex + data form, rather than
: making you edit the lex program to hard-code in all the regexes and special
: case logic.

I agree that lex is great for tokenizing simple languages, but it has
its limitations.  Note, for instance, that perl's tokenizer is hand
generated.

: > As for security concerns, there are patterns that can push the regular
: > expression matcher into exponential time, so, if you're concerned about
: > denial of service, you shouldn't allow untrusted users to specify
: > arbitrary regular expressions.
: 
: So allowing them to specify arbitrary code to evaluate is supposed to
: make this safer?

Where did I make that claim?

: I can just imagine you telling your boss "Well, I could just use the
: interface as is, and spend a few minutes coming up with a regex [...]

Your argument falls apart right there.  The language in question, that
might appear in a textbook on formal languages pattern, takes only a
trivial amount of extra thought and modification.  If there are only
a couple of warts like this in the patterns that you want to match,
then there's no reason to cook up a more flexible interface.  What
happens when you have a lot of patterns that begin to require more and
more effort?  What if you want to match strings such that there is no
Perl regular expression for them?

Greg
-- 
No one now dies of fatal truths: there are too many antidotes to them.
    -- Nietzsche


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

Date: 22 Feb 2001 19:12:42 GMT
From: erbmicha@msu.edu (erb)
Subject: system() and cgi
Message-Id: <973obb$2o20$1@msunews.cl.msu.edu>

i am running ActivePerl with the ISAPI part of it for the cgi-bin.

i have a perl script that runs just fine from the command line:

    	system 'c:\ease3\winease.exe c:\ease3\examples\elcrapola.bas';

but when i run it from the cgi-bin via a web browser, the application being 
called give a 'cannot reference memory...' error.

any ideas?

how do i run this application and then grab the output from it any other 
way?

thanks!!!


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

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


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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