[11466] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5066 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 5 13:07:22 1999

Date: Fri, 5 Mar 99 10:00:20 -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, 5 Mar 1999     Volume: 8 Number: 5066

Today's topics:
    Re: "cant last outside a block" not caught at compile t (Mark-Jason Dominus)
    Re: "cant last outside a block" not caught at compile t (M.J.T. Guy)
    Re: <STDIN> Question (M.J.T. Guy)
    Re: <STDIN> Question (M.J.T. Guy)
    Re: <STDIN> Question <upsetter@ziplink.net>
        Catching output from AT <smw3@doc.ic.ac.uk>
    Re: COnverting comma separate values (Jeff Lovell)
    Re: Cross Platform DBMs <ccyr@home.com>
        E-Mail Bounces <mwatkins@promotion4free.com>
    Re: Getting rid of ^M <bwebb@fred.net>
    Re: help using system() (Greg Bacon)
    Re: How to do a Case-insensitive Sort? (Greg Bacon)
    Re: How to run Perl program as NT service? <--- perl.ex <rawkrawl@rednecks.com>
    Re: long lines in data file being cut (Jonathan Stowe)
        Nifty little tied scalar package (Sean McAfee)
    Re: Perl - deleting files that are 2 days old <jglascoe@giss.nasa.gov>
    Re: Printing in Perl (the jackal)
    Re: questions about grep in a void context (Mark-Jason Dominus)
    Re: questions about grep in a void context <Allan@due.net>
        Quick Regular Expression Quesion <mwatkins@promotion4free.com>
    Re: Quick Regular Expression Quesion (M.J.T. Guy)
    Re: Regex example from Camel book (Greg Bacon)
    Re: Seriously confused about subscripts <jglascoe@giss.nasa.gov>
        Sorting an associative array <henning@hjk1.isdn.lif.de>
        System command doesn't return on NT <lgj19@mail.idt.net>
    Re: Taint checking, setuid cgi scripts, and user admini (Greg Bacon)
    Re: Yesterday! (M.J.T. Guy)
    Re: Yesterday! dave@mag-sol.com
    Re: Yesterday! (M.J.T. Guy)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 5 Mar 1999 12:03:37 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: "cant last outside a block" not caught at compile time?
Message-Id: <7bp2p9$sfg$1@monet.op.net>

In article <m1hfs0fvwx.fsf@zot.localdomain>,
Mark Atwood  <mra@pobox.com> wrote:
>#!/usr/bin/perl
>sub main {
>    print "wump\n";
>    last if 1;
>}
>&main();
>
>Can't "last" outside a block at ./tst.pl line 5.
>
>Why isn't this caught at compile time?

Because `last' has dynamic scope. 

	sub main { 
	    print "wump $_[0]\n";
	    last if 1;
	}

	while (<DATA>) {
	  &main($_);
	}

	__DATA__
	Line 1
	Line 2 which is never read or printed because of `last'
	Line 3 is not read either because the program has exited

The `last' here operates on the `while' loop.



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

Date: 5 Mar 1999 17:25:58 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: "cant last outside a block" not caught at compile time?
Message-Id: <7bp436$97b$1@pegasus.csx.cam.ac.uk>

In article <7bp2p9$sfg$1@monet.op.net>, Mark-Jason Dominus <mjd@op.net> wrote:
>Because `last' has dynamic scope. 
>
>	sub main { 
>	    print "wump $_[0]\n";
>	    last if 1;
>	}
>
>	while (<DATA>) {
>	  &main($_);
>	}
>
>	__DATA__
>	Line 1
>	Line 2 which is never read or printed because of `last'
>	Line 3 is not read either because the program has exited
>
>The `last' here operates on the `while' loop.

But it should be pointed out that such dynamic use will provoke warnings
with -w:

Exiting subroutine via last at - line 3, <DATA> chunk 1.


Mike Guy


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

Date: 5 Mar 1999 17:00:06 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: <STDIN> Question
Message-Id: <7bp2im$7kf$1@pegasus.csx.cam.ac.uk>

In article <39pv6ohk14.fsf@ibnets.com>, Uri Guttman  <uri@ibnets.com> wrote:
>but perl is smarter than you are. this seems to work just fine:
>
>perl -e '@a=<>; print @a; open( STDIN, q(-) ); $l=<>; print "[$l]\n"'

But doesn't do what was asked for.    He wants STDIN to be from a file
initially, not from the console.


Mike Guy


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

Date: 5 Mar 1999 17:04:24 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: <STDIN> Question
Message-Id: <7bp2qo$7uo$1@pegasus.csx.cam.ac.uk>

Larry Rosler <lr@hpl.hp.com> wrote:
>Opening '-' opens STDIN and opening '>-' opens STDOUT.
>
>So the platform-independent name of the terminal in Perl is '-'.  

Nope.   '-' is the platform-independent name of STDIN.   :-)
It'll only give you the terminal if STDIN was set up to the terminal.
Which is exactly what the original poster *didn't* want.

>Problem solved.

'Fraid not.    I don't know of a truly platform-independent way of
opening the terminal (if indeed a terminal is available).
But you can find some approximations in the Term:: modules.


Mike Guy


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

Date: Fri, 05 Mar 1999 17:34:12 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: <STDIN> Question
Message-Id: <oAUD2.291$I51.50535@news.shore.net>


M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:
: In article <39pv6ohk14.fsf@ibnets.com>, Uri Guttman  <uri@ibnets.com> wrote:
:>but perl is smarter than you are. this seems to work just fine:
:>
:>perl -e '@a=<>; print @a; open( STDIN, q(-) ); $l=<>; print "[$l]\n"'

: But doesn't do what was asked for.    He wants STDIN to be from a file
: initially, not from the console.

Thanks for the help. It looks like it will probably be easier and quicker
to have the users specify a file with "-f <filename>" or something
instead. This script is going to be run from the shell for the forseeable
future, so I could probably use "/dev/tty" or something similar, but I
figure if I do that it will probably be *just after* I've forgotten about
using that little hack that the script is added to a cron job. :)

--Art

-- 
--------------------------------------------------------------------------
                    National Ska & Reggae Calendar
                  http://www.agitators.com/calendar/
--------------------------------------------------------------------------


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

Date: Fri, 5 Mar 1999 17:06:02 +0000
From: Simon Wistow <smw3@doc.ic.ac.uk>
Subject: Catching output from AT
Message-Id: <Pine.LNX.3.96.990305165817.29773A-100000@sync02.doc.ic.ac.uk>


I'm writing a script which calls AT like this

	@run_command=("at","-f","$scriptname","+ 1 minute");
	system (@run_command)==0 || die "Couldn't run 'at': $?\n";


However at prints out

	Job x will be executed using /bin/sh

Since the script that calls At is itself being called by At (and
therefore any output will cause a mail to be sent to root which I don't
want) I want to trap this output some.

running 

	at -f $scriptname + 1 minute > dev/null

doesn't work neither does have something like

	system(@run_command) || die $?;
	while (<STDERR>){}

any ideas?

Cheers 
Simon




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

Date: 5 Mar 1999 16:00:29 GMT
From: jalovel@orl.ilstu.edu (Jeff Lovell)
Subject: Re: COnverting comma separate values
Message-Id: <slrn7e038u.34l.jalovel@www.orl.ilstu.edu>

Jonathan Stowe rambled on in comp.lang.perl.misc:
>This is pretty fundamental stuff.  

[smartass stuff snipped]

Oh, I see, clp.misc is for people who are beyond the basics.  This is
the type of responses that irk me.  You could politely pointed this
person to the documentation they needed, but instead you take this
"holier than thou" approach.  If what you have to say is not helpful
in the slightest, keep it to yourself.

Maybe we should propose comp.lang.perl.usless_answers in alt.config.


Jeff


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

Date: Fri, 05 Mar 1999 17:26:01 GMT
From: Colin Cyr <ccyr@home.com>
Subject: Re: Cross Platform DBMs
Message-Id: <36E013EF.698C262A@home.com>

If I recall correctly from when I was looking up the differences between
DBM formats, the only one which seemed to be platform independant, to my
recall, was DB_File.

When you are invoking perl's db_open (or similar command) it is just
using what ever dbm library it was compiled with, thus it can vary
between systems.

Jerome O'Neil wrote:
> 
> Debug::Psychic prognosticates that you are using Any_DBM.  I looks like
> it is using sdbm on the Sun and some other dbm (gdmb) on the linux box.
> You need to ensure that they are using the same library.
> 
> Even then, I don't think dbm files are portable between platforms.  I
> have problems moving gdbm files from Solaris to SCO and back.


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

Date: Fri, 5 Mar 1999 17:16:52 -0000
From: "Mike Watkins" <mwatkins@promotion4free.com>
Subject: E-Mail Bounces
Message-Id: <#$#r1wyZ#GA.280@nih2naae.prod2.compuserve.com>

Hi there,

I have a mailing list script, which automatically sends out messages at set
intervals of time.  I was just wondering, what will happen when an address
bounces?  Or how can you tell if it's a valid e-mail address, other than
just checking for the right format?

Thanks alot,
MIke





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

Date: Fri, 5 Mar 1999 12:47:19 -0500
From: "Robert E Webb" <bwebb@fred.net>
Subject: Re: Getting rid of ^M
Message-Id: <YPUD2.222$F4.297223@news.abs.net>

Philip, You are correct. I cut and pasted from some old code that had
the -0777. Let try this again:

This should work:
#!/usr/bin/perl -p

s/\015$//;

Sorry for the confusion.

Bob/

Philip Newton wrote in message <36DFB430.C5A7DA5D@datenrevision.de>...
>Robert E Webb wrote:
>>
>> This should work:
>>
>> #!/usr/bin/perl -p0777
>>
>> s/\015$//;
>
>I think not. If I understand correctly, -0777 will slurp in the whole
>file as a single string. Then your regular expression will match at the
>end of the string. You have removed the last ^M, but not all the ones on
>the lines in the middle. I think you need either to leave off the -0777
>(so that each line will have its ^M cut off) or add the /m modifier
>(make ^ and $ match inside the string, too) to the regular expression,
>like so:  s/\015$//m;  (alternately, you can replace \015 by \cM, I
>think, to show that you're looking for ^M, but that's a minor matter).
>
>Cheers,
>Philip




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

Date: 4 Mar 1999 21:30:36 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: help using system()
Message-Id: <7bmu1s$ch1$2@info.uah.edu>

In article <7bmpic$8s$1@nnrp1.dejanews.com>,
	cindy_conway@my-dejanews.com writes:
: I am trying to use system() on a Perl script running on an NT system. I need
: to invoke a windows application called Bar Tender.I've written it like this:
: 
: system("bartend") #bartend.exe is the program file
: 
: When I run the script, nothing happens. If I write the same line of code, and
: I try to invoke an application that is located under the winnt directory
: (like, say, notepad or pblush), it runs no problemo.

What's the return value from system?  What does $! say?  Is the desired
executable in your PATH?

Greg
-- 
Join the Army: travel to exotic distant lands; meet exciting, unusual people,
and kill them. 


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

Date: 4 Mar 1999 21:41:49 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: How to do a Case-insensitive Sort?
Message-Id: <7bmumt$ch1$4@info.uah.edu>

In article <36DEF62E.E7ED0BE6@giss.nasa.gov>,
	Jay Glascoe <jglascoe@giss.nasa.gov> writes:
: my @sorted = sort { lc $a cmp lc $b } @list;

Too many lc()s:

    my @sorted = map  { $_->[0] }
                 sort { $a->[1] cmp $b->[1] }
                 map  { [ $_, lc($_) ] }
                 @list;

Greg
-- 
We are Fudd of Borg: Pwepawre to be aswimiwated.


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

Date: Fri, 5 Mar 1999 18:30:39 +0100
From: "thomas" <rawkrawl@rednecks.com>
Subject: Re: How to run Perl program as NT service? <--- perl.exe persistance
Message-Id: <36e0142d.0@d2o64.telia.com>

Hiya,

Alongside this thread,a thought just struck me;
wouldnt it be a performance boost having the perl interpreter
loaded as a service.
Having it already loaded, straying the memory,should make the script
shoot faster,right. I mean,you dont have to load perl.exe and all its'
autoload stuff
every time you run your tiny 5000 bytes script.

 ...kinda like the Apache >>> mod_perl companionship...

Would this be an approach in words of performance ???

thunx
thomas


Henry Schlarb skrev i meddelandet <7bngk2$218$1@demon.uunet.ca>...
>It would be better if you either
>
>    -installed the perl.exe as a service and specify the script as a
>parameter. This is detailed in the servany documentation. I don't think
>batch files run well as a service.
>
>    -put the script in your startup directory
>
>for more info, respond directly to me. I work a couple of blocks from your
>address.
>
>Bob Fillmore wrote in message <36DDBB08.6F21193E@nrn1.nrcan.gc.ca>...
>>I would like to run a Perl program as an NT service so that it's started
>>on each reboot.





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

Date: Fri, 05 Mar 1999 16:50:38 GMT
From: gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: long lines in data file being cut
Message-Id: <36e009c8.28345228@news.dircon.co.uk>

On Fri, 05 Mar 1999 11:37:39 +0000, 23_skidoo
<23_skidoo@geocities.com> wrote:

>hi, i've just looked through perlfaq4 - Data Manipulation ($Revision:
>1.15 $) and perlfaq5 - Files and Formats ($Revision: 1.19 $) and
>dejanews for the answer to this question. no luck so far.
>
>i have a cgi script which reads from an html form and creates a data
>file like this, adding new entries onto the end of the file:
>
>Tues 2rd Mar - 108 Club
>19990302
>eric
>foo@bar.com
>a review of a gig which could be any length
>=====
>Tues 2rd Mar - 108 Club
>19990302
>eric2
>foo2@bar.com
>another review of a gig which again could be any length
>=====
>
>my problem is that the final line, the review of a gig can be any length
>and when they get over 1833 characters, that's all that gets stored, the
>rest is lost somewhere.
>


Without seeing your code I would pressed to give a definitive answer -
however it is probably an artefact of either the browser or the server
rather than the program itself.

/J\


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

Date: Fri, 05 Mar 1999 17:25:04 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Nifty little tied scalar package
Message-Id: <QrUD2.10176$Ge3.39910481@news.itd.umich.edu>

My main project at work right now is writing and maintaining a set of code
written in both Perl and Oracle PL/SQL.  I've collected all of the main
functionality into a single Perl module named "Workflow.pm", so that I can
quickly invoke any of a large number of routines from the command line like
so:

> perl -MWorkflow -e parse_new_stuff
> perl -MWorkflow -e 'call plsql_procedure'

Since most of my routines deal with an Oracle database, I put login and
logout code into BEGIN and END blocks in Workflow.pm:

BEGIN { $dbh = DBI->connect("dbi:Oracle:", @ORACLE_LOGIN) }
END   { disconnect $dbh }

Recently, however, I've been writing code that doesn't need to deal with
the database.  So, I wanted to avoid the overhead of connecting and
disconnecting with the database if no database code was called in a
particular run of the Perl interpreter.  I came up with the following tied
scalar package which loads a scalar only when the scalar's value is first
fetched:

{
    package OnDemand;
    sub TIESCALAR { bless [ $_[1], 0 ], $_[0] }
    sub FETCH { $_[0][1] ? $_[0][0] : (@{$_[0]} = (scalar &{$_[0][0]}, 1))[0] }
    sub STORE { @{$_[0]} = ($_[1], 1) }
}

(It looks a bit ugly, but I wanted it to be compact.)

One ties a scalar to the package like this:

tie $scalar, 'OnDemand', $ref_to_sub;

 ...where $ref_to_sub is a subroutine reference that is called (in scalar
context) when the scalar's value is first fetched.  The return value of the
subroutine becomes the scalar's value.  My database-connecting code became
this:

BEGIN {
    tie $dbh, 'OnDemand', sub {
        DBI->connect("dbi:Oracle:", @ORACLE_LOGIN)
    };
}

END { disconnect $dbh if (tied $dbh)->[1]; }

(That "if" clause in the END block is necessary, or the "disconnect $dbh"
would trigger a login when $dbh's value is fetched, followed immediately
by a logout when the "disconnect" method is called.  If $x is a scalar
tied to OnDemand, (tied $x)->[1] is a flag indicating whether the
subroutine originally associated with the scalar has been called.)

Anyway, I'm pretty happy with the results, and thought I'd share.

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


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

Date: Fri, 05 Mar 1999 12:24:00 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Perl - deleting files that are 2 days old
Message-Id: <36E01330.FB4FC967@giss.nasa.gov>

[courtesy copy of post sent to Larry via email]

hi Larry,

Larry Rosler wrote:
> 
> In article <36DEE294.326BF463@giss.nasa.gov> on Thu, 04 Mar 1999
> 14:44:20 -0500, Jay Glascoe <jglascoe@giss.nasa.gov> says...
> ...
> > unlink foreach @file_list;
> 
> That unlinks them one at a time (and only in 5.005, at that).  And all
> system calls should be checked, no?
> 
>   unlink(@file_list) == @filelist
>       or die "Couldn't unlink all of these files: @filelist. $!\n";

Right!  thank you.  I actually have a line like this in
one of my CGI programs.  Your solution is faster and safer:
it's a win all around.  :)

	Jay Glascoe
--
"Soup on all fours?"
"Of course.  Whaddaya think, Soup is a biped?" - mst3k


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

Date: 5 Mar 1999 17:00:51 GMT
From: hdiwan@diwanh.stu.rpi.edu (the jackal)
Subject: Re: Printing in Perl
Message-Id: <slrn7e03dj.qse.hdiwan@diwanh.stu.rpi.edu>

perldoc perlform
In article <7boqgs$n89$1@nnrp1.dejanews.com>, dennishancy@eaton.com wrote:
>I'm hoping this question has a simple answer.
>
>In Perl, I need to print a series of HTML form values to a text file.  I
>understand how to retrieve these values; but how can I produce formatted
>output?
>
>In other other words, field #1 is a text value of four characters that will
>be printed in positions 1-4;  field #2 is numeric and will be printed in
>positions 5-12 in the format #####.##; and so on.
>
>Any advice would be appreciated.  Thanks!
>
>
>Dennis Hancy
>Eaton Corporation
>Cleveland, OH
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


-- 
Hasan Diwan


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

Date: 5 Mar 1999 12:12:09 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: questions about grep in a void context
Message-Id: <7bp399$sgr$1@monet.op.net>

In article <7bmmtb$4om$1@samsara0.mindspring.com>,
Allan M. Due <Allan@due.net> wrote:
>1)  Given that grep in a void context is faster than the foreach, should we
>revisit the notion that grep in a void context is deprecated?  

It's not deprecated.  It's never been deprecated.

It might be bad style.  It might be obfuscated.  It might be slow.  It
might be naughty.  That's all arguable, and most of it is a matter of
opinion.  

There are a bunch of people running around saying that it's bad style,
obfuscated, slow, or naughty, but you don't have to listen to them.

It's like split infinitives in English.  People `split infinitives'
for hundreds of years.  Then a bunch of prescriptivist grammarians said
that split infinitives were naughty and bad, and nobody should ever do
that.  People continued to split infinitives, but now some of them
felt guilty about it.




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

Date: Fri, 5 Mar 1999 13:02:31 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: questions about grep in a void context
Message-Id: <7bp5rc$17e$1@samsara0.mindspring.com>

Mark-Jason Dominus wrote in message <7bp399$sgr$1@monet.op.net>...
:In article <7bmmtb$4om$1@samsara0.mindspring.com>,
:Allan M. Due <Allan@due.net> wrote:
:>1)  Given that grep in a void context is faster than the foreach, should
we
:>revisit the notion that grep in a void context is deprecated?
:It's not deprecated.  It's never been deprecated.
:It might be bad style.  It might be obfuscated.  It might be slow.  It
:might be naughty.  That's all arguable, and most of it is a matter of
:opinion.
:
:There are a bunch of people running around saying that it's bad style,
:obfuscated, slow, or naughty, but you don't have to listen to them.

Thanks Mark,
    Deprecated was incorrect it seems, but people sure react strongly if you
use grep in a void context.  Below are just a few quotes (taken out of
context <g>) which I think are representative of the general attitude.  I
always thought the point was functionality but now it seems to be based on
style. I believe I understand the definition given below "discarding the
value it returns, and using it only for its side effects" but I would
appreciate it if someone would explain why it is considered such bad style.
And if this is such bad style, why do we not see the same reaction when
folks do things like:

foreach (@array) {
    /the word/ ? then_do () : or_dont();
}

or

$count++ and next if /match/;

Both of which seem to meet the definition.  Is void context unstylish or
just map and grep in a void context?  Just trying to understand all this,
probably not worth spending much time on but I am just curious.  Any
edification is appreciated.

Quotes:

"You are using the wrong tool.  One indication of that is that you are
using 'grep' in void context (that is, discarding the value it returns,
and using it only for its side effects).  This is *never* the best way
to express the solution."

"uncool to use grep in a void context."

"the blue Camel, pg 548:
Avoid using grep, map, or backticks in a void context..."

"map and grep in a void context... Ick. :-)"

"I agree, for example, that using grep in a void context is bad, "

"Ouch. Please don't do this.  It's considered bad form to use map or
grep in a void context.  Use the equivalent foreach instead"

"The use of grep in void context is now officially considered harmful.
Please use foreach instead."

"It seems that grep is significantly faster for short lists, and not
too shabby with long lists either. though i agree that it would be
poor style to use as such."

--
$email{'Allan M. Due'} = ' All@n.Due.net ';
--random quote --
A computer lets you make more mistakes faster than any invention in
human history - with the possible exceptions of handguns and tequila.
 - Mitch Ratliffe





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

Date: Fri, 5 Mar 1999 17:09:19 -0000
From: "Mike Watkins" <mwatkins@promotion4free.com>
Subject: Quick Regular Expression Quesion
Message-Id: <uDvSosyZ#GA.330@nih2naae.prod2.compuserve.com>

Hi there,

I have a script which gathers the contents of an HTML file into the var
$html.  Now, I want to extract all of the names and values of form fields.
Right now, I have this:

(@texts) = $html =~ /<input.*type=.text.*name\=.(.+)/gi;

That works perfectly except it doesn't stop until either the end of the
file, or the end of the line.  Was just wondering, how do you get it to stop
at the next > it encounters?

Thanks alot,
MIke





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

Date: 5 Mar 1999 17:44:54 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Quick Regular Expression Quesion
Message-Id: <7bp56m$a8v$1@pegasus.csx.cam.ac.uk>

Mike Watkins <mwatkins@promotion4free.com> wrote:
>I have a script which gathers the contents of an HTML file into the var
>$html.  Now, I want to extract all of the names and values of form fields.
>Right now, I have this:
>
>(@texts) = $html =~ /<input.*type=.text.*name\=.(.+)/gi;
>
>That works perfectly except it doesn't stop until either the end of the
>file, or the end of the line.  Was just wondering, how do you get it to stop
>at the next > it encounters?

 (@texts) = $html =~ /<input.*type=.text.*name\=.([^>]+)/gi;
                                                  ^^^^


Mike Guy


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

Date: 4 Mar 1999 21:39:12 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Regex example from Camel book
Message-Id: <7bmui0$ch1$3@info.uah.edu>

In article <u8CD2.165$F4.217450@news.abs.net>,
	"Robert E Webb" <bwebb@fred.net> writes:
: The regex works for all except the last example, it adds commas to the right
: of the decimal point. Dosn't the atom (?!\d) say "up to something not a
: number"? If so, why is the regex adding commas to the right of the decimal?

It's the C<1 while> part that causes it to find as many matches as
possible (starting from the beginning of the string with each
iteration).  This is slightly different behavior from using the /g
regular expression modifier.

: And here maybe a rookie question...
: 
: when I write a script like this:
: 
: #!/usr/local/bin/perl -w
: 
: $qq=12345.6789;
: $qq =~ 1 while s/(\d)(\d\d\d)(?!\d)/$1,$2/;
: print "$qq\n";
: 
: I get use of unitialized variable.

That's because you didn't initialize $_.  I suspect you meant to write

    1 while $qq =~ s/(\d)(\d\d\d)(?!\d)/$1,$2/;

To commify decimal numbers, you might want to do something like

    my($dec,$frac) = split /\./, $number;
    1 while $dec =~ s/(\d)(\d\d\d)(?!\d)/$1,$2/;
    $number = $dec . "." . $frac;

Hope this helps,
Greg
-- 
Sam:  What'd you like, Normie? 
Norm: A reason to live. Gimmie another beer. 


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

Date: Fri, 05 Mar 1999 12:40:28 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: John Chris Wren <jcwren@atlanta.com>
Subject: Re: Seriously confused about subscripts
Message-Id: <36E0170C.8E6C3F68@giss.nasa.gov>

[courtesy copy of post sent to cited author, John, via email]

John Chris Wren wrote:
> 
> a href doc_aa.htm
> a href doc_ab.htm
> ...
> a href doc_zz.htm
> 
> If I perform the loop "for (@docs) { print "$_->[2]\n"; }" I get what I
> expect, each line displaying just the "doc_XX.htm" entry.  I now want to
> create a hashed table, with the index being the ?? portion of the file name
> (?? being the two lettes after the underscore).
> 
> I know that { my $doc_indexs; $doc_indexes{$_->[2]} = $_->[2]; } will create
> an entry in the hash table with the complete file name, and set the "data"
> portion of the array (I forget the correct name just now) to "doc_??.htm".

my %hash = ();
my $hash{KEY} = VALUE;

> However, what I really want is to set the index to just the ?? portion of the
> file name.  For all my reading, I can't seem to find the BASIC equivalent of
> left$, right$, or mid$ (please, don't flame me about BASIC.  It's just an
> example of the functionality I want).

my %doc_indexs = {};
my $val = $_->[2];
my ($key) = ($val =~ m#^doc_(..)\.htm$#);
$doc_indexes{$key} = $val;

> And I'm under the impression that using s/// requires that the data you want
> to substitute to be in $/.

hmm?  no.

> Am I being too 'C'-centric and missing the obvious?  I know how to do this in
> everything from 6502 assembly to PL/1, but I can't seem to make it happen in
> perl...

maybe this is more familiar:

#.......0123456789
$val = 'doc_??.htm';
$key = substr $val, 4, 2;

or perhaps

$key = (unpack "a4 a2", $val)[1];

putting it all together, "for (@docs) { print "$_->[2]\n"; }" becomes:

my %hash = ();
foreach (@docs) {
    my $val = $_->[2];
    $key = substr $val, 4, 2;
    $hash{$key} = $val;
}


	Jay Glascoe
--
"Soup on all fours?"
"Of course.  Whaddaya think, Soup is a biped?" - mst3k


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

Date: Fri, 05 Mar 1999 17:40:01 +0000
From: Henning Koch <henning@hjk1.isdn.lif.de>
Subject: Sorting an associative array
Message-Id: <36E016F0.49F8B8CC@hjk1.isdn.lif.de>

Hi,
I have a problem sorting an associative array.
The values of this array are numbers.
If I want to sort this numbers with:
     foreach $number (sort values(%array))
how can I access the numbers and the related index ?

Any help would be great.
Thanks in advance,
Henning.
--
Henning Koch, D-61184 Karben, Germany, henning@hjk1.isdn.lif.de




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

Date: Fri, 5 Mar 1999 16:56:49 -0000
From: "Lonnie Johnson" <lgj19@mail.idt.net>
Subject: System command doesn't return on NT
Message-Id: <7bp27r$o2d@nnrp4.farm.idt.net>

I am having a problem with a Perl script called FormMail.cgi. The problem is
with the following line:
    system("\"$mailprog\" -t -t -n $tempfile") || die("Cannot execute
$mailprog -- Check mailprog path and permissions : $!");

The Script is running on a Windows NT sever and I got FormMail.cgi from
www.geocel.com.
The cgi script stops executing after issuing the system command in the above
line. This line calls Windmail.exe to send an e-mail. The e-mail is sent,
but nothing after this line is executed. The problem is that since the CGI
script stops executing the following lines never delete  the temporary file
($tempfile).


        if ($kill_tempfile)
        {
                unlink($tempfile);
        }



In addition, I wish to extend the function of this script and I need the
script to perform further functions after the return from the system
command.

Any help would be appreciated.





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

Date: 4 Mar 1999 21:28:24 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Taint checking, setuid cgi scripts, and user administration
Message-Id: <7bmtto$ch1$1@info.uah.edu>

In article <slrn7dtnf8.jkr.shazam@colo.brain.com>,
	shazam@cheesewhiz.kraft.com (Justin) writes:
: -L94:  chdir("$real_home_dir");
: 
: so I can start copying files like .profile and .cshrc into their directory.
: 
: But I get this:
: 
: [Thu Mar  4 09:45:04 1999] 5: Insecure dependency in chdir while running 
: setuid at /dev/fd/5 line 92.

Whence comes the value of $real_home_dir?  Are you getting it from one
of the getpw*() family?  Recite this perlsec-ian mantra:

    You may not use data derived from outside your program to affect
    something else outside your program--at least, not by accident.

You must examine Any data whose source is external to your program 
before you may perform potentially dangerous operations with that
suspect data.  The perlsec manpage gives all the details on Perl's
tainting mechanism.

Greg
-- 
We must believe in free will. We have no choice.


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

Date: 5 Mar 1999 17:16:49 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Yesterday!
Message-Id: <7bp3i1$8l9$1@pegasus.csx.cam.ac.uk>

Benjamin Franz <snowhare@long-lake.nihongo.org> wrote:
>>my ($d, $m, $y) - (localtime(time - 24*60*60))[3 .. 5];
>>
>>my $yesterday = sprintf("%02d%02d%4d", $d, $m+1, $y+1900);
>
>There really should be a FAQ entry on why that is a _bad idea_.
>Days are NOT always exactly 24*60*60 seconds long and depending
>on it is unwise: POSIX to the contrary, many boxes do account 
>for leap seconds.

Why do people keep repeating this FUD?    I know of no platform where
time() includes leap seconds.    It would be quite difficult to
implement.

>for leap seconds. 'localtime' can also can get tangled with 
>daylight savings shifts.

Now there you have the real reason why days differ in length.


Mike Guy


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

Date: Fri, 05 Mar 1999 17:13:42 GMT
From: dave@mag-sol.com
Subject: Re: Yesterday!
Message-Id: <7bp3bs$vii$1@nnrp1.dejanews.com>

In article <trSD2.162$y_2.1220@typhoon01.swbell.net>,
  snowhare@long-lake.nihongo.org (Benjamin Franz) wrote:
> In article <7bo8cr$8f6$1@nnrp1.dejanews.com>,  <dave@mag-sol.com> wrote:
> >In article <WeID2.10078$Ge3.39532024@news.itd.umich.edu>,
> >  mcafee@waits.facilities.med.umich.edu (Sean McAfee) wrote:
> >> In article <36DF479F.379A5D5@mailexcite.com>,
> >> Aaron Au  <aaronau@mailexcite.com> wrote:
> >> >I want to input a date code (mmddyyyy)(03011999) and output the last day
> >> >format(02281999).
> >> >Does anyone have a simple script?
> >>
> >> First, install the Date::Calc module.
> >>
> >> Then:
> >>
> >> use Date::Calc qw(Add_Delta_Days);
> >>
> >> sub previous_day {
> >>     $_[0] =~ /^(\d\d)(\d\d)(\d\d\d\d)$/;
> >>     sprintf("%02d%02d%04d", (Add_Delta_Days($3, $1, $2, -1))[1,2,0]);
> >> }
> >
> >Or, using the standard Perl library.
> >
> >my ($d, $m, $y) - (localtime(time - 24*60*60))[3 .. 5];
> >
> >my $yesterday = sprintf("%02d%02d%4d", $d, $m+1, $y+1900);
>
> There really should be a FAQ entry on why that is a _bad idea_.
> Days are NOT always exactly 24*60*60 seconds long and depending
> on it is unwise: POSIX to the contrary, many boxes do account
> for leap seconds. 'localtime' can also can get tangled with
> daylight savings shifts. There is no need to install Date::Calc
> for this. The solution to edge condition problems is
> to _stay away from the edges_.
>
> #!/usr/bin/perl -w
> use strict;
> use Time::Local;
> my ($sec,$min,$hour,$mday,$month,$year) = localtime(time);
> my ($newtime) = timelocal(0,0,12,$mday,$month,$year);
> ($sec,$min,$hour,$mday,$month,$year) = localtime($newtime-86400);
> $month++;
> $year += 1900;
> print "Year: $year Month: $month Day: $mday\n";

Good point... and a nice solution.

Dave...

--
Dave Cross
Magnum Solutions Ltd: <http://www.mag-sol.com/>
London Perl M[ou]ngers: <http://london.pm.org/>

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


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

Date: 5 Mar 1999 17:20:55 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Yesterday!
Message-Id: <7bp3pn$8q4$1@pegasus.csx.cam.ac.uk>

Larry Rosler <lr@hpl.hp.com> wrote:
>
>  use Time::Local;
>  
>  $_ = '03011999'; # mmddyyyy
>  /(\d\d)(\d\d)(\d{4})/;
>  my $time = timelocal(0, 0, 12, $2, $1 - 1, $3 - 1900);
>  my ($d, $m, $y) = (localtime($time - 24*60*60))[3 .. 5];
>
>Note that I choose local noon to shut off the usual carping about 
>anomalies around Summer-Time transitions.

While that does indeed indeed avoid the problem (for any sanely defined
daylight saving scheme), why mess with localtime at all?     If you
use timegm() and gmtime() instead, all such problems disappear.
And it ought to be more efficient.


Mike Guy


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

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

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