[9487] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3080 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 7 12:18:26 1998

Date: Tue, 7 Jul 98 09:00:25 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 7 Jul 1998     Volume: 8 Number: 3080

Today's topics:
    Re: 'NEXT' and 'LAST' in do-until <merlyn@stonehenge.com>
    Re: 'NEXT' and 'LAST' in do-until <tchrist@mox.perl.com>
    Re: -- Picking up Extra .. Abigail, A Question for you. <dfsdf@ziplink.net>
    Re: -- Picking up Extra .. Abigail, A Question for you. (I R A Aggie)
    Re: -w on production code (was Re: better way of gettin (Abigail)
    Re: -w on production code (was Re: better way of gettin (Tina Marie Holmboe)
        Abigail - Another Question for you. <dfsdf@ziplink.net>
        backticks <peper@med-ph.uni-sb.de>
        beginners csh problem. <ubcg16u@mail.cryst.bbk.ac.uk>
    Re: CGI, Perl and the Internet Explorer <jc@ral1.zko.dec.com>
    Re: Command line argument <barnett@houston.Geco-Prakla.slb.com>
    Re: Command line argument (Tad McClellan)
    Re: Command line argument <boys@aspentech.com>
    Re: delete key from array (Abigail)
    Re: Do we need lame msgs in discussions? Re : Martien V (Tad McClellan)
    Re: Extracting portions of an HTML file using perl (Jeremy D. Zawodny)
    Re: Extracting portions of an HTML file using perl (Abigail)
        Finding a string between to known tags? <era.eraspma@mesmtp.ericsson.se>
    Re: Finding a string between to known tags? (Abigail)
        ftp list command <daniel@kupfer.demon.nl>
        Globbing from a list (Scott Erickson)
    Re: Help about Integer (Larry Rosler)
    Re: How do you delete arbitrary elements of an array in <danboo@negia.net>
    Re: How do you delete arbitrary elements of an array in (David A. Black)
    Re: How do you delete arbitrary elements of an array in <quednauf@nortel.co.uk>
    Re: How do you delete arbitrary elements of an array in <quednauf@nortel.co.uk>
    Re: How do you delete arbitrary elements of an array in <quednauf@nortel.co.uk>
    Re: How do you delete arbitrary elements of an array in (David A. Black)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 07 Jul 1998 15:06:35 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: 'NEXT' and 'LAST' in do-until
Message-Id: <8c90m5lmz7.fsf@gadget.cscaper.com>

>>>>> "Tom" == Tom Christiansen <tchrist@mox.perl.com> writes:

Tom> Here's how to do it all:

Tom>     LAST: {
Tom> 	do { NEXT: {
Tom> 	    last LAST if /whatever/;
Tom> 	    next NEXT if /whatever/;
Tom> 	    redo NEXT if /whatever/;
Tom> 	    ....
Tom> 	}} until something 
Tom>     }

And if you find that visually unappealing, just use a naked block:

	{
		...
		last if /whatever/;
		...
		redo if /whatever/;
		...
		redo unless something;
	}

There.  I use this all the time.  Remember that last/next/redo applies
to the naked block as if it was a loop that executes exactly one time.
This is one of the reasons that the Llama doesn't teach the do-while
loop: it leads to horrible uglies (as Tom illustrated nicely) when you
have to add last/next/redo.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 56 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 7 Jul 1998 15:48:02 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: 'NEXT' and 'LAST' in do-until
Message-Id: <6ntfvi$s6i$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Randal Schwartz <merlyn@stonehenge.com> writes:
:This is one of the reasons that the Llama doesn't teach the do-while
:loop: 

Ahem: see p 62 in that new-spangled blue version, which you aren't 
quite so familiar with as you are with the pink version. :-)

--tom
-- 
    "You need to go and find someone to teach you the rudiments of irrational
    discourse." --Larry Wall


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

Date: Mon, 06 Jul 1998 10:33:16 -0400
From: Webcruiser <dfsdf@ziplink.net>
Subject: Re: -- Picking up Extra .. Abigail, A Question for you.
Message-Id: <35A0E02C.796@ziplink.net>

Abigail, what do you mean you wouldn't re-open the file?


> Try something like this:
> 
>     $aidfile = "$filedirectory$AID.dta";   # "$AID" will shoot you in the foot.
>     open FILE, $aidfile or die "Eeps: $!"; # Always, always, *always* test
>                                            # the return value of open.
>     @STATUS = <FILE>;
>     close FILE;
> 
>     foreach (@STATUS) {s/^ //;}            # Remove leading space of all lines.
>                                            # Don't use C-ish for.
> 
>     open FILE, ">$aidfile" or die "Eeps: $!"; # Always, always, *always* test
>                                            # the return value of open.
>     print FILE @STATUS;                    #  @STATUS  eq join $,, @STATUS
>                                            # "@STATUS" eq join $", @STATUS
>                                            # $, eq "", $" eq " "
>                                            # That's where the spaces are coming
>                                            # from.
>     close FILE;
> 
> Of course, I wouldn't reopen the file, and I'd use locking too.
> 
> Abigail
> --
> perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: Tue, 07 Jul 1998 11:16:38 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: -- Picking up Extra .. Abigail, A Question for you.
Message-Id: <fl_aggie-0707981116380001@aggie.coaps.fsu.edu>

In article <35A0E02C.796@ziplink.net>, Webcruiser <dfsdf@ziplink.net> wrote:

+ Abigail, what do you mean you wouldn't re-open the file?

Open the file as read-write, slurp it up, seek() to the beginning of
the file, and write it back out after modifying it.

James


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

Date: 7 Jul 1998 15:16:06 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: -w on production code (was Re: better way of getting the last modified file?)
Message-Id: <6nte3m$6gl$2@client3.news.psi.net>

Tina Marie Holmboe (tina@scandinaviaonline.se) wrote on MDCCLXXI
September MCMXCIII in <URL: news:6nsva0$894$2@news1.sol.no>:
++ In article <6nra63$9in@mozo.cc.purdue.edu>,
++ 	gebis@albrecht.ecn.purdue.edu (Michael J Gebis) writes:
++ 
++ > I leave the -w flag in, but it's caused me some pain and embarassment
++ > (and other people some confusion) too.  It's a tradeoff I'm willing to
++ > take.  It probably isn't the right decision for all people or all
++ > projects.
++ 
++   I thought I'd add a comment... personally I would *strangle* anyone
++   who left -w in production code; and be tempted to be rather mean to them
++   even with development ditto.
++ 
++   This, my attitude, has a reason. My current workplace has alot of people
++   developing alot of programs meant for running by HTTP servers. It is known
++   as "CGI-programming"... :)

Your point? Does that make the programs anything special?

++   Most of the scripts written are not heavily debugged to rid themselves
++   of warnings. Like so many others I tend to tail -f the error logs when
++   I testrun CGI-script.

Oh, I see. CGI-code means worse quality!

++   And when people then use -w the net result is a furiously scrolling
++   screen, with absolutely *no* way of seeing any of the more serious
++   errors that might occur.
++ 
++ 
++   My .5c: think twice before leaving -w on production code. It might not
++   always be productive...


You shouldn't label alpha code as production code.





Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: 7 Jul 1998 15:36:41 GMT
From: tina@scandinaviaonline.se (Tina Marie Holmboe)
Subject: Re: -w on production code (was Re: better way of getting the last modified file?)
Message-Id: <6ntfa9$c7l$1@news1.sol.no>

In article <6nte3m$6gl$2@client3.news.psi.net>,
	abigail@fnx.com (Abigail) writes:

> ++   This, my attitude, has a reason. My current workplace has alot of people
> ++   developing alot of programs meant for running by HTTP servers. It is known
> ++   as "CGI-programming"... :)
> 
> Your point? Does that make the programs anything special?

  Irony *is* dead. Will there be a memorial service ?



> ++   My .5c: think twice before leaving -w on production code. It might not
> ++   always be productive...
> 
> 
> You shouldn't label alpha code as production code.

  And exactly where did I write 'alpha' in the above ? I talked about
  *production* code. I *meant* production code. Do me the courtesy of not
  suggesting meaning that is not there.

    A script is written, with -w, and works nicely with Perl 5.xxx.
    The script is put into production. with -w, and all is well.
    Perl 5.xxx is updated to 5.xxx++
    The script starts filling the errorslogs with warnings; warnings which are
     quite correct, but which makes *other* peoples lives harder.


  In other words, and again, leave off -w in *production* code. IMnsHO.


-- 
  Tina Marie Holmboe                
  Systems Programmer    (Geeks'R'Us)         [tina@tech.scandinaviaonline.se]
  WebMaster                                  [webmaster@scandinaviaonline.se]
  Scandinavia Online AB Development Dept.    (+46) 08 587 81000 (switchboard)
                                             (+46) 08 587 81189 (direct)


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

Date: Mon, 06 Jul 1998 10:57:46 -0400
From: Webcruiser <dfsdf@ziplink.net>
Subject: Abigail - Another Question for you.
Message-Id: <35A0E5EA.5C21@ziplink.net>

I installed your suggested changes, but I still get a leading white
space. Here is the code I am using for the various routines. Also, I
have a question related to some of your comments. First, the code:

Subroutine to add a new merchant to my system:
sub addmerchant{
	$aidfile = "$filedirectory$AID.dta";
	open(FILE,">$aidfile")|| die "can't open file";
	@status="New";               # All new merchants get this default
status
	$STATUS=@status[0];          # $STATUS is the variable used in the html
form.
	print FILE (@status);
	close FILE;
}

Subroutine to get the status of a merchant:
sub getstatus {
	$aidfile = "$filedirectory$AID.dta";
	open(FILE,"<$aidfile");
	@STATUS=<FILE>;
	foreach (@STATUS) {s/^ //;}   # Your suggested change.
	$numlines=@STATUS;            # my old routine to look for a leading
space.
	for ($x=1; $x<$numlines; $x++){
		if (substr($STATUS[$x],0,1) eq " "){
		$STATUS[$x]=substr($STATUS[$x],1);
		}
	}
	close FILE;
}

Subroutine to send the updateed changes as made from the html form at
http://webcruiser.com/manager/mmadmin.htm

sub updatestatus {
	$aidfile = "$filedirectory$AID.dta";
	open(FILE,">$aidfile");
	print FILE (@STATUS);
	close FILE;
}

----------------------------
Now, my question. What did you mean with these comments?

# the return value of open.
#  @STATUS  eq join $,, @STATUS
# "@STATUS" eq join $", @STATUS
# $, eq "", $" eq " "
# That's where the spaces are coming
# from.

Thanks for your assistance. I am trying to write an application that
saves me time on getting answers to my merchants who have submitted a
merchant application and call me every other day for a status.


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

Date: Tue, 07 Jul 1998 18:03:28 +0200
From: Klaus Peper <peper@med-ph.uni-sb.de>
Subject: backticks
Message-Id: <35A246D0.5AF1ECE9@med-ph.uni-sb.de>


The following code is doing wrong at our website:

$files=`ls`;
print "$files\n";

There is no print in this case, the webmaster told me that the
list goes to the monitor.

I have implemented the Simple Search by Matt as a cgi script at
my home page. The script uses similar backticks:
$ls = `ls $file`;
to scan directories.
$ls was always empty.

I decided to provide the search script with an input file
with all searchable files are indexed.
This approach works fine.

However, I still wonder why the backticks do not work?

Klaus Peper
http://www.med-rz.uni-sb.de/med_fak/physiol2/camellia/home.htm



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

Date: Tue, 7 Jul 1998 14:55:44 GMT
From: Neil Ranson <ubcg16u@mail.cryst.bbk.ac.uk>
Subject: beginners csh problem.
Message-Id: <Pine.OSF.3.96.980707155133.3019C-100000@groay.cryst.bbk.ac.uk>


I've just started learning perl and converting some csh scripts along the
way, but I've run into a problem. How do I execute a program from perl
which takes input from STDIN rather than as args?

In a csh shell I'd

	program <<eot
	$parameter1 	-  variables which have to be interpolated by perl
	$parameter2
	$parameter3
	end		- "program" exit command
	eot

Sorry, I just know that I'm being stupid but...

Cheers

*******************************************************************************
Neil Ranson.
Department of Crystallography,
Birkbeck College London,
email: n.ranson@mail.cryst.bbk.ac.uk
*******************************************************************************



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

Date: Tue, 07 Jul 1998 11:10:53 -0400
From: John Chambers <jc@ral1.zko.dec.com>
Subject: Re: CGI, Perl and the Internet Explorer
Message-Id: <35A23A7D.365CA74E@ral1.zko.dec.com>

schlecno@my-dejanews.com wrote:
> 
> I have a newbie-question which was surely asked many times before, but
> i was not able to fix that problem, yet.
> 
> I try to run a Perl program with CGI under WinowsNT 4.0. A Personal WebServer
> is installed and i created a directory named cgi-bin in that server directory.
> 
> My HTML script is a simple form:
> 
> <form action="formtest1.pl" method="POST">

Most likely problem is right here.  You gave a URL of "formtest1.pl for the
action.  There's no hostname or directory or anything there, so your browser
is going to send in a request for formtest1.pl in the same directory where
the html file was located.  This was presumably not the cgi-bin directory,
so "formtest1.pl" won't be found.

You need something like action="/cgi-bin/formtest1.pl".

Figuring out how to type the URLs so that the server looks in the right
place turns out to be one of the ongoing time wasters in web development.
Even old timers (i.e., people with more than 6 months experience ;-) spend
a lot of time baffled by why things aren't found.  What you need to do is
learn where the server keeps its log files, in particular its error-log
file, and keep a window open that's showing you the tail end of that
file.  It'll help you a lot.  And you'll spend some time staring at it
in disbelief, asking "Why the @#$*&^* did it look THERE?"

(I've never run the NT Personal WebServer.  Can anyone give this fellow
a good clue for how to monitor this server's log files?)


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

Date: Tue, 07 Jul 1998 08:28:12 -0500
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
To: Naama Kraus <naamah@haifa.vnet.ibm.com>
Subject: Re: Command line argument
Message-Id: <35A2226C.620CC7D8@houston.Geco-Prakla.slb.com>

[courtesy CC to cited author]

Naama Kraus wrote:
> 
> Hi!
> Here is a simple program (named my_prog) which reads a command line
> argument:
> 
> if (@ARGV) {
>     $a = shift;
> }
> 
> Now, when running:
>  > my_prog abc*
> I receive the error:
> > my_prog: No match
> No error occurs when running:
> > my_prog "abc*"
> 
> Can anyone help me understand the meaning of abc* as a command line
> argument ?
I'm going to assume unix, since you speak of command line arguments. 
(My comments probably hold true for DOS/Windows, but...)

In unix, * is a special typeglob character that will match any character
(and any number of them).  What is happening is that your shell (sh,
csh, tcsh, zsh, ???) is seeing the abc*, and is trying to match files in
your current directory for inclusion as command line arguments.

Apparently, there are no abc1, abc2, abcdefg, etc. files in your current
directory.

I don't really know why "abc*" would work, but it must be shell
dependent (and possibly OS dependent as well).  It works this way for me
under tcsh.

> 
>  -Thanx in advance,
>       - Naama.
HTH.

Dave

-- 
"Security through obscurity is no security at all."
		-comp.lang.perl.misc newsgroup posting

----------------------------------------------------------------------
Dave Barnett                 U.S.: barnett@houston.Geco-Prakla.slb.com
DAPD Software Support Eng    U.K.: barnett@gatwick.Geco-Prakla.slb.com
----------------------------------------------------------------------


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

Date: Tue, 7 Jul 1998 10:03:45 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Command line argument
Message-Id: <hcdtn6.frv.ln@localhost>

Naama Kraus (naamah@haifa.vnet.ibm.com) wrote:

: Now, when running:
:  > my_prog abc*
: I receive the error:
: > my_prog: No match


Because the shell does its thing with command line arguments *before*
calling perl.

Since you have a wildcard there, the shell tries to expand it.

It appears that you do not have any files in the current directory
that happen to start with 'abc'...

That is a message from the *shell*, not from perl.



: No error occurs when running:
: > my_prog "abc*"

Because the shell does not look for wildcards within quoted strings.


: Can anyone help me understand the meaning of abc* as a command line
: argument ?

Hope that does it.

If not, ask over in unix.questions or a shell newsgroup. It is not
a Perl question, since it happens before perl is ever invoked.



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


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

Date: Tue, 07 Jul 1998 16:19:05 +0100
From: Ian Boys <boys@aspentech.com>
Subject: Re: Command line argument
Message-Id: <35A23C69.63DE@aspentech.com>

Calle Dybedahl wrote:
> 
> Naama Kraus <naamah@haifa.vnet.ibm.com> writes:
> 
> > Now, when running:
> > > my_prog abc*
> > I receive the error:
> > my_prog: No match
> >
> > Can anyone help me understand the meaning of abc* as a command line
> > argument ?
> 
> This is a Unix-shell question, not a Perl question. Get a beginner's
> guide to Unix.

Hmmm, very helpful answer (not).

Naama: The command shell tries to expand abc* with matching file names
before calling the perl script.  When it can't find any matching files
it gives the error you see.  It is misleading because 

my_prog: No match

makes you think the error comes from my_prog, instead of the shell. But
your program has not even thought about beginning to run when this
message gets printed.

<Digression>

Can any Unix gurus tell my why this isn't a bug, or at least a
mis-feature?  If the error comes from (say) sh, then why isn't the
message

sh: No match

OK, I guess it goes way back and there was a good reason at the time.

</Digression>

Ian


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

Date: 7 Jul 1998 15:20:42 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: delete key from array
Message-Id: <6nteca$6gl$3@client3.news.psi.net>

dwiesel@my-dejanews.com (dwiesel@my-dejanews.com) wrote on MDCCLXXI
September MCMXCIII in <URL: news:6nsqfq$bhf$1@nnrp1.dejanews.com>:
++ Hi.
++ 
++ I don't seem to find the (probably) simple answer...
++ 
++ I have an array and want to delete a key from it
++ 
++ @array = ("hallo", "hallo2");
++ 
++ how do I delete $array[1] so that the arrays new look is ("hallo2") ???


But $array [1] eq 'hallo2'!


Perhaps you want to delete the first element?   Use shift.
Perhaps you want to delete the last element?    Use pop.
Perhaps you want to delete a range of elements? Use splice.
Perhaps you want to delete certain values?      Use grep.



Abigail
-- 
perl -MNet::Dict -we '(Net::Dict -> new (server => "dict.org")\n-> define ("foldoc", "perl")) [0] -> print'


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

Date: Tue, 7 Jul 1998 09:57:48 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Do we need lame msgs in discussions? Re : Martien Verbruggen
Message-Id: <c1dtn6.frv.ln@localhost>

F.Quednau (quednauf@nortel.co.uk) wrote:
: Azman Shariff wrote:
: > 
: > 
: > The question here is "Do we need his kind of replies to questions posed?"
: > Let's
: > face the facts.... what you know doesn't mean wha another person knows!

: A flame might help the relevant person to get up to date with the documentation.

: > Yes ... i do agree at times there are some or quiet a lot totally
: > irrelvant stupid
: > and totally frustrating messages! But can't we just ignore it? 
                                                        ^^^^^^^^^
                                                        ^^^^^^^^^

   And let them wallow in ignorance?

   There's plenty of ignorance already  ;-)

   Showing a method that gets answers often and quickly (eg. check the FAQ)
   will help with both the silly questioner's Question Of The Day,
   and with nearly all of their future questions!

   I think they should know about such a valuable resource...


: > Why take
: > the trouble
: > to answer with a remark? We are helping each other, and not to flame
: > each other!

: I just don't understand why people are so sensitive about flames. Are there
: people out there who have never been told off to touch the fire, or similar
: things?


   Would you remain silent if someone took cuts in line?


   I have this enshrined on my hard drive:

In article <1995Nov9.193745.13694@netlabs.com>, lwall@netlabs.com (Larry
Wall) wrote: ...

<Larry>  [snip]  I view a programming language as a place to be
<Larry>  explored, like Disneyland. You don't need to have a lot of preparation
<Larry>  to explore a theme park.  You do have to go along with the crowd
<Larry>  control measures, though.  In a sense, each ride has its own
<Larry>  prerequisites--if you cut in line, you risk getting tossed out of the
<Larry>  park.
<Larry> 
<Larry>  What we have here in this newsgroup is a failure in crowd control.
<Larry>  Reading the FAQ is like staying in line--it's something you should
<Larry>  learn in kindergarten.  Usenet needs a better kindergarten.



   What seem's Twilight Zone to me is the often heard response from
   the newbie that didn't know about checking resources before
   posting that goes something like:

      That's a stupid rule. I don't care that the rule evolved over
      about 20 *years* of Usenet society. I just got here, and it is
      a stupid rule, and I'll take cuts whenever I please, and you
      can't stop me, so there!


   In normal face-to-face society I would expect something more like:

      Oh. I didn't know that you were supposed to go to the end of 
      the line. Sorry.


   Strange...


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


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

Date: Tue, 07 Jul 1998 15:04:24 GMT
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: Extracting portions of an HTML file using perl
Message-Id: <35a338de.7175157@192.70.218.1>

[original author automagically cc'd via e-mail]

On Tue, 7 Jul 1998 12:50:25 +0100, "Phil Clark"
<phil.clark@takethisbitout.tpd.co.uk> wrote:

>Can someone tell me how to extract a portion of an HTML file in perl? For
>example the <HEAD> ........ </HEAD> section - I want to extract just the
>text in the middle of the tags, and not the tags themselves, nor anything
>outside the tags.

Use one of the HTML parsing module available on CPAN.

>Would that be easy to do in perl?

Yes.

Jeremy
-- 
Jeremy D. Zawodny                 jzawodn@wcnet.org
Web Server Administrator          www@wcnet.org
Wood County Free Net (Ohio)       http://www.wcnet.org/


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

Date: 7 Jul 1998 15:26:40 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Extracting portions of an HTML file using perl
Message-Id: <6nteng$6gl$4@client3.news.psi.net>

Phil Clark (phil.clark@takethisbitout.tpd.co.uk) wrote on MDCCLXXI
September MCMXCIII in <URL: news:a12tn6.av4.ln@gate.tpd.co.uk>:
++ Folks
++ 
++ This should be a simple request ...
++ 
++ Can someone tell me how to extract a portion of an HTML file in perl? For
++ example the <HEAD> ........ </HEAD> section - I want to extract just the
++ text in the middle of the tags, and not the tags themselves, nor anything
++ outside the tags.
++ 
++ Would that be easy to do in perl?


Someone will undoubtely post something like 

     m{<HEAD>(.*)</HEAD>}s
     # $1 is now the text you want.

They are, of course, wrong. It will work for the all the test files
you try it on - but you'll get bitten soon after releasing the code.

You need a parser to parse HTML. Get HTML::Parser from your friendly
CPAN dealer.




Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


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

Date: Tue, 07 Jul 1998 16:13:19 +0200
From: Marcus Spangenberg <era.eraspma@mesmtp.ericsson.se>
Subject: Finding a string between to known tags?
Message-Id: <35A22CFF.C1E7105B@mesmtp.ericsson.se>

How do I find a string from a file that is located between a known
start-tag and a known end-tag?

/Marcus



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

Date: 7 Jul 1998 15:27:43 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Finding a string between to known tags?
Message-Id: <6ntepf$6gl$5@client3.news.psi.net>

Marcus Spangenberg (era.eraspma@mesmtp.ericsson.se) wrote on MDCCLXXI
September MCMXCIII in <URL: news:35A22CFF.C1E7105B@mesmtp.ericsson.se>:
++ How do I find a string from a file that is located between a known
++ start-tag and a known end-tag?


Unsufficient information.


*What* tags, and what format is the file?



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


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

Date: Tue, 07 Jul 1998 16:05:18 -0700
From: Daniel Kupfer <daniel@kupfer.demon.nl>
Subject: ftp list command
Message-Id: <35A2A9AE.A62AD8AA@kupfer.demon.nl>

Can someone tell me how to use the list-command using (requiring)
ftp2.pl?

Thanks,


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

Date: Tue, 07 Jul 1998 15:54:59 GMT
From: Scott.L.Erickson@HealthPartners.com (Scott Erickson)
Subject: Globbing from a list
Message-Id: <35a2421b.521184353@news.mr.net>


Here is what I want to do: I want to apply a glob-like function to a
list, not the current directory. I want the simplicity of basic
filename expansion such that if I have a list of filenames, I can pull
out only those that match a given pattern. I am trying to avoid using
regular expressions as the pattern because this will be used by others
who are weak with regards to regexs, but okay with filename expansion
(i.e., *.jpg).

Is there a module that does such? I searched CPAN, but if it is there,
I did not find. I thought about creating such a function and using
regexs to simulate the effect of filename expansion, but if I can
avoid reinventing the wheel this time, I would be happy.

I also checked the FAQ, but found no reference to such an endeavor and
I did not find what I needed in the Camel book. So, if I missed it
somewhere in the FAQ or Camel book, please give me a pointer so that I
may look for myself.

Your help is appreciated,
Scott Erickson.


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

Date: Tue, 7 Jul 1998 07:59:05 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Help about Integer
Message-Id: <MPG.100bd7938f47be9098971b@nntp.hpl.hp.com>

In article <35A1F8D8.5A2E190D@wanadoo.com> on Tue, 07 Jul 1998 12:30:48 
+0200, Eric Zylberstejn <Eric.Zylberstejn@wanadoo.com> says...
> Hello,
> 
> Sergi Bech wrote:
> > 
> > How can I round a decimal value?
> > 
> > sample:
> > 
> > 5.6666 --- > 6
> > 4.3333 ----> 4
> 
> $a = 5.6666;
> $b = 4.3333;
> 
> $rounded_a = int ($a + 0.5);
> $rounded_b = int ($b + 0.5);
> 
> print "$rounded_a, $rounded_b\n";

This works wrong for negative numbers.  The harder way is to use

$rounded_a = int ($a + ($a > 0 ? 0.5 : -0.5));

The easier way is to use sprintf, as others have shown.

> 	Ericbegin:          vcard
 ...

Please don't use this in future postings.

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


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

Date: Tue, 07 Jul 1998 10:04:44 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: How do you delete arbitrary elements of an array in one go?
Message-Id: <35A22AFC.52B99A0F@negia.net>

F.Quednau wrote:
> 
> F.Quednau wrote:
> > sub splice_around {
> >   my $i = 0;
> >   foreach (@_) { splice(@arr, ($_-$i), 1); $i++;}
> > }
> 
> Won't work if the list of elements to be deleted comes in unordered, like
> splice_around(6,2)
> 
> sub splice_around {
>   my $i = 0;
>   @args = @_;
>   foreach (sort @args) { splice(@arr, ($_-$i), 1); $i++;}
> }
> 
> Would do the job. Interestingly, one can't use a sort on @_. I am not exactly
> sure, why...It would probably confuse something a lot.

two more problems and one suggestion. first off, you're still going
to have problems if duplicate arguments are provided. you really need to
do a unique sort. also, your sort is lexical when it should be numeric.
and i'm not sure what problem you were having, but sorting on @_ should
not be a problem. and as a suggestion i would pass a reference to the
target array in as the first arg. that way the sub doesn't have to have
knowledge of the array name.

@arr = qw/ 0 first second third fourth fith sixth seventh eight ninth /;

sub splice_around {
  my $target = shift;
  my $i = 0;
  @_ = sort { $a <=> $b } keys %{ { map {$_,1} @_ } };
  foreach (@_) { splice(@$target, ($_-$i++), 1); }
}

&splice_around(\@arr, 0,12,5,5,6);

foreach (@arr) {
  print "$_ - ";
}

and for the sake of TIMTOWTDI, how about:

sub splice_around {
  my ($target, $i, %bad) = (shift, 0);
  @bad{@_} = ();
  @$target = grep ! exists $bad{$i++}, @$target;
}

it should also run a good bit faster than the one above.

cheers,

-- 
Dan Boorstein   home: danboo@negia.net  work: danboo@y-dna.com

 "THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
                         - Cosmic AC


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

Date: Tue,  7 Jul 1998 10:25:20 EDT
From: dblack@saturn.superlink.net (David A. Black)
Subject: Re: How do you delete arbitrary elements of an array in one go?
Message-Id: <6ntb4g$fve$1@earth.superlink.net>

Hello -

"F.Quednau" <quednauf@nortel.co.uk> writes:

>Would do the job. Interestingly, one can't use a sort on @_. I am not exactly
>sure, why...It would probably confuse something a lot.


?

#!/usr/local/bin/perl -w

sub sort_me { sort @_ }

print sort_me (5,4,1,3,6), "\n";


Output:

13456


Looks pretty sorted to me.


David Black
dblack@saturn.superlink.net


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

Date: Tue, 07 Jul 1998 15:53:00 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: How do you delete arbitrary elements of an array in one go?
Message-Id: <35A2364B.AE559043@nortel.co.uk>

F.Quednau wrote:
>   foreach (sort @args) { splice(@arr, ($_-$i), 1); $i++;}

Ouch, I had it in front of me! Sometimes you don't see the forest because of the
many trees. A mail that I got stated the following:

for (sort {$b <=> $a} @args) { splice(@arr, $_, 1);}

Much nicer, cheers!


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

Date: Tue, 07 Jul 1998 16:02:30 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: How do you delete arbitrary elements of an array in one go?
Message-Id: <35A23886.136A3E56@nortel.co.uk>

Dan Boorstein wrote:
> 
> and for the sake of TIMTOWTDI, how about:
> 
> sub splice_around {
>   my ($target, $i, %bad) = (shift, 0);
>   @bad{@_} = ();
>   @$target = grep ! exists $bad{$i++}, @$target;
> }

Coool!!

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Tue, 07 Jul 1998 16:09:34 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: How do you delete arbitrary elements of an array in one go?
Message-Id: <35A23A2E.1DF445F@nortel.co.uk>

David A. Black wrote:
> 
> ?
> 
> #!/usr/local/bin/perl -w
> 
> sub sort_me { sort @_ }
> 
> print sort_me (5,4,1,3,6), "\n";
> 
> Output:
> 
> 13456
> 
> Looks pretty sorted to me.

Yes, indeed. I said that above because of the following:

sub sorthing {
   my @arr = @_; 
   for (sort @_) { print $_;}
   for (sort @arr) { print $_;}
}


&sorthing(5,4,6);

Gives: 546456

What happens there??
-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Tue,  7 Jul 1998 11:28:59 EDT
From: dblack@saturn.superlink.net (David A. Black)
Subject: Re: How do you delete arbitrary elements of an array in one go?
Message-Id: <6nterr$nvl$1@earth.superlink.net>

Hello -

"F.Quednau" <quednauf@nortel.co.uk> writes:

>Yes, indeed. I said that above because of the following:

>sub sorthing {
>   my @arr = @_; 
>   for (sort @_) { print $_;}
>   for (sort @arr) { print $_;}
>}


>&sorthing(5,4,6);

>Gives: 546456


I can't duplicate that:

candle:~/hacking/perl$ perl -w
sub sorthing {
   my @arr = @_;
   for (sort @_) { print $_;}
   for (sort @arr) { print $_;}
}


&sorthing(5,4,6);
^D
456456


David Black
dblack@saturn.superlink.net


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.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 3080
**************************************

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