[21756] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3960 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 12 18:05:49 2002

Date: Sat, 12 Oct 2002 15:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 12 Oct 2002     Volume: 10 Number: 3960

Today's topics:
    Re: Any way around using the $& variable? (Peter J. Acklam)
    Re: Any way around using the $& variable? <nobull@mail.com>
    Re: Any way around using the $& variable? <pinyaj@rpi.edu>
        array variable reference versus literal vector question <occitan@esperanto.org>
    Re: array variable reference versus literal vector ques <goldbb2@earthlink.net>
    Re: chat2.pl error. <pilsl_use@goldfisch.at>
        Doing two tasks at once <nospam@euro.com>
    Re: Doing two tasks at once <nospam@nospam.com>
        Extensible event loop architecture <nospam-abuse@ilyaz.org>
    Re: Extensible event loop architecture <goldbb2@earthlink.net>
        Help parsing HTML <aemily@colsd.org>
    Re: Help parsing HTML <kurzhalsflasche@netscape.net>
    Re: Help! How do you move one html page to another in P (Zordiac)
    Re: Help! How do you move one html page to another in P <bongie@gmx.net>
    Re: How about UNIVERSAL::hashkey() ? <heather710101@yahoo.com>
    Re: How about UNIVERSAL::hashkey() ? <heather710101@yahoo.com>
        Lexical-Alias 0.02 released <pinyaj@rpi.edu>
    Re: Problems with MSIE in combination with MAC not show <pkent77tea@yahoo.com.tea>
    Re: Problems with MSIE in combination with MAC not show <flavell@mail.cern.ch>
    Re: question from beginner >_< (kit)
        Thread::Queue; or variable scope? <shier@shorcan.com>
    Re: undef == true? <garry@ifr.zvolve.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 12 Oct 2002 15:24:40 GMT
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Any way around using the $& variable?
Message-Id: <adljk7a6.fsf@online.no>

Brian McCauley <nobull@mail.com> wrote:

> pjacklam@online.no (Peter J. Acklam) writes:
> 
> > Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote:
> > 
> > > You could use the @- and @+ arrays:
> > > 
> > > s/($regex)/"\e[36m" . substr($_, $-[0], $+[0] - $-[0]) . "\e[m"/ego;
> > > 
> > > if you have Perl 5.6+.
> > 
> > No, I can't.  Introducing extra parentheses will cause certain
> > regexes to fail where they would otherwise match.
> 
> There is no need to introdice extra parentheses.  I don't know
> why Jeff put them there.

Ah, I see.  Then it seems like I have found the solution I was
looking for!  Excellent!

I have Perl 5.6, but I'm not up to date on the new stuff added
since 5.005.

> You also should not use the /o qualifer unless you are really
> understand it (in which case you'll probably decide you don't
> want it).

The regex is static, but called in a loop, so I am quite sure I
want the /o.  :-)

Peter

-- 
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;


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

Date: 12 Oct 2002 17:18:58 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Any way around using the $& variable?
Message-Id: <u9adlj3a19.fsf@wcl-l.bham.ac.uk>

pjacklam@online.no (Peter J. Acklam) writes:

> Brian McCauley <nobull@mail.com> wrote:
> 
> > pjacklam@online.no (Peter J. Acklam) writes:
> > 
> > > Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote:
> > > > 
> > > > s/($regex)/"\e[36m" . substr($_, $-[0], $+[0] - $-[0]) . "\e[m"/ego;
> 
> > You also should not use the /o qualifer unless you are really
> > understand it (in which case you'll probably decide you don't
> > want it).
> 
> The regex is static, but called in a loop, so I am quite sure I
> want the /o.  :-)

When I said "understand it" I did not only mean understand what
happens when you have /o but also what happens when you don't.

If I say /$regex/o then the first time this is exceuted Perl will
cache the compliled regex and associate it with the current
statement.  When the same statement is exectuted again then Perl will
use the cached expression even if $regex has changed.

If I say /$regex/ then the first time this is exceuted Perl will cache
the compliled regex and associate it with the $regex variable.  When
/$regex/ is exectuted again then Perl will use the cached expression
unless $regex has changed.

So as you can see there may be a tiny run-time saving by using the /o
but this IMNSHO is far outwieghed by the chance that at some future
time you may what to wrap the whole lot in an outer loop over which
$regex is not invariant.

Note: if you had someting like /^$regex$/ then IIRC this would prevent
caching but this would better be solved by putting $regex=qr/^$regex$/
outside the loop rather than using the /o qualifier.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Sat, 12 Oct 2002 14:41:52 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Any way around using the $& variable?
Message-Id: <Pine.SGI.3.96.1021012144057.1166205B-100000@vcmr-64.server.rpi.edu>

On 12 Oct 2002, Brian McCauley wrote:

>Note: if you had someting like /^$regex$/ then IIRC this would prevent
>caching but this would better be solved by putting $regex=qr/^$regex$/
>outside the loop rather than using the /o qualifier.

I don't think so.  The ENTIRE regex is cached.  That means that the
following code does NOT recompile the regex, although $x and $y change.

  $x = "abc";
  $y = "def";
  for (1, 2) {
    /$x$y/;
    $x = "ab";
    $y = "cdef";
  }

-- 
Jeff "japhy" Pinyan      RPI Acacia Brother #734      2002 Acacia Senior Dean
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Sat, 12 Oct 2002 18:29:58 +0200
From: Daniel Pfeiffer <occitan@esperanto.org>
Subject: array variable reference versus literal vector question
Message-Id: <20021012182958.681557f9.occitan@esperanto.org>

Hi,

Do I have a chance of finding out whether I was passed a reference to an array variable, of to a literal vector which was only used for passing in a list?  Question is whether there is any point in changing values in the vector or if it's lost afterwards.

$ perl -e 'sub a($){print "@_\n"} a \@a'
ARRAY(0x8161190)

$ perl -e 'sub a($){print "@_\n"} a []'
ARRAY(0x8148a8c)

Both look alike, though the first is more powerful.

coralament / best Grötens / liebe Grüße / best regards / elkorajn salutojn
Daniel Pfeiffer

-- 
 -- http://dapfy.bei.t-online.de/sawfish/
  --


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

Date: Sat, 12 Oct 2002 16:44:33 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: array variable reference versus literal vector question
Message-Id: <3DA889B1.844AD1C0@earthlink.net>

Daniel Pfeiffer wrote:
> 
> Hi,
> 
> Do I have a chance of finding out whether I was passed a reference to
> an array variable, of to a literal vector which was only used for
> passing in a list?

You can, but it's not easy ...
use B;
my $array_ref = ...;
my $found = 0;
walksymtable( \%main::,
   sub { $found ||= ( \@{shift} == $array_ref ) },
   sub { !$found },
   "main::",
);
print $found ? "It's a named variable" : "It's an anonymous variable";

> Question is whether there is any point in changing
> values in the vector or if it's lost afterwards.

There's probably no harm in doing it -- it's easier to do it and not
worry about the cost if it might be lost.

And how do you know that it *will* be lost just because it's an
anonymous arrayref?

Remember: Premature optomization is the root of all evil :)

If you're worried about the cost, profile your code.

> $ perl -e 'sub a($){print "@_\n"} a \@a'
> ARRAY(0x8161190)
> 
> $ perl -e 'sub a($){print "@_\n"} a []'
> ARRAY(0x8148a8c)
> 
> Both look alike, though the first is more powerful.

What do you mean more powerful?
In particular, consider:
   my @a = ...;
   my @b = map [], 1..10;
   sub a($) { print @_, "\n" }
   a($_) for \@a, @b;
When I do \@a, that's a reference to a named variable.
Each of the elements of @b is an anonymous arrayref... but even though
they're anonymous, if a() changes them, the results won't be lost.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sat, 12 Oct 2002 22:18:14 +0200
From: peter pilsl <pilsl_use@goldfisch.at>
Subject: Re: chat2.pl error.
Message-Id: <3da88392$1@e-post.inode.at>

kees boss wrote:

> when I use "require chat2.pl" in my program's I get the error:
> 
> String found where operator expected at (eval 316) line 1, near "&__const
> 'struct sockaddr'"
>         (Missing operator before  'struct sockaddr'?)
> 
> I'm using preinstalled perl on SuSe linux 7.3 box.
> 
> Anybody know what is wrong with this perl-installation???
>

never used chat2.pl, but I quote its first few lines here:

# This library is no longer being maintained, and is included for backward
# compatibility with Perl 4 programs which may require it.
#
# In particular, this should not be used as an example of modern Perl
# programming techniques.
#
# Suggested alternative: Socket
#
# Based on: V2.01.alpha.7 91/06/16
# Randal L. Schwartz (was <merlyn@stonehenge.com>)
# multihome additions by A.Macpherson@bnr.co.uk
# allow for /dev/pts based systems by Joe Doupnik <JRD@CC.USU.EDU>

If I try to "require" this module I get the following:

Use of "do" to call subroutines is deprecated at 
/usr/lib/perl5/5.6.0/chat2.pl line 276.
Ambiguous call resolved as CORE::select(), qualify as such or use & at 
/usr/lib/perl5/5.6.0/chat2.pl line 368.
Ambiguous call resolved as CORE::select(), qualify as such or use & at 
/usr/lib/perl5/5.6.0/chat2.pl line 368.
Ambiguous call resolved as CORE::select(), qualify as such or use & at 
/usr/lib/perl5/5.6.0/chat2.pl line 371.
Ambiguous call resolved as CORE::select(), qualify as such or use & at 
/usr/lib/perl5/5.6.0/chat2.pl line 371.
syntax error at /usr/lib/perl5/5.6.0/i386-linux/sys/socket.ph line 15, near 
") ("
syntax error at /usr/lib/perl5/5.6.0/i386-linux/sys/socket.ph line 33, near 
"}"
Compilation failed in require at /usr/lib/perl5/5.6.0/chat2.pl line 18.
Compilation failed in require at ./t.pl line 5.

So cause chat2.pl seems to be a alpha-version dated from 1991 I wouldnt use 
it if I dont need to.

best,
peter


--  
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at



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

Date: Sat, 12 Oct 2002 10:38:15 -0700
From: Fr€d <nospam@euro.com>
Subject: Doing two tasks at once
Message-Id: <3DA85E07.CB8@euro.com>

I am trying to distribute some work among several machines.  The basic
task is to acquire a file (I'm doing it via Net::FTP), then run my perl
script on it, then send the results back (probably via ftp as well).

ie:

repeat {
  FTP next file from server;
  system("perl calc.pl filename");
  FTP results back to server;
}

The input files are 60-150Mb. The calculations take about the same time
as transferring the file, often less time.  So, I would like to 
ftp the next file while I'm doing the calculations.  The calculations
are basically CPU bound anyway, so this seems like a good fit that
wouldn't slow things down very much.

ie:

repeat {
  while (FTP'ing the next file) 
    do calcs on previous file;
  wait (if needed) until FTP is done;
  FTP results back to server;
}

Any pointers on where to look; I've browsed thru threads, exec() and
system() so far, but haven't figured how to put it together yet.  This
would be running on Win32 / ActiveState Perl

thanks


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

Date: Sat, 12 Oct 2002 12:58:18 -0700
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: Doing two tasks at once
Message-Id: <3da87e50_3@nopics.sjc>


"Fr?d" <nospam@euro.com> wrote in message news:3DA85E07.CB8@euro.com...
> I am trying to distribute some work among several machines.  The basic
> task is to acquire a file (I'm doing it via Net::FTP), then run my perl
> script on it, then send the results back (probably via ftp as well).
>
> ie:
>
> repeat {
>   FTP next file from server;
>   system("perl calc.pl filename");
>   FTP results back to server;
> }
>
> The input files are 60-150Mb. The calculations take about the same time
> as transferring the file, often less time.  So, I would like to
> ftp the next file while I'm doing the calculations.  The calculations
> are basically CPU bound anyway, so this seems like a good fit that
> wouldn't slow things down very much.
>
> ie:
>
> repeat {
>   while (FTP'ing the next file)
>     do calcs on previous file;
>   wait (if needed) until FTP is done;
>   FTP results back to server;
> }
>
> Any pointers on where to look; I've browsed thru threads, exec() and
> system() so far, but haven't figured how to put it together yet.  This
> would be running on Win32 / ActiveState Perl
>
> thanks

You might want to consider "fork".  I'd recommend you fork two separate
processes - one for copying files over to your local box, and one for
computation on files (and sending results back). The former simply drops
files into a designated directory, the latter keeps scanning for new files,
moves them to another directory for processing. The thing you have to watch
out for is you pick up and process a file in the middle of a FTP download. I
recommend you save FTPed files with a certain extention such as .tmp while
downloading and rename them to the original name afterwards.  If you keep
everything on one disk, Perl  built-in function "rename" should suffice,
otherwise, use File::Copy "move" function. From my understanding, they are
both atomic.




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

Date: Sat, 12 Oct 2002 20:25:06 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Extensible event loop architecture
Message-Id: <aoa0f2$tts$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Benjamin Goldberg 
<goldbb2@earthlink.net>], who wrote in article <3DA7AA41.B1CA3169@earthlink.net>:
> No -- it means that the only kinds of events that POE *cares about* are
> ones associated with filehandles.

Could you explain *why* some kinds of events are more important to POE
than the others (even if the low-level loop is replaced)?

> > I do not know what is L;
> 
> Perl's flock builtin.  This may be implemented with one of the C flock,
> lockf, or fcntl functions.

But what makes them *events*?

> > I also have no idea what is a "shared memory" event.
> 
> When performing rpc with shared memory, you use shared memory segments
> to send data to/recieve data from the program you're doing RPC with, and
> semaphores to tell the other program when it's safe to read from/write
> to those shared memory segments.  You wouldn't have a "shared memory"
> event, but you might have a semaphore event.

So please use less confusing words.  I do not care what a semaphore is
guarding - memory, filehandle, etc; so should not POE.

> > On OS/2 I know how to handle F, P, S and R (but *very* ugly).  On
> > Unix?  It is easy to handle F and S (thus P)...  [But only for S which
> > do not require ACKing.  The latter may be also doable, but need
> > further thinking.]

> On unix, I would use a lightweight thread for handling each type of
> event, and each of those threads would communicate the results to the
> main thread using one single mechanism (probably a mutex lock, some
> global memory (shared across all threads), and a condition variable).

You cannot wait simultaneously on a mutex and select(); so if the
select()-like functionality goes through POE, and the rest through a
"plugged-in subsystem", then the communication should go via a special
pipe.

You probably again think about a *full replacement* of an event loop.
As you already see, this leads to not-scalable solutions.  What is
needed is a way to *extend* the functionality of an existing event
loop (probably already consisting of several cooperating subsystems).

> The main thread could then read events from one place, using one
> mechanism, and not have to worry about anything else, due to data
> encapsulation.

Alas, nothing so simple; there is no data encapsulation until you
describe *how* it is encapsulated.  But I implemented this scheme on
OS/2, so I know what kind of API is needed to implement *this*
particular mode of extension.  This API is scalable in the sense I use
in this thread - many different subsystems may be installed
independently.  [When I say API, I mean C API; there is little chance
to do it in PurePerl.]

This API supposes that the event which triggers a subsystem is passed
to the event-core via a specified callback (which can, e.g, write a
word to a pipe) - this callback is communicated
event-core==>sybsystem.  It works well when a subsystem is
asyncroneous, and the subsystem events do not form a copious stream
(so that an overhead of an extra pipe write is not significant).
There must also be a callback so that the core may inform the
subsystem to stop (e.g., when the events served by the subsystem need
to be reconfigured) and to start.

The problem is that there definitely are *different* mechanisms of
extension that the asyncroneous ones (such as implemented via threads
or signal handlers).  I'm afraid that I'm blindfolded (by doing one
particular implementation) and my API 

E.g., suppose that select()-like events are expected very rare, but
the sybsystem events should be processed in a tight loop.  Then a
subsystem would like to be run in the main thread, and would like to
relocate the event-core into a secondary thread.  Definitely there may
be other scenarios as well.

But if nice people around take part in this discussion and volunteer
what *they* ever wanted from event loop engines, we have a better
chance to design a good extension mechanism.

> > I doubt it.  On OS/2 it is a special kind of Queue' ("prime" because
> > it has a separate API, comparing to core-Queue).
> 
> Because you can only talk through an API, there's no way to know how
> it's done internally.

But one can suspect anyway.  ;-)

> > Still do not understand what this has to do with SMTT and BS trying to
> > cooperate on event dispatch (using POE as an arbitrator).
> 
> If SMTT only cares about only F events, then it can use POE as a
> backend, regardless of what POE, in turn, uses as a backend.

But SMTT may use different kind of events, e.g., if it plots via Tk on
Windows.

> If BS could handle both F and W events, then it could act as a backend
> for POE, if you write an appropriate bridge class.

Ilya


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

Date: Sat, 12 Oct 2002 17:30:11 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Extensible event loop architecture
Message-Id: <3DA89463.7721427F@earthlink.net>

Ilya Zakharevich wrote:
[snip]
> > > On OS/2 I know how to handle F, P, S and R (but *very* ugly).  On
> > > Unix?  It is easy to handle F and S (thus P)...  [But only for S
> > > which do not require ACKing.  The latter may be also doable, but
> > > need further thinking.]
> 
> > On unix, I would use a lightweight thread for handling each type of
> > event, and each of those threads would communicate the results to
> > the main thread using one single mechanism (probably a mutex lock,
> > some global memory (shared across all threads), and a condition
> > variable).
> 
> You cannot wait simultaneously on a mutex and select(); so if the
> select()-like functionality goes through POE, and the rest through a
> "plugged-in subsystem", then the communication should go via a special
> pipe.

You can't *extend* POE's event loop, you can only replace it with a
custom event loop.  I was suggesting replacing it with a custom event
loop which is slightly more scalable (but is dependent on the existance
of preemptive OS level threads).

PS: As far as I know, the system I'm suggesting *is* fully scalable, if
you don't need a perl interpreter in any of those lightweight threads.

Each helper thread would perform it's blocking operation, then gain the
event queue lock, then add an event to the queue, then signal the event
cond, then unlock.

The main thread would acquire the event queue lock, wait for the cond if
there are no queued events, copy out one event and decrement the number
of items in the queue, then unlock and return the event.

(To cancel events on a filehandle, the simplest way I can think of is to
lock the queue, kill the thread which is doing select(), then start that
helper thread anew, but without that filedescriptor in it's fd_set, and
possibly remove from the queue any unprocessed events on the handle
you're now ignoring).

To add support for another type of event, simply create a new thread
which waits for events of that type, and uses the locking stuff to send
them into the queue.

> You probably again think about a *full replacement* of an event loop.

Yes.  And once one has written this replacement, a bridge class could be
used to make that replacement into a backend for POE.

> As you already see, this leads to not-scalable solutions.  What is
> needed is a way to *extend* the functionality of an existing event
> loop (probably already consisting of several cooperating subsystems).

Then design an *extensible* replacement, and use that replacement, and
if you need any extending, then extend it.  Just because POE's default
event loop isn't itself extensible doesn't prevent you from switching to
something which is.

> > The main thread could then read events from one place, using one
> > mechanism, and not have to worry about anything else, due to data
> > encapsulation.
> 
> Alas, nothing so simple; there is no data encapsulation until you
> describe *how* it is encapsulated.

Eh?  Main thread reads events from the queue.  Helper threads put events
into the queue.  Main thread needs not know how those helper threads
work.  It just looks in the queue and returns event structs.

Were you thinking of something else?

[snip]
> > > Still do not understand what this has to do with SMTT and BS
> > > trying to cooperate on event dispatch (using POE as an
> > > arbitrator).
> >
> > If SMTT only cares about only F events, then it can use POE as a
> > backend, regardless of what POE, in turn, uses as a backend.
> 
> But SMTT may use different kind of events, e.g., if it plots via Tk on
> Windows.

If it uses other types of events, then you should have said so. 
Changing the problem domain is *not* helping your argument.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sat, 12 Oct 2002 13:49:14 -0700
From: "Emily, Amanda" <aemily@colsd.org>
Subject: Help parsing HTML
Message-Id: <3da88493$1_1@news.vic.com>

I am trying to figure out perl on Windows 2000 (I'm trying to stay away from
VBScript if I can) and got the idea to put the weather forecast on an
internal website here at work. What I am trying to do parse a HTML page that
I retrieved and output the HTML and text between two comments and I am
having a bit of a problem with it.

The chunk of HTML that I am trying to parse is as follows:

<!-- TEXT FORECAST-->
<font face="arial">
<p>
<b>Today:</b> Plenty of sunshine. High around 55F. Winds light and
variable.<p>
<b>Tonight:</b> Generally clear skies. Low near 25F. Winds ENE at 5 to 10
mph.<p>
<b>Tomorrow:</b> Mostly sunny skies. High 62F. Winds light and variable.<p>
<b>Tomorrow night:</b> Clear. Low near 35F. Winds NNE at 5 to 10 mph.<p>
<b>Monday:</b> More sun than clouds. Highs in the low 60s and lows in the
low 30s.<p>
<b>Tuesday:</b> Sunshine. Highs in the low 60s and lows in the upper 30s.<p>
<b>Wednesday:</b> Times of sun and clouds. Highs in the low 60s and lows in
the mid 30s.<p>
</font>
<!-- ENDTEXT FORECAST-->

I am trying to grab everything between the comments and output it.

The perl script that I tried to use is as follows:

#!C:\perl\bin\perl.exe

system("wget -q http://weather.yahoo.com/forecast/USWA0088_f.html -O
c:\weather_temp.txt");
open(FILE, 'c:\\weather_temp.txt') || die "Uh... file not found.\n";
   while( <FILE> )
      {
      print if
         /<!-+\s+TEXT FORECAST\s+-+>/i
         ..
         /<!-+\s+ENDTEXT FORECAST\s+-+>/i;
      }

close(FILE);

The script does go out and grab the file I want, but the rest of it does not
run. I am getting no errors but there is no output. What am I doing wrong
and is there a perl module that could do the same thing for me?

Amanda Emily




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

Date: Sat, 12 Oct 2002 23:14:21 +0200
From: Dominik Seelow <kurzhalsflasche@netscape.net>
Subject: Re: Help parsing HTML
Message-Id: <3DA890AD.20701@netscape.net>

Emily, Amanda announced:
> I am trying to figure out perl on Windows 2000 (I'm trying to stay away from
> VBScript if I can) and got the idea to put the weather forecast on an
> internal website here at work. What I am trying to do parse a HTML page that
> I retrieved and output the HTML and text between two comments and I am
> having a bit of a problem with it.
> 
> The chunk of HTML that I am trying to parse is as follows:
> 
> <!-- TEXT FORECAST-->
> <font face="arial">
> <p>
> <b>Today:</b> Plenty of sunshine. High around 55F. Winds light and
> variable.<p>
> <b>Tonight:</b> Generally clear skies. Low near 25F. Winds ENE at 5 to 10
> mph.<p>
> <b>Tomorrow:</b> Mostly sunny skies. High 62F. Winds light and variable.<p>
> <b>Tomorrow night:</b> Clear. Low near 35F. Winds NNE at 5 to 10 mph.<p>
> <b>Monday:</b> More sun than clouds. Highs in the low 60s and lows in the
> low 30s.<p>
> <b>Tuesday:</b> Sunshine. Highs in the low 60s and lows in the upper 30s.<p>
> <b>Wednesday:</b> Times of sun and clouds. Highs in the low 60s and lows in
> the mid 30s.<p>
> </font>
> <!-- ENDTEXT FORECAST-->
> 
> I am trying to grab everything between the comments and output it.
> 
> The perl script that I tried to use is as follows:
> 
> #!C:\perl\bin\perl.exe
> 
> system("wget -q http://weather.yahoo.com/forecast/USWA0088_f.html -O
> c:\weather_temp.txt");
> open(FILE, 'c:\\weather_temp.txt') || die "Uh... file not found.\n";
>    while( <FILE> )
>       {
>       print if
>          /<!-+\s+TEXT FORECAST\s+-+>/i
>          ..
>          /<!-+\s+ENDTEXT FORECAST\s+-+>/i;
>       }
> 
> close(FILE);
> 
> The script does go out and grab the file I want, but the rest of it does not
> run. I am getting no errors but there is no output. What am I doing wrong
> and is there a perl module that could do the same thing for me?
> 
> Amanda Emily
> 
> 

Hello Amanda,

you can either put the whole HTML file into a string ($content in my
example) and grep for the text between the comments or search for
HTML::Parser (or maybe HTML::TokeParser) at CPAN (which is safer).
Anyway, if you decide to use the RegExp solution, try this:

my ($forecast)=($content=~/<!-- TEXT FORECAST-->(.*?)<!-- ENDTEXT
FORECAST-->/s);

HTH,
Dominik



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

Date: 12 Oct 2002 10:37:26 -0700
From: zordiac@hotmail.com (Zordiac)
Subject: Re: Help! How do you move one html page to another in Perl?
Message-Id: <7744b29b.0210120937.2c7e8d63@posting.google.com>

Again thanks one and all for the comments - please bear 
with me as I would like to clarify some things:


Jeff wrote
>The FAQ says:
>  How do I decode a CGI form?
>  You use a standard module, probably CGI.pm. Under no
>  circumstances should you attempt to do so by hand!

Jeff my perl cgi script has to work on different machines
how can the script be portable - I know I never mentioned 
this before - if it needs the CGI module downloaded. This
is one of the reasons for avoiding using this module. 
Thank you for the script. I just got it working but had to
move the -T bit on first line.


ME > b) take user input from any page

By this I meant the script is invoked and user input is taken
from the first html displayed page. A button is clicked and the
script POSTs this in effect back to itself - as I could not figure
out another way of doing this. What I want to do is get a user
to input a file name on one page and then display a record from
that file on another page. And allow the user to select another
record and have that displayed. Theres more to it than that but
thats the basics.


Many thanks,

Steve


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

Date: Sun, 13 Oct 2002 00:03:20 +0200
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: Help! How do you move one html page to another in Perl?
Message-Id: <2195952.nAhutC6KZ0@nyoga.dubu.de>

Zordiac wrote:
> Jeff wrote
>>The FAQ says:
>>  How do I decode a CGI form?
>>  You use a standard module, probably CGI.pm. Under no
>>  circumstances should you attempt to do so by hand!
> 
> Jeff my perl cgi script has to work on different machines
> how can the script be portable - I know I never mentioned
> this before - if it needs the CGI module downloaded.

a) The CGI.pm ist already part of newer Perl distributions.
b) If your perl is too old, you should download and install
   CGI.pm.  (It's pure Perl, AFAIK.)
c) Portability of your code is one of the main concerns of 
   the CGI module.  Take a look at the code to build HTTP
   headers, for example.  Do *you* know how to build correct
   line terminators under VMS?

> This
> is one of the reasons for avoiding using this module.

I cannot see any reason.  Portability is a reason to *use* CGI.pm, not 
to avoid it.

> Thank you for the script. I just got it working but had to
> move the -T bit on first line.

-T is a Good Thing[tm] for CGIs.  Read perlsec on "taint mode" for 
details.  If the code won't work with -T, rewrite the code.


Ciao,
        Harald
-- 
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Just don't create a file called -rf.  :-)
                -- Larry Wall in <11393@jpl-devvax.JPL.NASA.GOV>


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

Date: Sat, 12 Oct 2002 16:24:19 +0000 (UTC)
From: Da Witch <heather710101@yahoo.com>
Subject: Re: How about UNIVERSAL::hashkey() ?
Message-Id: <ao9ibj$729$1@reader1.panix.com>

In <u9y993u44w.fsf@wcl-l.bham.ac.uk> Brian McCauley <nobull@mail.com> writes:
>use overload 
>   '""' => sub { "In a string context"),
>   '{}' => sub { "In a hash key context" };

>If the '{}' overloading was not specified it should fall-back to the
>'""' operator.

This is an interesting approach, but the Perl 5.8 man page does not
mention '{}' as an overloadable operator.  Maybe I'm missing something
(I confess that I'm not familiar with overload).

I suppose that I could just overload '""', if knew how the overloading
sub could possibly tell whether or not it is being used in the context
of turning the object into a hashkey, but I have no idea how it could.

Thanks,

h



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

Date: Sat, 12 Oct 2002 16:25:28 +0000 (UTC)
From: Da Witch <heather710101@yahoo.com>
Subject: Re: How about UNIVERSAL::hashkey() ?
Message-Id: <ao9ido$729$2@reader1.panix.com>

In <u9y993u44w.fsf@wcl-l.bham.ac.uk> Brian McCauley <nobull@mail.com> writes:

>Da Witch <heather710101@yahoo.com> writes:

>> I think it would be great of a new hash_code() instance method were
>> added to UNIVERSAL, so that whenever an object $obj is used as a key
>> to hash, the Perl interpreter would first call $obj->hash_code to get
>> the appropriate hashkey to use for that object.  (This is the same
>> idea as the hashCode method of Java's Object class).  The default
>> value returned by UNIVERSAL::hash_code() would be the stringified
>> version of the object that Perl currently uses whenever objects are
>> used as hash keys.  But class programmers could override this method
>> to gain greater control over hashes that are indexed by objects.

>I do not think that there's a need for this feature as if you want a
>hash that is keyed on something that's not a simple string I think it
>makes more sense to think of this as a feature of the hash rather than
>the things that are to be used as keys.  This, of course, can already
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>be done.
 ^^^^^^^

How?

h


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

Date: Sat, 12 Oct 2002 15:32:47 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Lexical-Alias 0.02 released
Message-Id: <Pine.SGI.3.96.1021012152935.1167451B-100000@vcmr-64.server.rpi.edu>

See http://www.pobox.com/~japhy/modules/ for the full details.  It'll be
on CPAN soon.

NAME
    Lexical::Alias - makes a lexical an alias for another variable

SYNOPSIS
      require 5.008;
      use Lexical::Alias;

      my ($src, $dst);
      alias $src, $dst;

      my (@src, @dst);
      alias @src, @dst;

      my (%src, %dst);
      alias %src, %dst;

      # modifying $src/@src/%src
      # modifies $dst/@dst/%dst,
      # and vice-versa

      # or, if supporting Perls prior to v5.8:

      use Lexical::Alias qw( alias_r alias_s alias_a alias_h );

      my ($src, $dst);
      alias_s $src, $dst;

      my (@src, @dst);
      alias_a @src, @dst;

      my (%src, %dst);
      alias_h %src, %dst;

      alias_r \$src, \$dst;
      alias_r \@src, \@dst;
      alias_r \%src, \%dst;

DESCRIPTION
    This module allows you to alias a lexical (declared with "my") variable
    to another variable (package or lexical). You will receive a fatal error
    if you try aliasing a scalar to something that is not a scalar (etc.).

  Exported Functions
    * "alias(src, dst)"
        Makes *dst* (which must be lexical) an alias to *src* (which can be
        either lexical or a package variable). *src* and *dst* must be the
        same data type (scalar and scalar, array and array, hash and hash).

        This is only available in Perl v5.8 and later, where it is exported
        automatically.

    * "alias_s($src, $dst)"
        Makes *dst* (which must be lexical) an alias to *src* (which can be
        either lexical or a package variable). This is not exported by
        default.

    * "alias_a(@src, @dst)"
        Makes *dst* (which must be lexical) an alias to *src* (which can be
        either lexical or a package variable). This is not exported by
        default.

    * "alias_h(%src, %dst)"
        Makes *dst* (which must be lexical) an alias to *src* (which can be
        either lexical or a package variable). This is not exported by
        default.

    * "alias_r(\src, \dst)"
        Makes *dst* (which must be lexical) an alias to *src* (which can be
        either lexical or a package variable). *src* and *dst* must be the
        same data type (scalar and scalar, array and array, hash and hash).
        This is not exported by default.

  Caveats
    Because one variable is an alias for the other, making either one an
    alias for *another* variable makes them *both* aliases for it:

      use Lexical::Alias;

      my ($x, $y, $z);
      alias $x => $y;  # $y is an alias for $x
      alias $z => $y;  # $y (and thus $x) is an alias for $z
      $z = 10;
      print $x;        # 10

    This is not a bug.

AUTHOR
    Jeff "japhy" Pinyan, japhy@pobox.com

    Thanks to Tye McQueen for a bug fix -- this module should work from
    5.005 on.

    http://www.pobox.com/~japhy/

SEE ALSO
    Devel::LexAlias, by Richard Clamp, from which I got (and modified) the
    code necessary for this module. I've wanted this feature for some time,
    and Richard opened the door with this module.




-- 
Jeff "japhy" Pinyan      RPI Acacia Brother #734      2002 Acacia Senior Dean
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Sat, 12 Oct 2002 15:18:54 GMT
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: Problems with MSIE in combination with MAC not showing Perl generated HTML
Message-Id: <pkent77tea-A017C7.16185412102002@news-text.blueyonder.co.uk>

In article <3da83434$0$11204$1b62eedf@news.euronet.nl>,
 "Jan" <jan@nospam.harf.nl> wrote:

> "pkent" <pkent77tea@yahoo.com.tea> wrote in message
> > Client-Bad-Header-Line: Content-type text/html
> >
> Took me a while to see it.... Really. Finally saw it because of your
> redirection to the CGI module. Thanks a lot for pointing me at the missing
> colon...

No problem. It's not as if I saw it straight away either - had to try a 
few things before I spotted that :-)

P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


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

Date: Sat, 12 Oct 2002 17:07:02 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Problems with MSIE in combination with MAC not showing Perl generated HTML
Message-Id: <Pine.LNX.4.40.0210121657180.30100-100000@lxplus073.cern.ch>

On Oct 12, Jan inscribed on the eternal scroll:

[excessive quotage sniporama]

> Took me a while to see it....

Me too, I must admit.  Because I was reading something there which I
knew had to be there, and overlooking the fact that it really wasn't
there.

> Finally saw it because of your
> redirection to the CGI module. Thanks a lot for pointing me at the missing
> colon...

Are you sure you've got the right point out of this exchange?

Merely inserting the missing colon may bring relief from the immediate
symptoms, but who knows what other anomalies lurk in waiting?

Your hand-knitted code _looks_ OK and does (I think) now conform to
the published CGI specification.  But you're using a server whose
reputation for conforming to that same specification is less than
ideal.  At various times it's been necessary for CGI.pm to apply
fixups to get MS's web servers to behave as required.  You could get
that sort of fix for free if you would use CGI.pm (and keep it
reasonably up to date).



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

Date: 12 Oct 2002 13:24:40 -0700
From: manutd_kit@yahoo.com (kit)
Subject: Re: question from beginner >_<
Message-Id: <1751b2b5.0210121224.5eef7612@posting.google.com>

pkent <pkent77tea@yahoo.com.tea> wrote in message news:<pkent77tea-E009AD.10442912102002@news-text.blueyonder.co.uk>...
> In article <1751b2b5.0210112148.27350cc@posting.google.com>,
>  manutd_kit@yahoo.com (kit) wrote:
> 
> > 3) I am trying to make a game for my class, hmm ........ if I want to
> > make it works online, like playing in 2 different computers, what
> > should I do?
> 
> Depends on the kind of game. Do you want a client-server model, a peer 
> to peer model, or something else? Wha sort of game is it, and have you 
> written any of it already? How OS dependent does the code have to be? 
> Etc.
> Perl can probably do a lot, if not all, of what you want.
> 
> P

Thanks for you help, I am currently working on a board game for my
class, I 've already implemented it in c++, and I have to work on it
in perl. I want to explore more on the networking part of the game,
could you give me any suggestions?
what about linux to linux , win to linux and win to win ??


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

Date: Sat, 12 Oct 2002 13:26:38 +0228
From: Gord Shier <shier@shorcan.com>
Subject: Thread::Queue; or variable scope?
Message-Id: <tWZp9.21100$ZO1.1503117@news20.bellglobal.com>

Hi.
I posted this originally to comp.lang.perl, but have subsequently told that 
that newsgroup isn't used, and that this is the correct forum:

Hi.

I'm fairly new to perl programming (as will become apparent).

I'm trying to write a little perl program that will create 2 threads -- one 
to produce some information (thr1), and one to process it (thr2).  The 
first thread will pass the information to the second using a Thread::Queue.

The problem is that the subroutines that are run for each thread seem to 
get their own copy of the Queue.  thr1 can enqueue things onto the queue, 
and can see that they're there, but the original main thread doesn't see 
them.  thr2 can dequeue things from the queue that are enqueued before the 
threads are created, but cannot see anything enqueued after the threads are 
created by other threads.

I think that each of the threads is getting a copy of the original Queue, 
but I don't know how to stop it.

I've included my code, and the output (which hangs at the end, since thr2 
(child) is still waiting to dequeue something):

Best regards to all,
Gord.



the program:
------------------------------------
#!/usr/bin/perl

use Thread;
use Thread::Queue;

use vars qw($queue);

my $queue ;
my $val ;
my $thr1;
my $thr2;

my $queue = new Thread::Queue;
print "main queue = $queue\n";

$queue->enqueue("1");

print "starting thr1\n";
$thr1 = new Thread \&parent;

print "starting thr2\n";
$thr2 = new Thread \&child;

print "joining thr1\n";
$thr1->join;
print "returned from join1\n";
print "main count = " . $queue->pending() . "\n";

print "joining thr2\n";
$thr2->join;
print "returned from join2\n";

exit 0;

#------------------------------------------------------------------------

sub parent {
        print "parent running\n";
        print "parent queue = $queue\n";
        print "parent count = " . $queue->pending() . "\n";
        $queue->enqueue("1");
        print "parent count = " . $queue->pending() . "\n";
        $queue->enqueue("2");
        print "parent count = " . $queue->pending() . "\n";
        $queue->enqueue("3");
        print "parent count = " . $queue->pending() . "\n";
        #exit 0;
}

#------------------------------------------------------------------------

sub child {
        print "child running\n";

        print "child sleeping\n";
        sleep 5;
        print "child awake\n";

        print "child queue = $queue\n";

        print "count = " . $queue->pending() . "\n";
        $val = $queue->dequeue();
        print "val = $val\n";

        print "count = " . $queue->pending() . "\n";
        $val = $queue->dequeue();
        print "val = $val\n";
        #exit 0;
}
------------------------------------------------

the output:main queue = Thread::Queue=ARRAY(0x8149870)
starting thr1
starting thr2
parent running
parent queue = Thread::Queue=ARRAY(0x822b3a0)
parent count = 1
parent count = 2
parent count = 3
parent count = 4
joining thr1
returned from join1
main count = 1
joining thr2
child running
child sleeping
child awake
child queue = Thread::Queue=ARRAY(0x8290c78)
count = 1
val = 1
count = 0
^C
------------------------------------------------



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

Date: Sat, 12 Oct 2002 22:00:48 GMT
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: undef == true?
Message-Id: <slrnaqh6ls.4c0.garry@zfw.zvolve.net>

On Fri, 11 Oct 2002 10:48:02 -0700, peter <peter@nospam.calweb.com> wrote:
> I've encountered several cases where an undefined var or a var assigned 
> the value undef evaluated true or compared as true.  Does anyone know 
> the reason behind this?  I find it plain annoying.

You probably received the answer already in this thread, but... 

Another common mistake is a subroutine returning the scalar value
undef and the caller assigning the value to an array: 

  perl -wle 'sub z { undef } print "true" if my @a = z()'

If the subroutine is expected to return a list and needs to return a
failure indicator, then return the empty list for a false value in
list context.  

  perl -wle 'sub z { return } print "true" if my @a = z()'

-- 
Garry Williams


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 3960
***************************************


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