[20026] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2221 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 27 18:10:31 2001

Date: Tue, 27 Nov 2001 15:10:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006902612-v10-i2221@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 27 Nov 2001     Volume: 10 Number: 2221

Today's topics:
    Re: PERL puzzler: Date re-ordering to meet xsd format? <bart.lateur@pandora.be>
    Re: perl script <bart.lateur@pandora.be>
    Re: Re: Do some time calculations... (Logan Shaw)
    Re: replacing certain 'bad' words globally (Ralph Leonhardt)
        Request Regex Help <jc_va@hotmail.com>
    Re: Request Regex Help <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Request Regex Help <Laocoon@eudoramail.com>
    Re: Script for stripping FONT (HTML) tags <jurgenex@hotmail.com>
        Summing Array Elements (BUCK NAKED1)
    Re: Summing Array Elements <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Summing Array Elements <whataman@home.com>
    Re: Top-posts <me@my_no_spam.org>
        Using frames with PERL? (Kumaran Srimantha)
    Re: Using frames with PERL? <tony_curtis32@yahoo.com>
    Re: Using frames with PERL? <spam@thecouch.homeip.net>
    Re: Using frames with PERL? <echang@netstorm.net>
    Re: var per url! <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 27 Nov 2001 20:38:25 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: PERL puzzler: Date re-ordering to meet xsd format?
Message-Id: <ucu70us2ttn37pq0if2pq7ssb14nv3barj@4ax.com>

Ken Fine wrote:

>7.1.2001
>
>How can I reorder it using PERL substitutions to meet the xsd lexical form,
>which in the example above would be:
>
>2001-01-07
>
>It's a little trickier than your average PERL puzzle, because if there is
>only a single digit in the "day" or "month" field, a zero must be added to
>precede the value.

	print sprintf "%04d-%02d-%02d", reverse split /\./, '7.1.2001';

-- 
	Bart.


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

Date: Tue, 27 Nov 2001 20:36:04 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: perl script
Message-Id: <01u70u8id81vl5p8a3hc7fq5hj74d27pf8@4ax.com>

Bill Meyer wrote:

>This basically makes a http request and retrieves the information. I
>would like to add a function to record the length of time it takes for
>the request to be returned.

Get/install the module Time::HiRes, if it's not alreayd on your system.
Then write down the time before you start, and when you finish. Get the
difference between the two.

	use Time::HiRes;
	my $t0 = Time::HiRes::time;
	sleep 1;
	my $t1 = Time::HiRes::time;
	my $delta = $t1 - $t0;
	print "I slept for $delta second(s).\n";

-- 
	Bart.


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

Date: 27 Nov 2001 13:48:16 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Re: Do some time calculations...
Message-Id: <9u0qm0$5hs$1@starbuck.cs.utexas.edu>

In article <pYQM7.155472$QL2.4782888@amsnews03.chello.com>,
 <nobody@nowhere.com> wrote:
>> "nobody" <nobody@nobody.com> wrote in message

>> print scalar localtime(int(time()/86400)*86400);
>> 
>> produces;
>> Tue Nov 27 00:00:00 2001

>It produces:
>
>Tue Nov 27 01:00:00 2001
>
>on my pc!

On some local Linux and Solaris machines, it produces this:

	Mon Nov 26 18:00:00 2001

"print scalar localtime" produces this:

	Tue Nov 27 13:47:28 2001

So it's not even the right day...

  - Logan
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: Tue, 27 Nov 2001 20:55:02 +0100
From: ralphl@lrz.uni-muenchen.de (Ralph Leonhardt)
Subject: Re: replacing certain 'bad' words globally
Message-Id: <m2r0u9.81e.ln@cantor.local>

In article <9tpal4$8iu$1@news6.svr.pol.co.uk>,
	"Louis" <louisdepointedulac@theatredesvampires.freeserve.co.uk> writes:
> Hi, joe newbie here, so bare with me!
> 
> i was after a script that i could customize to include a list of bad words
> and a list of words to replace them with
> 
> and also this would need to be able to pick out the word anywhere on any
> page and replace it there in situe
Hi, 
I have a similar problem very often. So i started a small module.
I admit that it is  really ugly currently but it works.
For a real large bulk of replacements there exists a Data base based version.
But this is even uglier than the version below.
If you are interested let me know...

	Bye Ralph

package Synonyms;
use strict;
=head1
Synonym Tables (stables) are hashes where the target word is the key and
the synonyms for this target are stored in an anonymous array.  

rtables are hashes with the synonyms as keys and the target as 
values.
=cut

=head1
Synonyms new(hashref)

creates an rtable from an stable
my $s=Synonyms->new({
badass=>['gentleman','politician']
})

it takes care (dies) if circular synonyms are made
=cut
sub new {
    my $self=shift;
    my $stable=shift; #referenz auf synonymtabelle oder anonyme Stabelle
#now building r-table
    my %rtable=();
    foreach my $k (keys %$stable){ 
	next unless $k;
	foreach my $v (@{$$stable{$k}}){
	    die "Circular replacement  Value $v is key too \n" if $rtable{$k};
	    $rtable{$v}=$k;
#	    print "V: ",$v," Rtable: ",$rtable{$v},"\n";
	}
    }
    return bless \%rtable,$self;
}
=head1
returns a hashref to an r-table
=cut

sub get_rtable{
    my $self=shift;
    my %rtable=%$self;
    return \%rtable;
}

sub get_keywords{
    my $self=shift;
    my %stable;
    foreach my $k (keys %$self){
	$stable{$$self{$k}}=$k;
    }
    return keys %stable;
}
=head1
@syns=$s->get_synonyms($badword);
returns undef if  $badword is not a target
returns all synonyms for a targe
=cut
sub get_synonyms_for{
    my $self=shift;
    my $synonym=shift;
    my @ar=();
    while(my ($key,$value)=each %$self){
	push  @ar,$key if ($self->{$key} eq $synonym) ;
    }
    return @ar;
}
	
sub add_synonym {} #für namen den tabelleneintrag hinzufügen
sub delete_synonym {} #für name tabelle löschen
sub delete_synonym_name_for {} #name, synonym to be deleted
sub add_synonym_name_for {} #name, synonym to be added

=head1
translate

This is the workhorse.
 $cleanword=$s->translate($badword) if $s->translate($badword);

if $badword is not found undef is returned 
=cut

sub translate{ #ersetzt synonyme durch name
    my $self=shift;
    my $syn=shift; 
    return $self->{$syn} if $self->{$syn};
    return undef;
} #  ersetzt sämtliche synonyme durch ausgangswort(argument)

1;



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

Date: Tue, 27 Nov 2001 21:34:04 +0000 (UTC)
From: "Buck Turgidson" <jc_va@hotmail.com>
Subject: Request Regex Help
Message-Id: <0b0a74559d0feb55e0f13dfc3215fad7.38849@mygate.mailgate.org>

I am trying to search through an NT directory of code modules for filenames
that are uppercase.  Then I will update them manually, so that they'll run in
Unix, due to the case-sensitivity.

A typical line of code that I want to flag is:

#include 'Update.Mod'  ! and possibly a comment starting with an excl. point.

or 

#Include 'Update.Mod'  ! and possibly a comment starting with an excl. point.

The uppercase "Include" is ok, but not the embedded file name, which I want to
change.

Here is my perl grep script, but it is not capturing what I want, it's getting
them anyway.  Can someone spot my error?

gr "#Include|#include\w'+[A-Z]'" *.*


-- 
Posted from  [65.193.99.4] 
via Mailgate.ORG Server - http://www.Mailgate.ORG


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

Date: Tue, 27 Nov 2001 22:58:07 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Request Regex Help
Message-Id: <9u129f$sp5$07$1@news.t-online.com>

On Tue, 27 Nov 2001 21:34:04 +0000 (UTC), Buck Turgidson wrote:

[...]

> Here is my perl grep script, but it is not capturing what I want, it's getting
> them anyway.  Can someone spot my error?
> 
> gr "#Include|#include\w'+[A-Z]'" *.*

This is no Perl script.

Tassilo
-- 
Ernest asks Frank how long he has been working for the company.
	"Ever since they threatened to fire me."


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

Date: Tue, 27 Nov 2001 23:01:03 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Request Regex Help
Message-Id: <Xns9166EA2B1384FLaocooneudoramailcom@62.153.159.134>

$filename = $1 if /#[iI]nclude\s+'([A-Z][^']+)'/;


Hope this helps u

Lao


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

Date: Tue, 27 Nov 2001 12:29:22 -0800
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Script for stripping FONT (HTML) tags
Message-Id: <3c03f7a2$1@news.microsoft.com>

"Tor Fuglerud" <t.k.fuglerud@hf.uio.no> wrote in message
news:3c03b453.15485216@nntp.uio.no...
> On Wed, 21 Nov 2001 21:20:08 +0100, ggd@gaura.nitai.hr (Sasa Janiska)
wrote:
> >I'm pretty newbie in the Perl and soem concrete task is ahead of me which
> >has to be finished asap.
> >
> >Please, do you know for any script which can strip <FONT>, </FONT> and
> ><FONT SIZE="+1"> tags from the html files.

> [A solution based on pattern matching]

You may want to read the FAQ answer about why it's a bad idea to do HTML
parsing on your own.
HTML::Parser does this nicely and more important: correctly.

jue




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

Date: Tue, 27 Nov 2001 14:58:45 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Summing Array Elements
Message-Id: <20815-3C03FE85-243@storefull-247.iap.bryant.webtv.net>

I've reviewed the docs and Google. How do I get the sum of all the
elements in an array, AND make sure that each element is a digit. I'm
trying to add up all the file sizes of all of the files in @url. What am
I doing wrong?

$url = param("url");
@url = split(" ", $url);
foreach $f(@url) {
   $urlsize = get($f);
   $urlsize = length($urlsize); 
   $urlsize =~ /^\d/ or die "$urlsize must be a digit: $!";
   }
my $Key; 
my $Total; 
foreach $Key (@urlsize) { 
$Total += $Key; 
}
print $Total;



NOTE: I didn't use LWP's "head($url)" because servers don't always send
a head.

Thanks,
Dennis



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

Date: Tue, 27 Nov 2001 22:54:38 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Summing Array Elements
Message-Id: <9u122u$d4g$01$1@news.t-online.com>

On Tue, 27 Nov 2001 14:58:45 -0600 (CST), BUCK NAKED1 wrote:
> I've reviewed the docs and Google. How do I get the sum of all the
> elements in an array, AND make sure that each element is a digit. I'm
> trying to add up all the file sizes of all of the files in @url. What am
> I doing wrong?
> 
> $url = param("url");
> @url = split(" ", $url);
> foreach $f(@url) {
>    $urlsize = get($f);
>    $urlsize = length($urlsize); 
>    $urlsize =~ /^\d/ or die "$urlsize must be a digit: $!";
     ^^^^^^^^
>    }
> my $Key; 
> my $Total; 
> foreach $Key (@urlsize) { 
                ^^^^^^^^
> $Total += $Key; 
> }
> print $Total;

@urlsize is an unitialized array in your script. Had you used 'strict'
you had been told about this by Perl. :-)
Why do you check whether the return-value of length() only consists of
digits? This is not necessary since length will always return a number.
Something like this would be a more direct approach:

my $size = 0;
$size += length get $_ for @url;
print $size;
    
Tassilo
-- 
The mother of the year should be a sterilized woman with two adopted children.
		-- Paul Ehrlich


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

Date: Tue, 27 Nov 2001 22:55:19 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: Summing Array Elements
Message-Id: <3C0419F4.2BB4407D@home.com>

"Tassilo v. Parseval" wrote:
> 

> @urlsize is an unitialized array in your script. Had you used 'strict'
> you had been told about this by Perl. :-)
Thanks for stating that in a kindly manner. I should've done that. I
usually try "use strict"; but forgot to this time. I also usually
utilize "use diagnostics", "-w", "-d" and everything else I can to
figure out my problem before posting. My server doesn't have "use
warnings" though. I wish they did. I have questions about all of these
debugging methods; but that's another thread, another day.

> Why do you check whether the return-value of length() only consists of
> digits? This is not necessary since length will always return a number.
> Something like this would be a more direct approach:
OK, but what if length of one of the array elements is undefined and I
want to "die"?
 
> my $size = 0;
> $size += length get $_ for @url;
> print $size;
> 
Thanks. Those 3 simple lines sure replace my mess nicely and simply. I
spent a day working with this and researching. Also, thanks for adding
an explanation so that I can study it and hopefully not make the same
mistakes again. I've never used "get" or "for" in this type of
statement. I always use something like 
  
foreach $f(@url) { 
#do something
} 

or 

get($url) or die "could not GET $url: $!"\n";


so getting the statement correct was part of my problem. Why do you have
to give $size a value of 0, before defining $size?

At least I was using the correct operator(+=). :-)

Have a Great Day!
--Dennis


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

Date: Tue, 27 Nov 2001 16:26:26 -0500
From: Dave VP <me@my_no_spam.org>
Subject: Re: Top-posts
Message-Id: <3C040502.45A42563@my_no_spam.org>

"Randal L. Schwartz" wrote:
> 
> Just because a certain Redmond company put the default cursor ahead of
> the quoted text doesn't mean that this is a better way of doing
> things.  Ask the people who have been involved in online communities
> longer than that company has been in existance.

I'm convinced it *is* a M$-driven phenomenon.  Take a look at
microsoft.pub.* for a mess of top-posts.

Dave


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

Date: 27 Nov 2001 11:35:08 -0800
From: kumaran76@yahoo.com (Kumaran Srimantha)
Subject: Using frames with PERL?
Message-Id: <861ae413.0111271135.1dc1b19a@posting.google.com>

hello, 

          I have a question regarding using PERL with HTML frames. 
          Please find the perl program below. 

          -------- 

          #!/usr/local/bin/perl 

          print "Content-type:text/html", "\n\n"; 
          print "<html>"; 
          print "<head><title> Report </title></head>"; 

          print "<frameset rows=\"15%,85%\">"; 
          print "<frame src=\"menu_bar.html\" name=\"topmenu\">"; 
          print "<frame src=\"O49361.pdf\" name=\"mainwindow\">"; 
          print "</frameset>"; 

          print "</html>"; 

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

          When this perl program is run (i.e, when I point the web browser to 
          this perl program), it tries to execute the menu_bar.html 
          and the O49361.pdf instead of just displaying the 2 files. I 
          just want the 2 files to be displayed as is instead of it 
          getting executed. How do I do that? 

          Thanx in advance, 
          -Kumaran


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

Date: Tue, 27 Nov 2001 14:00:15 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Using frames with PERL?
Message-Id: <87667wt25s.fsf@limey.hpcc.uh.edu>

>> On 27 Nov 2001 11:35:08 -0800,
>> kumaran76@yahoo.com (Kumaran Srimantha) said:

> hello, I have a question regarding using PERL with HTML
> frames.  Please find the perl program below.

>           --------

>           #!/usr/local/bin/perl

>           print "Content-type:text/html", "\n\n"; print
> "<html>"; print "<head><title> Report </title></head>";

>           print "<frameset rows=\"15%,85%\">"; print
> "<frame src=\"menu_bar.html\" name=\"topmenu\">"; print
> "<frame src=\"O49361.pdf\" name=\"mainwindow\">"; print
> "</frameset>";

>           print "</html>";

>           -------------

>           When this perl program is run (i.e, when I
> point the web browser to this perl program), it tries to
> execute the menu_bar.html and the O49361.pdf instead of
> just displaying the 2 files.

No it doesn't.  It outputs the above HTML.  Test by
running the program from the command-line.  You appear to
be confused as to what "it" is.  From the context of your
post, "it" is the perl program, but what you presumably
mean is that "it" is the result of trying to access the
appropriate URL pointing at this program from within a
browser.

So this is almost certainly a server configuration
problem.

> I just want the 2 files to be displayed as is instead of
> it getting executed. How do I do that?

I don't think that is the case either.  You want
"clickable links" to those files (relative URLs) to be
displayed within the HTML; you certainly don't want to
display the files themselves.

The problem is how the web server is treating your
program.  You'd have the same problem in any language; not
just perl.  So follow-ups set to

    comp.infosystems.www.servers.misc

(unless you can find a closer match to the server you are
using).

Also discover the CGI.pm module (standard in perl
distribution).  It makes the CGI part much easier and
saves you trying to output raw CGI/HTTP headers.

hth
t
-- 
Oh!  I've said too much.  Smithers, use the amnesia ray.


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

Date: Tue, 27 Nov 2001 15:03:36 -0500
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: Using frames with PERL?
Message-Id: <nkSM7.12156$et3.1808949@weber.videotron.net>


"Kumaran Srimantha" <kumaran76@yahoo.com> wrote in message
news:861ae413.0111271135.1dc1b19a@posting.google.com...
> hello,
>
>           I have a question regarding using PERL with HTML frames.
>           Please find the perl program below.
>
>           --------
>
>           #!/usr/local/bin/perl
>
>           print "Content-type:text/html", "\n\n";
>           print "<html>";
>           print "<head><title> Report </title></head>";
>
>           print "<frameset rows=\"15%,85%\">";
>           print "<frame src=\"menu_bar.html\" name=\"topmenu\">";
>           print "<frame src=\"O49361.pdf\" name=\"mainwindow\">";
>           print "</frameset>";
>
>           print "</html>";
>
>           -------------
>
>           When this perl program is run (i.e, when I point the web browser
to
>           this perl program), it tries to execute the menu_bar.html
>           and the O49361.pdf instead of just displaying the 2 files. I
>           just want the 2 files to be displayed as is instead of it
>           getting executed. How do I do that?
>
>           Thanx in advance,
>           -Kumaran

What tries to execute them ? The web server ? The web browser ? What exactly
are the symptoms as opposed to what you think is happening ?

Neither menu_bar.html or O49361.pdf are executables, so the web browser will
do it's best to try to accomodate displaying them in an appropriate manner
based on their MIME header. For the html document, the web browser should
display it internally. For the PDF document, it will try to launch the adobe
viewer windowed within the frame. If the viewer is not found it will prompt
you to save as/open.

Can you tell us EXACTLY what happens so we can help more ?

Also the above has no dynamic content whatsoever, so the above CGI is
nothing more than wasting system resources. Make it into a regular html file
and avoid perl altogether for this purpose.

However, if you DO decide you want to keep it in perl, there's an easier way
than multiple print statements.
Try this:

#!/usr/local/bin/perl

print <<"EOHTML";
Content-type:text/html

<html>
<head><title> Report </title></head>

<frameset rows="15%,85%">
<frame src="menu_bar.html" name="topmenu">
<frame src="O49361.pdf" name="mainwindow">
</frameset>

</html>
EOMHTML




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

Date: Tue, 27 Nov 2001 22:44:13 GMT
From: "E.Chang" <echang@netstorm.net>
Subject: Re: Using frames with PERL?
Message-Id: <Xns9166B581EAEA8echangnetstormnet@207.106.92.86>

kumaran76@yahoo.com (Kumaran Srimantha) wrote in
news:861ae413.0111271135.1dc1b19a@posting.google.com: 

> hello, 
> 
>           I have a question regarding using PERL with HTML frames. 
>           Please find the perl program below. 
[snip]
>           print "<frame src=\"menu_bar.html\" name=\"topmenu\">"; 
>           print "<frame src=\"O49361.pdf\" name=\"mainwindow\">"; 
[snip]
>           When this perl program is run (i.e, when I point the web
>           browser to this perl program), it tries to execute the
>           menu_bar.html and the O49361.pdf instead of just
>           displaying the 2 files. I just want the 2 files to be
>           displayed as is instead of it getting executed. How do I
>           do that? 

You haven't really provided all the background, so it is hard to guess 
the problem.  Based on what you did give, one possibility is that you 
have the script and the other two documents in the server's cgi-bin 
directory.  This placement tells the server to handle them all as 
executable programs.  If this is the problem, put the two source files 
under the document root and modify the URLs accordingly.

-- 
EBC


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

Date: Tue, 27 Nov 2001 12:37:55 -0800
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: var per url!
Message-Id: <3c03f9a4$1@news.microsoft.com>

"Benjamin Koertelt" <koertelt@melle-pufe.com> wrote in message
news:3c03770a$1@netnews.web.de...
> i want to pass my index.cgi a var (a path, for example
http://www.perl.com/)

A variable? Are you sure? Wouldn't a simple parameter/argument be good
enough?

> and now i want to create a frameset, like:
> <frame src=\"$url\" name=\"main\" noresize>\n";
> any idea?

Use "print" maybe?

jue




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

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


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