[19901] in Perl-Users-Digest
Perl-Users Digest, Issue: 2096 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 8 18:10:47 2001
Date: Thu, 8 Nov 2001 15:10:11 -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: <1005261011-v10-i2096@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 8 Nov 2001 Volume: 10 Number: 2096
Today's topics:
Re: passing array values from perl to javascript <samneric@tigerriverOMIT-THIS.com>
Re: passing array values from perl to javascript <samneric@tigerriverOMIT-THIS.com>
Re: Removing whitespace from list / array (Tad McClellan)
Re: repeated string <spam@thecouch.homeip.net>
Re: repeated string <tsee@gmx.net>
Script to generate Perl Docs in HTML jks@saba.bass
Re: Unix executed thru CGI? <tsee@gmx.net>
Re: Unix executed thru CGI? <uri@stemsystems.com>
Re: Unix executed thru CGI? <tsee@gmx.net>
Re: Unix executed thru CGI? (Tad McClellan)
Re: Unix executed thru CGI? <tintin@snowy.calculus>
VVP: Variable = system command (vivekvp)
Re: VVP: Variable = system command (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 8 Nov 2001 16:50:18 -0500
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: passing array values from perl to javascript
Message-Id: <MPG.16549193f062d5419896bc@news.onemain.com>
hugo wrote:
> I am trying to pass an array with values from a perl to a javascript
> array, then open a new window which displays the javascript array
> values. I am reading in the perl array into the javascript array with
> print statements, and this seems to work well (when I look at thepage
> source). However, when I try to transfer the javascript array values to
> a new window, and display them, nothing happens. An alert statement
> attempting to display the [0] index value of the javascript array states
> that it is undefined.
I've mixed these 2 languages in the past, and found it easier to write the
javascript to a static page with temporary static values plugged into the
variables. After I get that code working correctly, then I write the perl code
to dynamically produce that javascript code and insert the variable values.
Then any new errors are introduced by my own sloppy perl coding of already-
functioning js code.
> Here is my code:
> 1. First, in my perl code, I read fill in the javascript array with
> values from the perl array (@data is my perl array and jsinfile is my
> javascript array):
>
> print "<SCRIPT LANGUAGE=\"javascript\">";
print "<!--\n";
> print "var jsinfile = new Array();";
You printed a semi-colon after "Array()", but...
> for ($i = 0; $i < @data; $i++) {
> chomp $data[$i];
> print "jsinfile[$i] = \"$data[$i]\"";
> }
...NO LINEFEEDS OR SEMI-COLONS IN THAT PRINT STATEMENT!
So your finished js statements look like:
jsinfile[0] = "zero"jsinfile[1] = "one"jsinfile[2] = "two"
print "// -->\n";
> print "</SCRIPT>";
BTW, adding trailing linefeeds ("\n") to each line also makes it easier to
debug your javascript code in the page source after you load it into the
browser when you have a problem. And omitting them is a good way to introduce
browser-specific problems during the js parsing...
> Then I have a form with a button to view the new page, with an onClick
> statement, passing the jsinfile array to the function which opens the
> new page:
>
> print "<FORM METHOD=\"POST\" ENCTYPE=\"multipart/form-data\">";
> print "<p>View double-spaced file?";
> print "<INPUT TYPE=\"SUBMIT\" VALUE=\"View\"
> onClick=\"javascript:open_outfile1(jsinfile)\">";
> print "</FORM>";
Minor point: You have declared a global array infile[]. Why are you passing it
to a function as an argument when it's already globally available within that
function?
> Then I have the javascript function which is activated by onClick and
> opens the new window. The new window is opened but no jsinfile values
> are displayed in the page. Note that this function occurs earlier in the
> code (i.e. higher up), but that shouldn't matter. The window alert on
> the third line states that jsinfile is undefined.
>
> print "<SCRIPT LANGUAGE=\"javascript\">";
> print "function open_outfile1(jsinfile) {";
> print "window.alert(\"jsinfile (in javascript function) is : \" +
> jsinfile[0]);";
> print "newWindow = window.open('','newWin',
> 'toolbar=yes,location=yes,scrollbars=yes,resizable=yes,width=500,height=500,');";
> print "newWindow.document.write(\"<html><head><title>Double spaced
Your next problem:
You're writing here to a window that isn't necessarily open yet. The OS may not
have finished creating the object, and you can't count on js pausing for that
to happen.
See: http://developer.irt.org/script/358.htm - Why when writing into a popup
window does Internet Explorer return with 'Access is denied'?
------------------------------
Date: Thu, 8 Nov 2001 16:53:33 -0500
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: passing array values from perl to javascript
Message-Id: <MPG.1654c8e96b65b5f19896bd@news.onemain.com>
hugo wrote:
> I am trying to pass an array with values from a perl to a javascript
> array, then open a new window which displays the javascript array
> values. I am reading in the perl array into the javascript array with
> print statements, and this seems to work well (when I look at thepage
> source). However, when I try to transfer the javascript array values to
> a new window, and display them, nothing happens. An alert statement
> attempting to display the [0] index value of the javascript array states
> that it is undefined.
I've mixed these 2 languages in the past, and found it easier to write the
javascript to a static page with temporary static values plugged into the
variables. After I get that code working correctly, then I write the perl code
to dynamically produce that javascript code and insert the variable values.
Then any new errors are introduced by my own sloppy perl coding of already-
functioning js code.
> Here is my code:
> 1. First, in my perl code, I read fill in the javascript array with
> values from the perl array (@data is my perl array and jsinfile is my
> javascript array):
>
> print "<SCRIPT LANGUAGE=\"javascript\">";
print "<!--\n";
> print "var jsinfile = new Array();";
You printed a semi-colon after "Array()", but...
> for ($i = 0; $i < @data; $i++) {
> chomp $data[$i];
> print "jsinfile[$i] = \"$data[$i]\"";
> }
...NO LINEFEEDS OR SEMI-COLONS IN THAT PRINT STATEMENT!
So your finished js statements look like:
jsinfile[0] = "zero"jsinfile[1] = "one"jsinfile[2] = "two"
print "// -->\n";
> print "</SCRIPT>";
BTW, adding trailing linefeeds ("\n") to each line also makes it easier to
debug your javascript code in the page source after you load it into the
browser when you have a problem. And omitting them is a good way to introduce
browser-specific problems during the js parsing...
> Then I have a form with a button to view the new page, with an onClick
> statement, passing the jsinfile array to the function which opens the
> new page:
>
> print "<FORM METHOD=\"POST\" ENCTYPE=\"multipart/form-data\">";
> print "<p>View double-spaced file?";
> print "<INPUT TYPE=\"SUBMIT\" VALUE=\"View\"
> onClick=\"javascript:open_outfile1(jsinfile)\">";
> print "</FORM>";
Minor point: You have declared a global array infile[]. Why are you passing it
to a function as an argument when it's already globally available within that
function?
> Then I have the javascript function which is activated by onClick and
> opens the new window. The new window is opened but no jsinfile values
> are displayed in the page. Note that this function occurs earlier in the
> code (i.e. higher up), but that shouldn't matter. The window alert on
> the third line states that jsinfile is undefined.
>
> print "<SCRIPT LANGUAGE=\"javascript\">";
> print "function open_outfile1(jsinfile) {";
> print "window.alert(\"jsinfile (in javascript function) is : \" +
> jsinfile[0]);";
> print "newWindow = window.open('','newWin',
> 'toolbar=yes,location=yes,scrollbars=yes,resizable=yes,width=500,height=500,');";
> print "newWindow.document.write(\"<html><head><title>Double spaced
Your next problem:
You're writing here to a window that isn't necessarily open yet. The OS may not
have finished creating the object, and you can't count on js pausing for that
to happen.
See: http://developer.irt.org/script/358.htm - Why when writing into a popup
window does Internet Explorer return with 'Access is denied'?
------------------------------
Date: Thu, 08 Nov 2001 19:08:44 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Removing whitespace from list / array
Message-Id: <slrn9uljen.k5v.tadmc@tadmc26.august.net>
mark <mark.adaoui@siemens.at> wrote:
>My code:
>#!usr/local/bin/perl
^^
^^
Is the truly your code?
How are you invoking the program?
Didn't notice that missing character before...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 8 Nov 2001 14:25:09 -0500
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: repeated string
Message-Id: <LZAG7.1568$H82.149757@weber.videotron.net>
"Houda Araj" <Houda.Araj@cogmedia.com> wrote in message
news:21916d9f.0111081100.34a2f06d@posting.google.com...
> I have a file that I want a perl script to (1) read, (2) find all
> identical repeated strings within that file and (3) mark the repeated
> strings with <>
> Any info is appreciated. Thanks!
How large is the file ?
The reason is, you need to parse the entire file for sure.
If the file is fairly small, you can store each line you find as a key in
the hash and increment that key by 1 every time it's encountered. This is
(comparatively) fast but will take up a lot of memory.
The other option is to use a module to calculate the checksum for each line,
then use that in a logic similar to the above. Calculating the checksum will
slow down reading the file, but the checksum stored will take up less memory
than the above.
your call !
------------------------------
Date: Thu, 8 Nov 2001 20:33:41 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: repeated string
Message-Id: <9semi8$862$04$1@news.t-online.com>
"Mina Naguib" <spam@thecouch.homeip.net> schrieb im Newsbeitrag
news:LZAG7.1568$H82.149757@weber.videotron.net...
|
| "Houda Araj" <Houda.Araj@cogmedia.com> wrote in message
| news:21916d9f.0111081100.34a2f06d@posting.google.com...
| > I have a file that I want a perl script to (1) read, (2) find all
| > identical repeated strings within that file and (3) mark the repeated
| > strings with <>
^^^^^^^
| > Any info is appreciated. Thanks!
|
| How large is the file ?
|
| The reason is, you need to parse the entire file for sure.
| If the file is fairly small, you can store each line you find as a key in
| the hash and increment that key by 1 every time it's encountered. This is
| (comparatively) fast but will take up a lot of memory.
[...]
The OP used the word "string", not line. I hope the OP meant "line" because
marking repeated strings (including single chars) does not make sense.
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m
------------------------------
Date: Thu, 08 Nov 2001 19:54:54 GMT
From: jks@saba.bass
Subject: Script to generate Perl Docs in HTML
Message-Id: <m37kt1599s.fsf@saba.bass>
Hello all,
Does anyone know of a script that will build a tree of all of the Perl
documentation in HTML format? I have experimented with installhtml, but
I wind up with incomplete directories, broken links, etc. I am looking for
something that builds ALL of the documentation (e.g. includes a page for h2xs).
It would be nice if it builds indexes etc.
Any help is much appreciated.
Thanks,
John
------------------------------
Date: Thu, 8 Nov 2001 20:31:08 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Unix executed thru CGI?
Message-Id: <9semdj$pk1$00$1@news.t-online.com>
[agh, a top post!]
"Brian Janko" <brian@jankoNOnet.SPAMcom.INVALID> schrieb im Newsbeitrag
news:2miG7.92763$tb2.7391962@bin2.nnrp.aus1.giganews.com...
| This is for an intranet at work which any user can access web pages from.
| The Unix command is a specific which I will set up. As far as the user
| knows, they just click a button. On the OS, their button-pushing simply
| copies the file to another file with a different name. The user does not
| know what goes on in the background.
First: As found in one of Uri-"I never use shift"'s replies to another
top-poster:
http://www.btinternet.com/~chiba/sbox/topposters.html
http://www.uwasa.fi/~ts/http/quote.html
http://www.geocities.com/nnqweb/nquote.html
Please read those.
Anyway, if you just want to copy a file, you can use Perl to do that. No
reason to use a Unix command. The File::Copy module from CPAN may be exactly
what you are looking for!
HTH,
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m
------------------------------
Date: Thu, 08 Nov 2001 19:38:13 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Unix executed thru CGI?
Message-Id: <x7pu6trr1h.fsf@home.sysarch.com>
>>>>> "SM" == Steffen Müller <tsee@gmx.net> writes:
SM> First: As found in one of Uri-"I never use shift"'s replies to another
SM> top-poster:
I RESEMBLE THAT REMARK!
:-)
SM> http://www.btinternet.com/~chiba/sbox/topposters.html
SM> http://www.uwasa.fi/~ts/http/quote.html
SM> http://www.geocities.com/nnqweb/nquote.html
i now have those url's in a emacs buffer so i can insert them
quickly. between the 3 of them top-posters sometimes seem to get the
clue.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 8 Nov 2001 21:03:17 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Unix executed thru CGI?
Message-Id: <9seo9p$mao$03$1@news.t-online.com>
"Uri Guttman" <uri@stemsystems.com> schrieb im Newsbeitrag
news:x7pu6trr1h.fsf@home.sysarch.com...
| >>>>> "SM" == Steffen Müller <tsee@gmx.net> writes:
|
| SM> First: As found in one of Uri-"I never use shift"'s replies to
another
| SM> top-poster:
|
| I RESEMBLE THAT REMARK!
|
| :-)
Glad to hear that.
| SM> http://www.btinternet.com/~chiba/sbox/topposters.html
| SM> http://www.uwasa.fi/~ts/http/quote.html
| SM> http://www.geocities.com/nnqweb/nquote.html
I really could kick my parents where it hurts and enjoy it for blessing me
with those initials. ;)
| i now have those url's in a emacs buffer so i can insert them
| quickly. between the 3 of them top-posters sometimes seem to get the
| clue.
Umpf. I need another newsreader for multiple buffers. This one even
encourages top-posting. Hell, I need *a* newsreader.
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m
------------------------------
Date: Thu, 08 Nov 2001 20:38:53 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Unix executed thru CGI?
Message-Id: <slrn9ulon0.kf4.tadmc@tadmc26.august.net>
Uri Guttman <uri@stemsystems.com> wrote:
> SM> http://www.btinternet.com/~chiba/sbox/topposters.html
> SM> http://www.uwasa.fi/~ts/http/quote.html
> SM> http://www.geocities.com/nnqweb/nquote.html
>
>i now have those url's in a emacs buffer so i can insert them
>quickly. between the 3 of them top-posters sometimes seem to get the
>clue.
Maybe they will believe it if Microsoft says so?
Randal posted this URL a while ago:
http://www.jsiinc.com/newsgroup_document.htm
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 9 Nov 2001 08:15:04 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Unix executed thru CGI?
Message-Id: <WzCG7.1$hb.155731@news.interact.net.au>
"Steffen Müller" <tsee@gmx.net> wrote in message
news:9semdj$pk1$00$1@news.t-online.com...
>
> Anyway, if you just want to copy a file, you can use Perl to do that. No
> reason to use a Unix command. The File::Copy module from CPAN may be
exactly
> what you are looking for!
No need to grab File::Copy from CPAN, it's part of core Perl.
------------------------------
Date: 8 Nov 2001 12:37:05 -0800
From: vivekvp@spliced.com (vivekvp)
Subject: VVP: Variable = system command
Message-Id: <9bf633be.0111081237.3137b0bb@posting.google.com>
Hello,
Can I do this:
$last=system("tail test.txt")
and have the variable $last filled with the last lines of the file
'test.txt'.
I tried it - and $last always comes out as 0 - not the last lines of
the file 'test.txt'.
I have a bunch of files that end with .txt and I want to get the last
part of each file and list them.
So I would get
<file_name>
(last lines of <file_name>)
<file_name>
(last lines of <file_name>)
etx
So far I have this:
#!/usr/bin/perl
open (sd,"all.sds"); <---this is a file of all the *.txt files
open (tail,">sdstails.txt");
while ($line=<sd>) {
system("tail $line");
print tail "$line $sds \n";
}
any help?
Thanks,
V
------------------------------
Date: Thu, 08 Nov 2001 21:04:20 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: VVP: Variable = system command
Message-Id: <slrn9ulpsn.ki5.tadmc@tadmc26.august.net>
vivekvp <vivekvp@spliced.com> wrote:
>
>$last=system("tail test.txt")
>
>and have the variable $last filled with the last lines of the file
>'test.txt'.
>#!/usr/bin/perl
You should ask for all the help you can get:
#!/usr/bin/perl -w
use strict;
>open (sd,"all.sds"); <---this is a file of all the *.txt files
You should always, yes *always*, check the return value from open():
open (SD,"all.sds") or die "could not open 'all.sds' $!";
it is also conventional to use UPPER CASE for filehandles, else
your code will stop working when you upgrade to Perl version
12.5 and it has a new 'sd' keyword in it...
>any help?
You can get help by reading the documentation for the functions
that you use!
perldoc -f system
tells you how to capture an external program's output.
You must have missed it, try reading it again.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 2096
***************************************