[15866] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3279 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 7 18:06:40 2000

Date: Wed, 7 Jun 2000 15:05:29 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <960415529-v9-i3279@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 7 Jun 2000     Volume: 9 Number: 3279

Today's topics:
    Re: Anoymous hash slices <makarand_kulkarni@My-Deja.com>
    Re: Anoymous hash slices <makarand_kulkarni@My-Deja.com>
    Re: Anoymous hash slices <lr@hpl.hp.com>
    Re: Aol coockie: date error <lr@hpl.hp.com>
    Re: Best Way to Test if File Exists (Brandon Metcalf)
        Calling perl module from C <hmerrill@my-deja.com>
    Re: Calling perl module from C <care227@attglobal.net>
        cgi.pm (name)
    Re: cgi.pm <lr@hpl.hp.com>
        CGI::Cookie or HTTP::Cookie <grichard@uci.edu>
    Re: CGI::Cookie or HTTP::Cookie <lauren_smith13@hotmail.com>
    Re: change priority (Clinton A. Pierce)
        COM/OCX <chris.wrightNOchSPAM@pictureiq.com.invalid>
        connect() timeouts in perl <docurizen@my-deja.com>
        Content-type header to Set Cookie <norbert@NOSPAMcontrex-us.com>
    Re: Content-type header to Set Cookie <sariq@texas.net>
    Re: getpwent with duplicate UIDs <gellyfish@gellyfish.com>
        Help with a simple regular expression <dana_hartley@nospam.hotmail.com>
    Re: Help with a simple regular expression <lauren_smith13@hotmail.com>
    Re: Help with a simple regular expression <hmerrill@my-deja.com>
    Re: Help with a simple regular expression <dana_hartley@nospam.hotmail.com>
    Re: Help with a simple regular expression <lauren_smith13@hotmail.com>
    Re: Help with a simple regular expression <lr@hpl.hp.com>
    Re: Help with a simple regular expression <godzilla@stomp.stomp.tokyo>
    Re: Help with OO needed. (James Kufrovich)
    Re: Help with OO needed. <aqumsieh@hyperchip.com>
        help with specPerl <tlanierNOtlSPAM@atmel.com.invalid>
        Help with writing to other program gthorne777@my-deja.com
    Re: how to write on a file? <lr@hpl.hp.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 07 Jun 2000 12:09:10 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: Anoymous hash slices
Message-Id: <393E9DD6.812CB3F0@My-Deja.com>

>     @array = map { my %hash;
>           @hash{qw(cost flavor texture)} = split /\|/; \%hash } @lines;
>
> or, equivalently,
>
>     @array = map { my $href = { };
>           @$href{qw(cost flavor texture)} = split /\|/; $href } @lines;
>
> or, differently,
>
>     @array = map { my @a = split /\|/;
>           { cost => $a[0], flavor => $a[1], texture => $a[2] } } @lines;
>

All the above are just variations of what Tim wrote inside the For loop.
The contents of for () are now inside map.Other than that there is no difference.




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

Date: Wed, 07 Jun 2000 12:09:18 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: Anoymous hash slices
Message-Id: <393E9DDE.FDFA8141@My-Deja.com>

>     @array = map { my %hash;
>           @hash{qw(cost flavor texture)} = split /\|/; \%hash } @lines;
>
> or, equivalently,
>
>     @array = map { my $href = { };
>           @$href{qw(cost flavor texture)} = split /\|/; $href } @lines;
>
> or, differently,
>
>     @array = map { my @a = split /\|/;
>           { cost => $a[0], flavor => $a[1], texture => $a[2] } } @lines;
>

All the above are just variations of what Tim wrote inside the For loop.
The contents of for () are now inside map.Other than that there is no difference.




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

Date: Wed, 7 Jun 2000 13:27:41 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Anoymous hash slices
Message-Id: <MPG.13a850161e6e2ab298ab3c@nntp.hpl.hp.com>

In article <393E9DD6.812CB3F0@My-Deja.com> on Wed, 07 Jun 2000 12:09:10 
-0700, Makarand Kulkarni <makarand_kulkarni@My-Deja.com> says...
> >     @array = map { my %hash;
> >           @hash{qw(cost flavor texture)} = split /\|/; \%hash } @lines;
> >
> > or, equivalently,
> >
> >     @array = map { my $href = { };
> >           @$href{qw(cost flavor texture)} = split /\|/; $href } @lines;
> >
> > or, differently,
> >
> >     @array = map { my @a = split /\|/;
> >           { cost => $a[0], flavor => $a[1], texture => $a[2] } } @lines;
> >
> 
> All the above are just variations of what Tim wrote inside the For loop.
> The contents of for () are now inside map.Other than that there is no difference.

You quoted me (and posted twice) without attribution, so I thought I'd 
add in the sentence you omitted to quote, right above that code:

In article <MPG.13a73254c859a91f98ab2f@nntp.hpl.hp.com> on Tue, 6 Jun 
2000 17:08:28 -0700, Larry Rosler <lr@hpl.hp.com> says...

 ...

> As for the question you actually asked, I don't think it would be any 
> better than your loop, because you need two different accesses to the 
> hash.

As I said, the map() approach isn't any better than the for loop (though 
I imagine a map() assignment to an array is somewhat faster than 
multiple pushes).  But it is a lot better than the code you posted, 
which calls three splits where one would do.

The original poster asked, in effect, if he could do this list-of-hashes 
initialization without using named temporaries.  I showed three 
different types of named temporaries, but still don't see an efficient 
solution that uses none.

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


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

Date: Wed, 7 Jun 2000 12:06:28 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Aol coockie: date error
Message-Id: <MPG.13a83d0bd6ad41ad98ab38@nntp.hpl.hp.com>

In article <1ebv8d5.1901a5wxc89qeN%tony@svanstrom.com> on Wed, 7 Jun 
2000 17:00:06 +0200, Tony L. Svanstrom <tony@svanstrom.com> says...

 ...

>    my $cookietime = "@days[$temptime[6]], $temptime[3]-@months[$temptime[4]]-".
>         ($temptime[5]+1900) . " "; my @ends = (':',':',' GMT',);

The '-w' flag would warn you about the two incorrect accesses to those 
array elements.

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


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

Date: 7 Jun 2000 18:10:09 GMT
From: bmetcalf@baynetworks.com (Brandon Metcalf)
Subject: Re: Best Way to Test if File Exists
Message-Id: <8hm361$c96$1@spinner.corpeast.baynetworks.com>

grichard@uci.edu writes:

 > I'm sure there is a better way to do this, but I want to test if a file
 > exists. Below is what I'm currently doing, if there's is a better way please
 > tell me and/or direct me to the relevant doc.
 > 
 > if (open(FILE, $file)) {
 >     close FILE;
 >     do stuff;
 > }

if (-e $file)

Brandon


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

Date: Wed, 07 Jun 2000 20:20:21 GMT
From: Hardy Merrill <hmerrill@my-deja.com>
Subject: Calling perl module from C
Message-Id: <8hmapi$hch$1@nnrp1.deja.com>

When trying to compile a C program that executes a Perl subroutine, the
C compiler is not able to find "EXTERN.h" nor "perl.h", even though we
are specifying the CORE directory with -I switch in the compile line:

cc -I/usr/lib/perl5/5.00503/i386-linux/CORE
-L/usr/lib/perl5/5.500503/i386-linux/CORE -o myfile myfile.o

Has anyone else been able to successfully implement invoking a Perl
subroutine from a C program?  What are we missing?

Thanks.

--
Hardy Merrill
Mission Critical Linux
http://www.missioncriticallinux.com


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 07 Jun 2000 16:39:52 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Calling perl module from C
Message-Id: <393EB318.A11DEDCF@attglobal.net>

Hardy Merrill wrote:
> 
> 
> cc -I/usr/lib/perl5/5.00503/i386-linux/CORE
> -L/usr/lib/perl5/5.500503/i386-linux/CORE -o myfile myfile.o
> 
> Has anyone else been able to successfully implement invoking a Perl
> subroutine from a C program?  What are we missing?
> 

Did you check out the documentation at:

http://www.perl.com/pub/doc/manual/html/pod/perlembed.html

called "How to embed perl in your C program"?


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

Date: Wed, 07 Jun 2000 20:40:17 GMT
From: jobs@craigslist.net (name)
Subject: cgi.pm
Message-Id: <Rqy%4.1408$ee3.97250@bgtnsc04-news.ops.worldnet.att.net>

cgi.pm



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

Date: Wed, 7 Jun 2000 13:57:25 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: cgi.pm
Message-Id: <MPG.13a8570d7bca6b1998ab40@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <Rqy%4.1408$ee3.97250@bgtnsc04-news.ops.worldnet.att.net> on 
Wed, 07 Jun 2000 20:40:17 GMT, name <jobs@craigslist.net> says...
> cgi.pm

No, CGI.pm even in case-independent file syatems.

And your question is?

BTW, you meant to use the 'Reply-To:' header to ask for email responses.  
'Followup-To:' messes with the newsgroup.  But I did what you requested 
anyhow.

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


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

Date: Wed, 7 Jun 2000 11:42:16 -0700
From: "Gabe" <grichard@uci.edu>
Subject: CGI::Cookie or HTTP::Cookie
Message-Id: <8hm59f$9l2$1@news.service.uci.edu>

These modules seem to do pretty much the same thing. Which is preferred?
Why?

Gabe




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

Date: Wed, 7 Jun 2000 11:59:47 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: CGI::Cookie or HTTP::Cookie
Message-Id: <8hm61r$4j$1@brokaw.wa.com>


Gabe <grichard@uci.edu> wrote in message
news:8hm59f$9l2$1@news.service.uci.edu...
> These modules seem to do pretty much the same thing. Which is preferred?
> Why?

The HTTP modules seem to be designed for working with raw HTTP, while the
CGI module is designed for those writing CGI programs.

Lauren





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

Date: Wed, 07 Jun 2000 21:52:38 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: change priority
Message-Id: <Guz%4.101994$h01.806011@news1.rdc1.mi.home.com>

[Posted and mailed]

In article <8hlv9k$gvf$1@news.sovam.com>,
	"Roman Chumakov" <zfido88@zr.ru> writes:
> I need to low priority for executing a perl script.
> 
> How a perl script can do it itself?
> May a perlscript to low itself priority? If yes - How?

perldoc -f setpriority



-- 
-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours! 
  clintp@geeksalad.org         for details see http://www.geeksalad.org
"If you rush a Miracle Man, 
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Wed, 07 Jun 2000 14:37:52 -0700
From: chris <chris.wrightNOchSPAM@pictureiq.com.invalid>
Subject: COM/OCX
Message-Id: <200814db.70ce5676@usw-ex0101-005.remarq.com>

Can anyone point me to a perl module for using perl to interact
with MS COM/OCX objects.

Thanks,

Chris

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



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

Date: Wed, 07 Jun 2000 20:34:51 GMT
From: Dr. Ari D Jordon DD <docurizen@my-deja.com>
Subject: connect() timeouts in perl
Message-Id: <8hmbl9$hu2$1@nnrp1.deja.com>

I am currently working on a simple network monitoring package for our
network (basically just checking for connectivity).  The script I have
so far works fine internally; machines that are up either succeed or set
errno to ECONNREFUSED, down machines give EHOSTUNREACH, all of which is
easy to check speedily (takes about 3 seconds for a failure to give
EHOSTUNREACH).

however, when the script is run externally, it's taking over 10 minutes
for connections to time out on addresses that are not responding (ones
that are up still respond nearly instantly).  Considering I'm monitoring
an entire class C network, it takes too long to do externally.  Is there
any way to change how long connect() waits before giving up?  This is
under perl 5.005 in both cases, on Linux 2.2.15 internally, and 2.2.14
externally.  Any suggestions would be appreciated.

--
And when the last Lear jet had left, the towers of Illium finally burned
With the acrid stench of molten glass against a night sky lit livid with
That raw wound purple that signals the end of everything.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 7 Jun 2000 17:47:16 -0400
From: Norbert Wienholz <norbert@NOSPAMcontrex-us.com>
Subject: Content-type header to Set Cookie
Message-Id: <MPG.13a88cf082de4463989682@news.sover.net>

Can I reset the Content-Type after outputting some HTML
(where it was set to text/html), to be able to set a cookie
afterwards?
Rearranging the code to set the cookie before would be
very inefficient in this case.

print "Content-type: text/html\n\n";
print "...HTML CODE..."
print "Set-Cookie: name=$name; expires=$expire;\n";
   [This way it prints out the Set-Cookie command]

(I don't want to use CGI.pm. I'm still learning
Perl and would like to know what's happening.)

Thanks,

Norbert


-- 
remove NOSPAM from address to reply directly


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

Date: Wed, 07 Jun 2000 16:59:03 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Content-type header to Set Cookie
Message-Id: <393EC5A7.D8D9F2E1@texas.net>

Norbert Wienholz wrote:
> 
> Can I reset the Content-Type after outputting some HTML
> (where it was set to text/html), to be able to set a cookie
> afterwards?
> Rearranging the code to set the cookie before would be
> very inefficient in this case.
> 
> print "Content-type: text/html\n\n";
> print "...HTML CODE..."
> print "Set-Cookie: name=$name; expires=$expire;\n";
>    [This way it prints out the Set-Cookie command]

The language you choose for the program is irrelevant.  Ask in a group
which discusses HTML.

> (I don't want to use CGI.pm. I'm still learning
> Perl and would like to know what's happening.)

With that logic, I assume the code above uses your own print() routine.

- Tom


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

Date: 7 Jun 2000 20:39:47 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: getpwent with duplicate UIDs
Message-Id: <8hm8e3$knd$1@orpheus.gellyfish.com>

On Mon, 05 Jun 2000 20:53:14 GMT Sweth Chandramouli wrote:
> 	It appears that getpwent slurps in passwd info
> from the appropriate source and stores it in a hash keyed on UID; as a
> result, duplicate UIDs (such as a second UID 0 account for admin use)
> don't appear in an enumeration.  Is this a) a bug, and b) avoidable without
> doing kludgy things like parsing nsswitch and then enumerating the relevant
> data source manually?
> 

A cursory examintation of the code would make me say that this isnt the
case and a small test viz :

while(@foo = getpwent())
{
   print "@foo\n";
}

shows that it definitely isnt :

tdcjs x 202 202   Login for my NFS at work /home/tdcjs /bin/bash
foo x 202 502    /home/foo /bin/bash

Of course it might be your OS or C library or whatever.  Trying to get
users with the UID of 202 obviously results in only the first one being
returned though.

What version of Perl and what OS are you using ?

/J\
-- 
Yes, honey...Just squeeze your rage up into a bitter little ball and
release it at an appropriate time, like that day I hit the referee with
the whiskey bottle.
-- 
fortune oscar homer


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

Date: Wed, 7 Jun 2000 14:10:35 -0400
From: "Dana H" <dana_hartley@nospam.hotmail.com>
Subject: Help with a simple regular expression
Message-Id: <393e8ff6$1$155$39368dfe@news.twtelecom.net>

I have a problem that I know PERL can easily do, but I just cannot get it to
work.

I want to use PERL to extract all of the values from a XML file...meaning I
want it to parse the entire text file, outputting a list of anything that is
between the "" characters and the >< characters. That should give me a list
of all of the values and attributes in my document.

Any help would be appreciated.




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

Date: Wed, 7 Jun 2000 11:38:48 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: Help with a simple regular expression
Message-Id: <8hm4qf$v3s$1@brokaw.wa.com>


Dana H <dana_hartley@nospam.hotmail.com> wrote in message
news:393e8ff6$1$155$39368dfe@news.twtelecom.net...
> I have a problem that I know PERL can easily do, but I just cannot get it
to
> work.
>
> I want to use PERL to extract all of the values from a XML file...meaning
I
> want it to parse the entire text file, outputting a list of anything that
is
> between the "" characters and the >< characters. That should give me a
list
> of all of the values and attributes in my document.

I'm not sure you want to use a regular expression here.  Try looking at the
XML::Parser.

perldoc XML::Parser

Lauren





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

Date: Wed, 07 Jun 2000 20:15:02 GMT
From: Hardy Merrill <hmerrill@my-deja.com>
Subject: Re: Help with a simple regular expression
Message-Id: <8hmafm$h03$1@nnrp1.deja.com>

In article <8hm4qf$v3s$1@brokaw.wa.com>,
  "Lauren Smith" <lauren_smith13@hotmail.com> wrote:
>
> Dana H <dana_hartley@nospam.hotmail.com> wrote in message
> news:393e8ff6$1$155$39368dfe@news.twtelecom.net...
> > I have a problem that I know PERL can easily do, but I just cannot
get it
> to
> > work.
> >
> > I want to use PERL to extract all of the values from a XML
file...meaning
> I
> > want it to parse the entire text file, outputting a list of anything
that
> is
> > between the "" characters and the >< characters. That should give me
a
> list
> > of all of the values and attributes in my document.
>
> I'm not sure you want to use a regular expression here.  Try looking
at the
> XML::Parser.
>
> perldoc XML::Parser

I'm running Perl 5.005_03 and XML::Parser is not included in the
standard distribution.  But you can find the module at any
CPAN(Comprehensive Perl Archive Network) mirror - one location is at
www.perl.com/CPAN-local/README.html.  You will find that there are a lot
of XML modules at CPAN.

Hope this helps.

--
Hardy Merrill
Mission Critical Linux
http://www.missioncriticallinux.com


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 7 Jun 2000 16:25:06 -0400
From: "Dana H" <dana_hartley@nospam.hotmail.com>
Subject: Re: Help with a simple regular expression
Message-Id: <393eaf48$0$152$39368dfe@news.twtelecom.net>

> > I have a problem that I know PERL can easily do, but I just cannot get
it
> to
> > work.
> >
> > I want to use PERL to extract all of the values from a XML
file...meaning
> I
> > want it to parse the entire text file, outputting a list of anything
that
> is
> > between the "" characters and the >< characters. That should give me a
> list
> > of all of the values and attributes in my document.
>
> I'm not sure you want to use a regular expression here.  Try looking at
the
> XML::Parser.
>
> perldoc XML::Parser
>
> Lauren

Thanks for the tip, Lauren, but I don't think that will work. The problem is
that the XML files that I am going to be looking at are not guaranteed to be
well formed or even valid. I've tried some other XML parsers, but when I
found out that the files I was working with may not be 100% XML, I started
thinking a regular expression route. I only need to get the values out and
into a list.

I'm not that experienced with PERL, but have been trying to do it by writing
the entire file to a string variable, $input. Then I tried using @matches =
$input =~ />.*?</gs. It matched the first occurance of the match, but no
others. It also left the >< on the values so they displayed like >value<...I
don't know how to do a regular expression in PERL and not include the angle
brackets.

I'm frusterated with it and will probably end up using C++ (which I'm more
familiar with) to go through the damn file character by character.

-Dana




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

Date: Wed, 7 Jun 2000 13:41:24 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: Help with a simple regular expression
Message-Id: <8hmc0a$6nr$1@brokaw.wa.com>


Dana H <dana_hartley@nospam.hotmail.com> wrote in message
news:393eaf48$0$152$39368dfe@news.twtelecom.net...
>
> I'm not that experienced with PERL, but have been trying to do it by
writing
> the entire file to a string variable, $input. Then I tried using @matches
=
> $input =~ />.*?</gs. It matched the first occurance of the match, but no
> others. It also left the >< on the values so they displayed like
>value<...I
> don't know how to do a regular expression in PERL and not include the
angle
> brackets.

If you are sure that your data is always going to fit that pattern, then you
can use a regular expression.  The main reason not to use a RE is because of
data in quotes that might contain a false match (for a RE).

To change your RE just a little,

@matches = $input =~ />(.*?)</gs;

This will capture just the data (and any newlines if the data spans more
than a line) and leave off the brackets.

>
> I'm frusterated with it and will probably end up using C++ (which I'm more
> familiar with) to go through the damn file character by character.

Another one saved by the Camel!

:-)

Lauren





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

Date: Wed, 7 Jun 2000 13:41:23 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Help with a simple regular expression
Message-Id: <MPG.13a85352d1a56fe998ab3e@nntp.hpl.hp.com>

In article <393eaf48$0$152$39368dfe@news.twtelecom.net> on Wed, 7 Jun 
2000 16:25:06 -0400, Dana H <dana_hartley@nospam.hotmail.com> says...

 ...

> I'm not that experienced with PERL, but have been trying to do it by writing
> the entire file to a string variable, $input. Then I tried using @matches =
> $input =~ />.*?</gs. It matched the first occurance of the match, but no
> others.

That is a surprise.  Are you sure about it?

>         It also left the >< on the values so they displayed like >value<...I
> don't know how to do a regular expression in PERL and not include the angle
> brackets.

Not having to state explicitly what is captured by a //g regex is a DWIM 
feature -- in the absence of parentheses, it captures the entire match.  
What you want to do is to state specifically what you want to capture.

  @matches = $input =~ />(.*?)</gs;

> I'm frusterated with it and will probably end up using C++ (which I'm more
> familiar with) to go through the damn file character by character.

Otherwise known as 'going to hell in a handbasket'.  :-)

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


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

Date: Wed, 07 Jun 2000 14:37:51 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Help with a simple regular expression
Message-Id: <393EC0AF.2183BFBC@stomp.stomp.tokyo>

Dana H wrote:
 
> > > I want to use PERL to extract all of the values from a XML file...

> > > between the "" characters and the >< characters. 


> > I'm not sure you want to use a regular expression here.  
> > Try looking at the XML::Parser.

> Thanks for the tip, Lauren, but I don't think that will work. 
> The problem is that the XML files that I am going to be looking
> at are not guaranteed to be well formed or even valid. 

> I'm not that experienced with PERL, but have been trying to do 
> it by writing the entire file to a string variable, $input. Then
> I tried using @matches = > $input =~ />.*?</gs. It matched the 
> first occurance of the match, but no others. It also left the >< 
> on the values so they displayed like >value<...I don't know how to
> do a regular expression in PERL and not include the angle brackets.


What you want to do is not impossible nor really all
that hard. Use of a module might not be your best choice
for reasons you have lightly touched upon.

Only requirement here is some work and careful planning.
Work you understand. Planning would involve getting to
know what type of documents you will be searching, this
is, developing a good feel for what your average input
will be, then writing code accordingly.

Rather than write code which affords a solution, I have
put together a tiny test script to exemplify a few ways
you can expect failure. This is timely. You have mentioned
your input may not always be to industry standards. This
is a well accepted fact of programming and, presents rather
enjoyable challenges for us.

My code exemplifies some variations in what you might
expect for input, quotes in one string, no quotes in
another, deliberate tricks to cause failure. My hopes
are this will inspire you to think in directions of
nailing down what you want, with precision.

For example, matching "a href=" and grabbing what follows,
up to a point ( > ) would nail this down better. Looking
for what lies between > Stuff Here </a> would better match
your hyperlink titles. Attributes, values, have their own
common symbols which must be there. An equal sign is a
good example; src= .. href= .. size= .. and so forth.

However, no guarantee quotes will be there and no promise
a person won't toss in a space or spaces around an equal
sign. A good approach then, would be to delete all quotes
and all spaces first, then shoot for a match, yes?

This method is something people tire of reading from me.
"Precondition Your Input" as much as possible, then work
with it, after crossing your fingers.

Down below you will find printed results and a test script.
This is not a solution but rather has an intent of pointing
to a few problems of many you may expect to encounter. You
might just find some solutions if you read between my lines.

Careful planning on your part, preconditioning your input,
some adequate beta testing, you can do this, with no need
for a module.


Godzilla!



PRINTED RESULTS
_______________


Test One Is Successful:

Between Quotes: bozo.gif 

Between > And < : Target 



Test Two Fails:

Between Quotes:  

Between > And < : <!--Not A Target--> 



Test Three Is Successful:

Between Quotes: bozo.gif 

Between > And < : Target 



TEST SCRIPT
___________


#!/usr/local/bin/perl

print "Content-Type: text/plain\n\n";


## Test One Pretend Input:

print "Test One Is Successful:\n\n";

$string = "<IMG SRC=\"bozo.gif\">Target<P>";

if ($string =~ /"(.*)"/)
 { $var1 = $1 }

print "Between Quotes: $var1 \n\n";

if ($string =~ />(.*)</)
 { $var2 = $1; }

print "Between > And < : $var2 \n\n";


## Test Two Pretend Input:

print "\n\nTest Two Fails:\n\n";

$string2 = "<IMG SRC=bozo.gif><!--Not A Target--><P>";

if ($string2 =~ /"(.*)"/)
 { $var3 = $1; }

print "Between Quotes: $var3 \n\n";

if ($string2 =~ />(.*)</)
 { $var4 = $1; }

print "Between > And < : $var4 \n\n";


## Test Three Pretend Input:

print "\n\nTest Three Is Successful:\n\n";

$string3 = "<IMG SRC=\"bozo.gif\"><!--Not A Target-->Target<P>";

if ($string3 =~ /SRC="(.*)"/)
 { $var5 = $1; }

print "Between Quotes: $var5 \n\n";


$string3 =~ s/<([^>]+)>//gi;

print "Between > And < : $string3 \n\n";


exit;


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

Date: Wed, 07 Jun 2000 18:30:43 GMT
From: eggie@REMOVE_TO_REPLYsunlink.net (James Kufrovich)
Subject: Re: Help with OO needed.
Message-Id: <slrn8jt59j.fd7.eggie@melody.mephit.com>

On Wed, 07 Jun 2000 07:42:01 GMT, Bart Lateur <bart.lateur@skynet.be> wrote:
[snip]
>In summary: called as a class method, $parent becomes the emtpy string,
>and $class becomes the string that is the first argument. Called as an
>object method, $class becomes the class of the object, and $parent
>becomes the object itself. So I gather the new object will be a child of
>that object; or at least: the passed object will be the parent of the
>new object. That usually means the same thing...   ;-)
>
>p.s. I just noticed that the usual OO semantics all assume that the
>class name will never be "0" (zero).

	Thanks. I think it all makes sense now.  I'm still a little fuzzy
on how $parent can be used if it's an object (ie, the constructor is
called as an object method), but I'll figure it out.  Thanks again.

Jamie Kufrovich

-- 
FMSp3a/MS3a A- C D H+ M+ P+++ R+ T W Z+ 
Sp++/p# RLCT a+ cl++ d? e++ f h* i+ j p+ sm+


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

Date: Wed, 07 Jun 2000 19:15:32 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Help with OO needed.
Message-Id: <7an1kxqp4b.fsf@merlin.hyperchip.com>


eggie@REMOVE_TO_REPLYsunlink.net (James Kufrovich) writes:

> 	Thanks. I think it all makes sense now.  I'm still a little fuzzy
> on how $parent can be used if it's an object (ie, the constructor is
> called as an object method), but I'll figure it out.  Thanks again.

Well, here's one situation. Suppose you create an object, and then through
some lengthy process you set some of its parameters. Now, you would like
to create another object with the exact same parameters. You can do it
from scratch, and create a new object and initialize it the way you did
with the first one. Or, you can also simply do a:

	$parent->new();

and arrange for the new() method to figure out how it was called, and
act accordingly.

--Ala


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

Date: Wed, 07 Jun 2000 14:09:09 -0700
From: Tony Lanier <tlanierNOtlSPAM@atmel.com.invalid>
Subject: help with specPerl
Message-Id: <11963fea.d6200cd6@usw-ex0101-007.remarq.com>

I need help trying to get specPerl 1.1 to run on our Sorlaris 2.6
environment. We have Perl 5.005 and Tk 8.0 installed. I can run
perl/Tk scripts. I downloaded the specTcl 1.1 and specPerl
software and installed them, but I keep getting some strange
errors when running the script "specPerl". First off, the script
needs to run something called 'wish', which apparently came with
Tk. Well, I can't find it ('which wish' doesn't find it either).
The specPerl script looks like this:

#!/bin/sh
# SpecTcl, by S. A. Uhler
# Copyright (c) 1994-1995 Sun Microsystems, Inc.
#
# See the file "license.txt" for information on usage and
redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# Change DIR to the directory that contains the SpecTcl source
files
DIR=/opt/TWWfsw/SpecTcl1.1/SpecTcl

# Change WISH to the pathname of your tk4.1a2 (or >) wish binary
WISH=`which wish`

env SPECTCL_DIR=$DIR $WISH $DIR/main.tk -perl $@ &
#env SPECTCL_DIR=$DIR $DIR/main.tk -perl $@ &
echo "Starting SpecPerl 1.0"
exit 0

If I leave the $WISH statement in, I get the following error:

env: No such file or directory (which I believe is due to the
system not finding wish).

If I comment it out, I get the following error:

env: Permission denied

If I try to run main.tk by itself, I get this:

env: Permission denied

Hmmm, I can't figure this one out. I even did a test case in my
home directory and got the same error! If anyone can point me to
the problem, I would very much appreciate it!

Tony

PS I can run specPerl at home on Windows 98 WITHOUT any probelms!
Go figure!!

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



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

Date: Wed, 07 Jun 2000 21:45:14 GMT
From: gthorne777@my-deja.com
Subject: Help with writing to other program
Message-Id: <8hmfp5$l64$1@nnrp1.deja.com>

Can anyone tell me why this program will not work without the "-i"
switch in the first line?  If I try to run it without it, nothing ever
shows up on screen, and it does not accept input.  Using the "-i"
option, it works great.  Where does the output go when you do an "open
(| progname)"?  Eventually, I would like to parse the output of this and
only show certain lines.  What's the best way of doing this?

-------Begin Program-------
#!/usr/local/bin/perl -i

use Term::ReadKey;
use IO::Handle;

my $delay=10;
my $command;

sub ipmh_loop
{
  ReadMode('cbreak');
  do
  {
    system("clear");
    $ps=open(IPMH, "| ipmhTool -ns \$OSI_SYSTEM");
    print IPMH "sh procs\nq\n";
    close (IPMH);
    print "Command: ";
    STDOUT->autoflush(1);
  }
  while (! defined ($command = ReadKey($delay)));
  ReadMode('normal');
  interpret_command();
}

sub interpret_command
{
  if ($command=~m/\w/i)
  {
    $command=$&;
    if ($command eq "q")
    {
      print "\nexiting...\n\n";
      exit(0);
    }
    elsif ($command eq "d")
    {
      print "Time (in seconds): ";
      $delay=<STDIN>;
      print "Delay set to $delay seconds.\n";
      ipmh_loop();
    }
    elsif ($command eq "h")
    {
      print "\nCommands:  d <seconds> - set delay to <seconds>\n";
      print "           h - help (this screen)\n";
      print "           q - quit\n\n";
      print " Press <Return> to continue. ";
      if (<STDIN>) {ipmh_loop();}
    }
    else
    {
      print "\n`$command' is not a valid option.  Press <Return> to
continue. ";
      if (<STDIN>) {ipmh_loop()};
      $command=<STDIN>;
    }
  }
}

ipmh_loop();

-------End Program-------

Thanks for any help you could give me.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 7 Jun 2000 11:04:33 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: how to write on a file?
Message-Id: <MPG.13a82e88840e383198ab36@nntp.hpl.hp.com>

In article <8hkqad$ejd$1@slb6.atl.mindspring.net> on 7 Jun 2000 06:32:45 
GMT, Eric Bohlman <ebohlman@netcom.com> says...
> The_tick (the_tickNOthSPAM@inet.net.nz.invalid) wrote:

 ...

> : close(FILE);
> 
> Wow!  A statement without any problems!

Strictly speaking, no.  This statement has problems also.

For a regular file, as in this case, the close() may fail if flushing 
the output buffer causes the file system to run out of space or the file 
to reach a predetermined size limit.  Or, for that matter, if any of the 
previous print() statements (unchecked by common usage) has caused the 
problem.

For a pipe, checking the close() is the way to determine successful 
completion of the process piped to.

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


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

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 V9 Issue 3279
**************************************


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