[11521] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5122 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 12 18:07:27 1999

Date: Fri, 12 Mar 99 15:01:30 -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, 12 Mar 1999     Volume: 8 Number: 5122

Today's topics:
        Regex $1 behavior (Jeff Lovell)
    Re: regexp gurus help! Parsing HTML <emschwar@mail.uccs.edu>
    Re: regexp gurus help! Parsing HTML (Bart Lateur)
    Re: regexp gurus help! Parsing HTML (Tad McClellan)
    Re: Regular expression question <Jonathan.c.sala@boeing.com>
    Re: Regular expression question <jglascoe@giss.nasa.gov>
    Re: remote ftp and exec from NT to Unix (Ethan H. Poole)
        Send a space via Net::Telnet? <kwoody@citytel.net>
    Re: Send a space via Net::Telnet? (I R A Aggie)
    Re: standard input and standard error <partha@mihy.mot.com>
        std{in,out,err} for Win32 processes? eldridge@graphics.stanford.edu
        The Meta-problem: helping others with Perl problems <cassell@mail.cor.epa.gov>
    Re: why doesn't this script modify the actual file? <jglascoe@giss.nasa.gov>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 12 Mar 1999 21:21:34 GMT
From: jalovel@orl.ilstu.edu (Jeff Lovell)
Subject: Regex $1 behavior
Message-Id: <slrn7ej4n4.cbq.jalovel@dogbert.orl.ilstu.edu>

Ok, I'm sure I must be missing something fairly obvious here, but I can't
seem to find it.  When I use the $1 backreference in s/// it doesn't seem
to work.  Here is the code I am working with:

#!/usr/bin/perl -w

$address = "127.0.0.1";
$address =~ s/((\d+\.)*)/$1/;
print $address, "\n";  # eq "127.0.0.1" <- I don't want this.
print $1, "\n";        # eq "127.0.0."  <- I want this.


Any help would be appreciated.  If you could CC via mail I would be greatful
too.  My news server is on the fritz here, and posts are lost left and right.


Jeff


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

Date: 12 Mar 1999 13:32:35 -0700
From: Eric The Read <emschwar@mail.uccs.edu>
Subject: Re: regexp gurus help! Parsing HTML
Message-Id: <xkf4snqmot8.fsf@valdemar.col.hp.com>

mct@moviefone.com writes:
> I've killed two perfectly good evenings trying to do this:

Then let someone else do it for you.  In fact, someone already has.
Check out HTML::Parser, available from CPAN.  It's much easier and more
reliable than what you're trying to do.  In fact, I think someone has
proved that you can't parse HTML with a regexp; you *must* use a parser
to handle it properly.

> <INPUT TYPE="checkbox" NAME="NotListed" VALUE="Not Listed">

What happens when you get something like:

<INPUT TYPE="checkbox"
       Name=NotListed
       Value=
"Not Listed">

This is valid HTML, but it won't pass your regexp.


-=Eric


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

Date: Fri, 12 Mar 1999 21:12:43 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: regexp gurus help! Parsing HTML
Message-Id: <36ea7db6.1194563@news.skynet.be>

Randal L. Schwartz wrote:

>>>>>> "Bart" == Bart Lateur <bart.lateur@skynet.be> writes:

>>> Take this string:
>>> 
>>> <INPUT TYPE="checkbox" NAME="NotListed" VALUE="Not Listed">
>
>Bart> Good example of what split() is bad in. You should use a real parser, or
>Bart> a better quick fix. Here's a (rather succesful :-) attempt.
>
>Except that it doesn't handle single-quoted attributes.  There's a version
>in HTML::SimpleParse::parse_args that gets this correct.

Is that all? That one is easy to fix. Just extend the alternatives with
one more, plus the extra code to remove the single quotes if there were
no double quotes.

What is far worse is that it will gladly skip any HTML errors, or things
that are not exactly formed as in this one example. Examples:

It accepts:
	<INPUT TYPE="checkbox";NAME="NotListed",VALUE="Not Listed">

and (oh horrors!):
	<INPUT TYPE="checkbox"> NAME="NotListed"> VALUE="Not Listed">

and in:
	<INPUT TYPE="checkbox" NAME="NotListed" SELECTED>

the "SELECTED" attribute is simply skipped.

But, this really was just a simple Perl exercise, playing/demonstrating
how in principal similar stuff could be tackled in Perl. The skipping of
unrecognized stuff, however, is often a real problem.

	Bart.


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

Date: Fri, 12 Mar 1999 10:05:21 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: regexp gurus help! Parsing HTML
Message-Id: <hfabc7.k2a.ln@magna.metronet.com>

Tad McClellan (tadmc@metronet.com) wrote:
: mct@moviefone.com wrote:

: : INPUT TYPE="checkbox" NAME="NotListed" VALUE="Not Listed"

: : Split the elements so that I can store them in an array. Like this;

: : INPUT
: : TYPE="checkbox"
: : NAME="NotListed"
: : VALUE="Not Listed"


: : Please, deliver me from my mental block! Thank You!


: my @parts = grep $_ !~ /^\s*$/,          # discard elements that contain
:                                          # only spaces and newline
:                  split /([a-zA-Z0-9.-]+  # a "name"
:                                          # wrap the whole thing in parens
:                                          # so split() won't discard them
:                          (?:="[^"]*")?   # optional spec of attribute value
:                         )/x;


   Seems I had a bit of a mental block there too :-)

   That is much too convoluted. This is nicer:

      my @parts = /([a-zA-Z0-9.-]+(?:="[^"]*")?)/g;


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


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

Date: Fri, 12 Mar 1999 18:41:24 GMT
From: Jonathan Sala <Jonathan.c.sala@boeing.com>
Subject: Re: Regular expression question
Message-Id: <36E95FD4.7278BE23@boeing.com>

Here is the answer:

#!/opt/bin/perl5 -w

open (LOG, "<quotes");

while (<LOG>){
 chomp($_);
 #@r=s/(["]\w+["])/\U$`$&\U$'/g;

 #s/(["]\w+["])/\U$`$&\U$'/g;
 if (m/(["]\w+["])/){
 print "\l$`$&\L$'\n";
  }
}


Tom Wood wrote:
> 
> I am trying convert all upercase character to lowercase unless they are
> quote encapsulated.
> 
> for example:
> 
> strings such as "THIS", 'THIS SENTENCE' and " THAT " would be excluded
> from the conversion.
> 
> I've tried using the tr function and match and substitution operators.
> I can convert the case were a single word is quoted but not multiple
> words or words with leading or trailing spaces.
> 
> Any help would be appreciated.


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

Date: Fri, 12 Mar 1999 15:38:05 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Tom Wood <thomas.wood@wichita.boeing.com>
Subject: Re: Regular expression question
Message-Id: <36E97B2D.A876DD37@giss.nasa.gov>

[courtesy copy of post sent to cited author]

Tom Wood wrote:
> 
> I am trying convert all upercase character to lowercase unless they are
> quote encapsulated.
> 
> for example:
> 
> strings such as "THIS", 'THIS SENTENCE' and " THAT " would be excluded
> from the conversion.

hmm.  My first idea is to split your string into "words",
then leverage the might of "Text::ParseWords".


use Text::ParseWords;
my @words = quotewords('\ ', 1, $string);

s/^([^"'].*?[^"'])$/\L$1/ foreach @words;
my $new_string = join ' ', @words;


see 
perlfaq4: "How can I split a [character] delimited 
	   string except when inside [character]?"
perldoc Text::ParseWords

	Jay Glascoe
--  
	"'We promise, yes I promise!' said Gollum.  'I will serve
	 the master of the Precious.  Good master, good Smeagol,
	 *gollum*, *gollum*!'  Suddenly he began to weep and bite
	 at his ankle again."

	--J.R.R.T.


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

Date: Fri, 12 Mar 1999 16:25:57 -0500
From: ehpoole@ingress.com (Ethan H. Poole)
Subject: Re: remote ftp and exec from NT to Unix
Message-Id: <AnFCr7Mb#GA.126@rejz.ij.net>

[Posted and Emailed]  In article <36E8DC57.D9717D7F@ewh.uni-hannover.de>, 
raming@ewh.uni-hannover.de says...
>
>Hi everybody!
>
>Can anyone please give me a quick example how to transfer files from
>NT-Workstation to a Unix-Workstation and execute a command there via a
>perl script on NT-Perl5.0?

A simple method in NT, assuming the FTP session can be scripted in advance, 
is to have your Perl script write an FTP script file, then execute NT's FTP 
command and provide it with the script.  FTP will then execute each line in 
the script. (info: ftp -help)

-- 
Ethan H. Poole              | Website Design and Hosting,
                            | CGI Programming (Perl & C)..
========Personal=========== | ============================
* ehpoole @ ingress . com * | --Interact2Day, Inc.--
                            | http://www.interact2day.com/



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

Date: Fri, 12 Mar 1999 12:34:50 -0800
From: Keith Woodworth <kwoody@citytel.net>
Subject: Send a space via Net::Telnet?
Message-Id: <Pine.BSI.3.95.990312122339.21341A-100000@rosencrantz.citytel.net>


using pmwho for our portmasters here (its a C program) and decided to
write some perl to see if I could do it in perl but with a twist. I 
want to be able to use it for our Cisco NAS's as well...what I wrote works
for the most part but I have one small prob.

The PM3's when you do a "sho session" to see who's online and the output
goes to scroll offscreen it gives a "Hit Enter for More". Easy enough just
send a \n to continue. But the cisco you send a \n and you get the next
line only.  You have to hit the spacebar to finish the scroll and see the
rest of the who output.

Using Net::Telnet what char can I use to send a spacebar hit (for
lack of a better term?)

Thanks,
Keith





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

Date: 12 Mar 1999 22:15:01 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Send a space via Net::Telnet?
Message-Id: <slrn7ej50r.701.fl_aggie@stat.fsu.edu>

On Fri, 12 Mar 1999 12:34:50 -0800, Keith Woodworth <kwoody@citytel.net> wrote:

+ send a \n to continue. But the cisco you send a \n and you get the next
+ line only.  You have to hit the spacebar to finish the scroll and see the
+ rest of the who output.

Using the space is the way most pagers work. A ' \n' isn't, tho...

+ Using Net::Telnet what char can I use to send a spacebar hit (for
+ lack of a better term?)

Looking at the examples in the Net::Telnet documentation:

         ## Wait for first prompt and "hit return".
         $t->waitfor('/continue:.*$/');
         $t->print("");

Would seem to me that what you want is:

$t->print(" ");

James


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

Date: Thu, 11 Mar 1999 17:45:38 +0530
From: Ramanujam Parthasarathi <partha@mihy.mot.com>
To: Chim Kin Sang <mecks@ust.hk>
Subject: Re: standard input and standard error
Message-Id: <36E7B3EA.4DB0F648@mihy.mot.com>

Try the same redirection inside the system() command.

HTH
-Partha

Chim Kin Sang wrote:

> Hi,
>         I am developing some automatical weather forecast system. I have
> write a lot of
> little program, include C-Shell, C and FORTRAN. I try to put it together
> by PERL.
>
>         The problem I engaged is that when I am using the command
> system. I cannot
> put the standard output and standard error into the same file. for
> example, C-shell
> handle it by   something.exe >&! outfile
>
>         Can anyone tell me how PERL handle the same thing. I am new to
> PERL.
>
> Thanks
> Jim





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

Date: Fri, 12 Mar 1999 18:51:26 GMT
From: eldridge@graphics.stanford.edu
Subject: std{in,out,err} for Win32 processes?
Message-Id: <7cbnn9$qhv$1@nnrp1.dejanews.com>

Hi-

I'm writing up some perl utilities for managing multiple simultaneous
jobs under unix/win32.  In an ideal world, I'd like to be able to do
things like:

@args = ( 'ls', '-l' );

( $output, $input ) = FileHandle::pipe();

$pid = Foobar::Job( $input, $output, $output, @args );

$input->close();

$pid = Foobar::WaitForAny();

Foobar::WaitForPid( $pid );

And so forth.  This is all easily doable with Open3, from the Unix side of
things.

The Win32 problems with this appear to be:

1.  Win32::Process doesn't support WaitForAny, although this could be
    trivially added

2.  IPC::Open3 (which allows you to specify std{in,out,err} handles for a
    process) supports Win32, but only through the system() call, which
    provides no pid, no mechanism for waiting for jobs, etc.

Anybody out there have any suggestions?  It seems like this should be a slam
dunk, since the Win32 process creation function (CreateProcess) allows you
to specify what stdin/stdout/stderr are connected to for the new process,
so it could/should be much simpler than the Unix-ish fork/exec/dup/pipe
fiasco.

Any help much appreciated,

Thanks,

-Matthew

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


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

Date: Fri, 12 Mar 1999 14:56:49 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: The Meta-problem: helping others with Perl problems
Message-Id: <36E99BB1.B9282B84@mail.cor.epa.gov>

To all those who answer Perl questions:

Today I received an e-mail from someone to whose post I had
replied.  It was a thank-you, rather than a flame.  But..
in the middle of the post, the user mentioned that he was
able to find on the Net the answer, based on what I had said,
since he _did_not_know_what_perldoc_was_and_couldn't_find_it_.

Uh-oh.  What good does it do to tell people 'perldoc perlfaq4'
if they have no idea what we are talking about?  How do we help
people who are on systems other than their own, and are stymied
by the.. umm.. how can I put this.. the lack of Perlishness of
their ISP or their network administrator?

gnat sends out e-mails to people (who haven't munged up their
addresses for fear of canned meat byproducts) using a Perl bot.
(Or so I have assumed.)  Is it feasible to launch a copy of his
e-mail to each new poster?  If so, this could be sent from some
set point of origin which could then be put in everyone's 
killfiles so the rest of us wouldn't see such a message.  Or
is this total overkill?  His mini-FAQ may or may not help to
an extensive degree.  But it is of course impossible to evaluate
the extent of such help based only on those people who post to
c.l.p.m.  Basic sampling theory on the problem of non-response.

So.  Am I wasting my time thinking about this?  Am I wasting
*your* time posting this?  Am I wishing I had a snappy joke for
the last part of this triple?
-- 
David

David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Fri, 12 Mar 1999 15:15:44 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: David Kirwan <DKirwan@BaltimoreInc.com>
Subject: Re: why doesn't this script modify the actual file?
Message-Id: <36E975F0.7B89BCFB@giss.nasa.gov>

[courtesy copy of post sent to David]

David Kirwan wrote:
> 
> open (SRCFILE, $location) || die "couldn't open : $location\n";

you just opened "SRCFILE" for reading, not writing.

open SRCFILE, ">$location" or die "foo: $!";

> #print {SRCFILE} "some shit";
> while (<SRCFILE>) {
> 
>     print;

you want to print to "SRCFILE", right?  So,

print SRCFILE;

> 
>     if (/\$thefilename::$thefilename/) {
>         $line = 0;
>     }
>     elsif (/^\s*{\s*$/ && $line == 1) {
>         print "         CONSTRUCTOR\n";

print SRCFILE "foo";

>     }
>     $line++
> }

	Jay
-- 
"Narf!"
  --Pinky


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

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

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