[7841] in Perl-Users-Digest
Perl-Users Digest, Issue: 1466 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 13 06:07:26 1997
Date: Sat, 13 Dec 97 03:00:20 -0800
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, 13 Dec 1997 Volume: 8 Number: 1466
Today's topics:
Re: 1st Script/Where's the bug ? <dformosa@st.nepean.uws.edu.au>
Re: accessing a file in directory other than cgi script (David Waring)
Re: Call a script automatically from a webpage <webmaster@fccj.cc.fl.us>
Re: Call a script automatically from a webpage <webmaster@fccj.cc.fl.us>
Re: Capturing the previous URL? (Abigail)
Re: date conversation ??? (Steffen Beyer)
delete file in perl <kelly_horst@hotmail.com>
Re: eof and low level io <rjk@coos.dartmouth.edu>
Re: eof and low level io <webmaster@fccj.cc.fl.us>
Re: Help with a regex <rjk@coos.dartmouth.edu>
Re: newbie: compact an array <NerveGas@nospam.com>
Only one execution in -ne <kistler@inf.ethz.ch>
Re: Perl Modules Info lvirden@cas.org
Perl on Netware? <mbowers@CimageD.com>
Re: Perl Plug-In for Netscape? lvirden@cas.org
Re: perl puzzler (brian d foy)
Re: problem with chomp() - actually it's split <nospam@domain.com>
problem with chomp() (John Cartwright)
Re: Restricting CGI Programs to Perl. <ejk@uiuc.edu>
Script calls embedded in web pages <ddbadowski@fedex.com>
Re: setting environment variable within perl script (brian d foy)
Re: There's More Than One Way? <nospam@domain.com>
Re: what does qq() do? (brian d foy)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Dec 1997 09:57:49 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: 1st Script/Where's the bug ?
Message-Id: <882007069.40193@cabal>
In <349193BD.FFAE131F@thebestjobs.com> Alex Craig <alexcraig@thebestjobs.com> writes:
>Decided to move up from Prism to Perl.
>My first script is supposed to simply read a file and strip out any
>addresses ending in .uk
>Unfortunately it leaves me with a blank file.
>Any help would be appreciated.
Your doing this in a very unusial mannor.
>@ARGV = ("c:\\pmail\\mail\\alex\\bulk1.pml");
An odd way of makeing perl load a file. And that path makes you look like
your an email spammer, which is makeing me realy nervious about giving you
adivce.
> $where = index($_,".uk\n");
> if ($where != -1) {
> $_ = '' # or try substr($_, 0);
> }
This whole section should be something like
if (not (/\.uk$/)) {
print;
}
--
Please excuse my spelling as I suffer from agraphia see the url in my header.
Never trust a country with more peaple then sheep. I do not reply to mungged
Support NoCeM http://www.cm.org/ addresses.
I'm sorry but I just don't consider 'because its yucky' a convincing argument
------------------------------
Date: Sat, 13 Dec 1997 00:24:14 -0800
From: dwaring@nwsr.com (David Waring)
Subject: Re: accessing a file in directory other than cgi script?
Message-Id: <dwaring-1312970024140001@blv-lx102-ip6.nwnexus.net>
I just want to reinforce what Bart says, pay no attention to others who
tell you to go to another newsgroup, your problem is most likely the path,
use and absolute path, (it could be permisions as another suggested but
you probably would have figured that out yourself).
In article <3491b70c.16915856@news.tornado.be>, bart.mediamind@tornado.be
(Bart Lateur) wrote:
> none@nowhere.com wrote:
>
> >Is it possible to open a file in a perl cgi script that is in a
> >superdirectory (or any other directory for that matter) than the one
> >which is in the script itself?
>
> The reason why it doesn't work, could be because your script is accessed
> via a different path than you think it is (via links).
>
> Try this script:
>
> print "Content-type: text/plain\n\n";
> print "This script is $0\n";
>
> I think you may be amazed about the result.
>
> The net result is that "..\datafile.txt" then tries to open a file in a
> different directory than you think it does.
>
> Using absolute paths doesn't look as nice, but ought to work.
>
> HTH,
> Bart.
------------------------------
Date: Fri, 12 Dec 1997 21:32:16 -0500
From: "Webmaster" <webmaster@fccj.cc.fl.us>
Subject: Re: Call a script automatically from a webpage
Message-Id: <3491f44b.0@usenet.fccj.cc.fl.us>
You would probably want to turn-on 'cgi' as a file type, so the URL would be
http://mysite.com/thepage.cgi (or some such.) However, this opens up a wide
security hole :-)
Try using something like the following -
----------------------------------------------------------------------
#!/usr/bin/perl
#
# simple redirection cgi. sends a different page location depending on
# the type of the browser accessing the page. In this example, it
# splits 3 ways, first for Netscape 2.0, second for lynx (text-only),
# and finally for all other browsers.
#
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if ($ENV{'HTTP_USER_AGENT'} =~ /^Mozilla\/*/) {
print "Location:http://www.fccj.cc.fl.us/index-netscape.html\n\n";
}
elsif ($ENV{'HTTP_USER_AGENT'} =~ /^Lynx.*/) {
print "Location:http://www.fccj.cc.fl.us/index-profs.html\n\n";
}
elsif ($ENV{'HTTP_USER_AGENT'} =~ /^Charlotte*/) {
print "Location:http://www.fccj.cc.fl.us/index-profs.html\n\n";
}
else {
# Most 'other' browsers are capable of displaying the New Page :)
print "Location:http://www.fccj.cc.fl.us/index-netscape.html\n\n";
}
----------------------------------------------------------------------
HTH,
Bill
Builders Connection wrote in message
<349150C8.506@builders-connection.com>...
>Call a script automatically from a webpage
>is there a way to call script automatically from a webpage just by
>logging on to that page. Say you go to http://mysite.com/thepage.htm
>and have the script run automatically to redirect you? All the scripts
>I've seen require some kind of action to make them work.
------------------------------
Date: Fri, 12 Dec 1997 21:39:06 -0500
From: "Webmaster" <webmaster@fccj.cc.fl.us>
Subject: Re: Call a script automatically from a webpage
Message-Id: <3491f5e4.0@usenet.fccj.cc.fl.us>
Or, this one :-)
HTH,
Bill
----------------------------------------------------------------------------
-------------
#!/usr/local/bin/perl
# Random Image Displayer
# Version 1.2 Created by: Matt Wright
# Created On: 7/1/95 Last Modified: 7/17/95
# I can be reached at: mattw@misha.net
# Scripts Archive at: http://worldwidemart.com/scripts/
# The file README contains more information and installation instructions.
# Necessary Variables
$basedir = "http://astro.fccj.cc.fl.us/~trevor/gifs/";
@files = ("Collage01.gif","Collage02.gif");
# Options
$uselog = 0; # 1 = YES; 0 = NO
$logfile = "/usr/home/trevor/logs/image-log";
srand;
$num = rand(@files); # Pick a Random Number
# Print Out Header With Random Filename and Base Directory
print "Location: $basedir$files[$num]\n\n";
# Log Image
if ($uselog eq '1') {
open (LOG, ">>$logfile");
print LOG "$files[$num]\n";
close (LOG);
}
exit;
# Shamelessly 'borrowed' from Matt :-)
----------------------------------------------------------------------------
-------------
Webmaster wrote in message <3491f44b.0@usenet.fccj.cc.fl.us>...
>You would probably want to turn-on 'cgi' as a file type, so the URL would
be
>http://mysite.com/thepage.cgi (or some such.) However, this opens up a
wide
>security hole :-)
>
>Try using something like the following -
>----------------------------------------------------------------------
>#!/usr/bin/perl
>#
># simple redirection cgi. sends a different page location depending on
># the type of the browser accessing the page. In this example, it
># splits 3 ways, first for Netscape 2.0, second for lynx (text-only),
># and finally for all other browsers.
>#
>read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>if ($ENV{'HTTP_USER_AGENT'} =~ /^Mozilla\/*/) {
> print "Location:http://www.fccj.cc.fl.us/index-netscape.html\n\n";
>}
>elsif ($ENV{'HTTP_USER_AGENT'} =~ /^Lynx.*/) {
> print "Location:http://www.fccj.cc.fl.us/index-profs.html\n\n";
>}
>elsif ($ENV{'HTTP_USER_AGENT'} =~ /^Charlotte*/) {
> print "Location:http://www.fccj.cc.fl.us/index-profs.html\n\n";
>}
>else {
># Most 'other' browsers are capable of displaying the New Page :)
> print "Location:http://www.fccj.cc.fl.us/index-netscape.html\n\n";
>}
>
>----------------------------------------------------------------------
>
>HTH,
>Bill
>
>
>Builders Connection wrote in message
><349150C8.506@builders-connection.com>...
>>Call a script automatically from a webpage
>>is there a way to call script automatically from a webpage just by
>>logging on to that page. Say you go to http://mysite.com/thepage.htm
>>and have the script run automatically to redirect you? All the scripts
>>I've seen require some kind of action to make them work.
>
>
------------------------------
Date: 13 Dec 1997 03:40:09 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Capturing the previous URL?
Message-Id: <slrn694103.50c.abigail@betelgeuse.wayne.fnx.com>
Brian Godden (bgodden@apple.com) wrote on 1564 September 1993 in
<URL: news:B0B701F7-4FB2D9@17.219.12.192>:
++ Hello,
++
++ I'm trying to capture the last URL accessed by a browser that goes to my
++ form and submits. Is there a ENV variable that grabs this? Is this even
++ possible? Just to clarify, I'm not talking about $ENV{'HTTP_REFERER'} that
++ grabs the forms actual URL.
You are wrong three times:
- This is not the appropriate group.
- HTTP_REFERER is the correct env. variable - but of course at the moment
the form was requested, not when the cgi program digesting the results
is requested. Unless you have a really wicked browser.
- In general, you can't get it. The header is not required, and in
certain cases, it should *not* be send.
Abigail
--
Followups set.
------------------------------
Date: 13 Dec 1997 07:42:51 GMT
From: sb@en.muc.de (Steffen Beyer)
Subject: Re: date conversation ???
Message-Id: <66te9r$evu$1@en1.engelschall.com>
Sigi <sigi@remsmurr.de.delete.this> wrote:
> I was wondering if someone has a fine little script or know of it wich
> takes todays date and says to me what date last friday (sample) had. I
> thank very much for grandiose answers and tips.
Get the "Date::DateCalc" module - available either from my web site at
http://www.engelschall.com/u/sb/download/ or any CPAN ftp server - and
proceed as follows:
-------------------- cut here -------------------- cut here --------------------
#!/sw/bin/perl -w
use strict;
no strict "vars";
use Date::DateCalc qw(:all);
use Date::DateCalcLib qw(:all);
@today = parse_date(`/bin/date`); # for UNIX only (see also below!)
$dayofweek = day_of_week(@today);
if ($dayofweek > 5)
{
@friday = calc_new_date(@today,5-$dayofweek);
}
else
{
@friday = calc_new_date(@today,-2-$dayofweek);
}
print "Today is ", date_to_string(@today), "\n";
print "Last friday was ", date_to_string(@friday), "\n";
-------------------- cut here -------------------- cut here --------------------
Instead of the two lines:
@today = parse_date(`/bin/date`);
$dayofweek = day_of_week(@today);
you can also use:
($day,$month,$year,$dayofweek) = (localtime(time))[3,4,5,6];
$dayofweek += 7 unless($dayofweek);
$year += 1900;
$month++;
@today = ($year,$month,$day); # just makes dates easier to handle...
to make it faster and more portable.
Hope this helps!
Yours,
--
Steffen Beyer <sb@sdm.de> http://www.engelschall.com/u/sb/
Feel free to visit my download area with free software at
http://www.engelschall.com/u/sb/download/
>> Unsolicited commercial email goes directly to /dev/null <<
------------------------------
Date: Sat, 13 Dec 1997 01:14:43 -0700
From: Kelly Horstmann <kelly_horst@hotmail.com>
Subject: delete file in perl
Message-Id: <349243F3.20BA20D9@hotmail.com>
I want to write a perl program to delete a specified kind of file, (for
example *.o file)in the current directory (say, /usr/bin/perl) and also
delete all the *.o files in all other subdirectories (eg.
/usr/bin/perl/dir1, /usr/bin/perl/dir2, /usr/perl/dir3 etc). I
have been working on that for couple hours, and I just don't know how to
call perl
to search all the *.o files in all the subdirectories. Just let me know,
if you can code
up this problem.
------------------------------
Date: Sat, 13 Dec 1997 02:16:52 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: eof and low level io
Message-Id: <34923664.ADCC773D@coos.dartmouth.edu>
Calle Dybedahl wrote:
>
> Michael Reed <mreed@cis.ohio-state.edu> writes:
>
> > Problem is... at the end of the file it keeps trying to read, and I'm
> > not sure how to get it to throw some sort of exception to let me handle
> > it.
>
> You seem to have missed this little bit when you read about sysread()
> in the perlfunc manpage (you *did* read the manpage, right?):
>
> "Returns the number of bytes actually read, or undef if there was an error."
>
> Reading at end of file counts as an error.
Then why doesn't it return undef for that situation? At least for me it doesn't:
% cat > temp
Hi!
% perl
open(IN, "temp") or die "$!";
$r = sysread(IN, $buf, 10);
print "\$r = $r ";
print +(defined($r) ? "(defined)\n" : "(not defined)\n");
print "\$buf = $buf\n";
$r = sysread(IN, $buf, 10);
print "\$r = $r ";
print +(defined($r) ? "(defined)\n" : "(not defined)\n");
print "\$buf = $buf\n";
outputs:
$r = 4 (defined)
$buf = Hi!
$r = 0 (defined)
$buf =
Note that $r is 0, not undef, when I try to read at end of file.
Tested it with perl 5.004 on BSD and perl 5.002 on Ultrix.
Chipmunk
------------------------------
Date: Fri, 12 Dec 1997 19:59:21 -0500
From: "Webmaster" <webmaster@fccj.cc.fl.us>
Subject: Re: eof and low level io
Message-Id: <3491de88.0@usenet.fccj.cc.fl.us>
At the sysread/io level EOF is practically meaningless.
I might suggest using the function to determine the size of your target
first, then only reading that many bytes.
Can't remeber the 'size of file' command off the top of my head, but I
believe it is the standard file test - stat - which returns an array
containing all file-related info.
This - stat - with tell, will make sysread/syswrite more usable :-)
HTH,
Bill
Michael Reed wrote in message <3491546A.6ADE@cis.ohio-state.edu>...
>Hi...
>when using sysread and sysopen... how can you detect the end of a file?
>The code goes something like this:
>
>sysopen SCHED_FILE, $SCHEDAT ,O_RDONLY , 0666;
> for(;;){
> sysread SCHED_FILE, $location, 80;
> print "- $trial -\n";
> sysread SCHED_FILE, $phone, 8;
> print "- $trial -\n";
> for ($week=0; $week<=6; $week++){
> for ($period=0; $period<=47; $period++){
> sysread SCHED_FILE, $first_slot, 4;
> $first_slot = unpack "i", $first_slot;
> print "- $first_slot ----";
> sysread SCHED_FILE, $second_slot, 4;
> $second_slot = unpack "i", $second_slot;
> print "- $second_slot -\n";
> }
> }
> print "\n";
> }
>
>Problem is... at the end of the file it keeps trying to read, and I'm
>not sure how to get it to throw some sort of exception to let me handle
>it.
>
>Thanks,
> Mike
>
>--
>Michael Reed
>CIS Web Manager 778 Dreese
>Computer and Information Science 2015 Neil Avenue Col, OH 43012
>The Ohio State University Office phone: (614) 292-1153
------------------------------
Date: Sat, 13 Dec 1997 00:52:47 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Help with a regex
Message-Id: <349222AF.41904800@coos.dartmouth.edu>
Martien Verbruggen wrote:
>
> In article <66im51$6qb$1@news.digifix.com>,
> sanguish@digifix.com (Scott Anguish) writes:
> >
> > I'm attempting to breakdown different file entries...
> >
> > Filename.1.0.PIs.tgz
> > Filename.1.3.W.tgz
> > Filename.PI.tgz
> > Flex.files.2.0.tgz
> >
Martien's two code suggestions:
> my ($filename, $version, $PIWMs) =
> m{
> ^(.*?) # file name (match non-greedy)
> \.? # 0 or 1 dot
> (\d+\.\d+)? # 0 or 1 version number
> \.? # 0 or 1 dot
> ([PIWMs]*) # PIWMs field (might be empty)
> \.tgz # extension
> $ # The end
> }x;
and:
> my @ff = split /\./;
>
> # get rid of extension
> pop(@ff);
>
> my $ff = pop(@ff);
>
> if ($ff =~ /^[PIWMs]+$/)
> {
> # Found a PIWMs field
> $PIWMs = $ff;
> $ff = pop(@ff);
> }
>
> if ($ff =~ /^\d+$/)
> {
> $version = pop(@ff) . '.' . $ff;
> $filename = join( '.', @ff);
> }
> else
> {
> $filename = join( '.', @ff, $ff);
> }
These should be suitable if all the filenames being processed are guaranteed
to fit the required syntax.
However, both of these incorrectly match filenames which don't, such as:
file1.2.tgz
$_ = 'file1.2.tgz';
The regexp solution:
$filename = 'file'
$version = '1.2'
The split solution:
$filename = ''
$version = 'file1.2'
The regexp will also match filenames such as 'file...tgz'
The split solution, of course, assigns to the variables no matter how far
the filename deviates from the specified syntax.
To fix the regexp solution, the "optional" dots should be matched only if
the corresponding version number or PIWMS field also matches:
my ($filename, $version, $PIWMs) =
m{
^(.*?) # file name (match non-greedy)
(?:
\.
(\d+\.\d+) # version number
)? # (optional)
(?:
\.
([PIWMs]+) # PIWMs field
)? # (optional)
\.tgz # extension
$ # The end
}x;
The split solution would take a bit more work. I prefer the regexp solution anyway.
Chipmunk
------------------------------
Date: Sat, 13 Dec 1997 03:20:22 -0700
From: NerveGas <NerveGas@nospam.com>
Subject: Re: newbie: compact an array
Message-Id: <34926166.14B9@nospam.com>
> : > Suppose @a is an array of integers. I want to compact @a, so
> : > that elements that are 0 get deleted. How can I do this without >
> : > declaring another array @b such as:
I couldn't tell you how to do it (I don't think it's possible), but
if you are looking to save memory, you may want to try creating the
second array, and simply undef() each element in the first as it is
checked. For example....
foreach $i (@a) {if ($i) {@b[$j] = $i;undef($a[$j];$j++;};};
Steve
------------------------------
Date: Sat, 13 Dec 1997 10:37:38 +0100
From: Per Kistler <kistler@inf.ethz.ch>
Subject: Only one execution in -ne
Message-Id: <34925761.E088C142@inf.ethz.ch>
Hi All
How can one make that a command like reading a file will be
executed only once within a perl -ne '....' statement?
While processing files I have to read another file, which
could stay in an array, instead of beeing read a new for
every line of the of the files to process.
Like in such a line:
perl -ne 'read one time "filename"; statements for each line; print;'
files
Thanks, Per.
--
Per Kistler, Unix Systems Administrator, kistler@inf.ethz.ch
http://www.vis.inf.ethz.ch/~kistler/
Swiss Federal Institute of Technology, Zuerich, Switzerland
---------------------------------------------------------------------
------------------------------
Date: 13 Dec 1997 05:39:29 GMT
From: lvirden@cas.org
Subject: Re: Perl Modules Info
Message-Id: <66t72h$29o$1@srv38s4u.cas.org>
In article <3490dc62.0@news5.kcdata.com>, "Nic" <nic@cyber-west.com> wrote:
>I am somewhat familiar with perl programming and have been tinkering with it
>for a while. I was just wondering if there is a book out there that covers
>many of the commonly used and/or advanced perl modules.
Anyone ever modify perl's roffitall script to generate printed pages based
on all installed pods rather than just the ones in the distribution?
--
Larry W. Virden INET: lvirden@cas.org
<URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
Unless explicitly stated to the contrary, nothing in this posting should
be construed as representing my employer's opinions.
------------------------------
Date: 13 Dec 97 03:59:53 GMT
From: "Matt W. Bowers" <mbowers@CimageD.com>
Subject: Perl on Netware?
Message-Id: <01bd077b$0feb69a0$351ad8cc@kermit.invsn.com>
Can anyone refer me to a good source of information for the current Perl
port to Netware? A client of mine picked that server (despite several
impassioned pleas to the contrary). Now I need to figure out how to install
& configure the Perl interpreter.
In advance, Thanks!
--
Matt W. Bowers
Chiseled Image Designer Services
PO Box 1692
Modesto, CA 95353-1692
(209)578-8142 webshop@CimageD.com
------------------------------
Date: 13 Dec 1997 05:25:07 GMT
From: lvirden@cas.org
Subject: Re: Perl Plug-In for Netscape?
Message-Id: <66t67j$1rg$1@srv38s4u.cas.org>
According to Alex Tang <altitude@ren.us.itd.umich.edu>:
:Peter Prymmer <pvhp@forte.com> wrote:
:: Eric Hilding wrote:
:
:
:: > Eric Hilding wrote:
:: > ***UPDATED***
:: > >
:: > > Tad McClellan (tadmc@metronet.com) wrote:
:: > > : Eric Hilding (eric@hilding.com) wrote:
:: > > : : I've looked around but just can't seem to find the
:: > > : : info on an alleged Perl 'Plug-In' for Netscape. Any
:: > > : : references would be appreciated. Tnx.
:: > >
:: > > : Where did you hear the allegations?
ftp://skyler.arc.ab.ca/pub/perl/ in the newest OpenGL tar file.
Now that I have found the source Eric was seeking, could someone update
the source for the latest Netscape plugin SDK, latest OpenGL libraries,
and latest perl?
--
Larry W. Virden INET: lvirden@cas.org
<URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
Unless explicitly stated to the contrary, nothing in this posting should
be construed as representing my employer's opinions.
------------------------------
Date: Sat, 13 Dec 1997 02:08:08 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: perl puzzler
Message-Id: <66tbrp$orl@bgtnsc02.worldnet.att.net>
In article <349193A5.58A26270@ti.com>, Max Luther Tuinstra
<tuinstra@ti.com> wrote:
> Why does $var have the value undef rather than "tarzan" in the print statement
> below?
it printed
$var = tarzan
for me. which perl are you using?
--
brian d foy <http://computerdog.com>
#!/usr/bin/perl
$_=q|osyrNewkecnaYhe.mlorsePptMskurj|;s;[NY.PM]; ;g;local$\=
qq$\n$;@pm=split//;while($NY=pop @pm){$pm.=$NY;$ny.=pop @pm}
$pm=join'',reverse($ny,$pm);open(NY,'>&STDOUT');print NY $pm
------------------------------
Date: Sat, 13 Dec 1997 06:12:22 GMT
From: John Nolan <nospam@domain.com>
Subject: Re: problem with chomp() - actually it's split
Message-Id: <3492288E.6474@domain.com>
John Cartwright wrote:
> I ran into a situation where chomp() and chop() seem to behave differently
> that I would expect. What seems to happen is that chomp() is lopping off
> all of the trailing whitespace characters even though it reports removing
> only one. The following code illustrates my problem.
No, I think the culprit here is split -- or rather, the order of your
chops and splits.
>
> #
> # this doesn't seem to work correctly
> #
> $a = "a\tb\t\t\t\t\n";
> chomp $a;
At this point, $a is "a\tb\t\t\t\t"
>
> @mylist = split(/\t/,$a);
> $i = 0;
You chomped first, then split.
Here the length of @mylist is 2.
> $a = "a\tb\t\t\t\t\n";
> @mylist = split(/\t/,$a);
> chomp $mylist[$#mylist];
This time, you split first, then chomped the last element,
so the newline was still at the end of the string
when you split. @mylist now contains 6 elements.
Try this out, see what happens:
$a = "a\tb\t\t\t\t\n";
@mylist = split(/\t/,$a);
$length = @mylist;
print "Length of array = $length \n";
chomp $a;
@mylist = split(/\t/,$a);
$length = @mylist;
print "Length of array = $length \n";
--John Nolan
------------------------------
Date: Fri, 12 Dec 1997 21:59:17 -0700
From: jcartwright@wans.net (John Cartwright)
Subject: problem with chomp()
Message-Id: <jcartwright-1212972159180001@usm-40-46.wans.net>
Hello All,
I ran into a situation where chomp() and chop() seem to behave differently
that I would expect. What seems to happen is that chomp() is lopping off
all of the trailing whitespace characters even though it reports removing
only one. The following code illustrates my problem.
#
# this doesn't seem to work correctly
#
$a = "a\tb\t\t\t\t\n";
chomp $a;
@mylist = split(/\t/,$a);
$i = 0;
foreach (@mylist) {
print ("$i: $_\n");
$i++;
}
#
# this does
#
$a = "a\tb\t\t\t\t\n";
@mylist = split(/\t/,$a);
chomp $mylist[$#mylist];
$i = 0;
foreach (@mylist) {
print ("$i: $_\n");
$i++;
}
Thanks for any suggestions!
--john
jcartwright@wans.net
------------------------------
Date: Fri, 12 Dec 1997 21:54:44 -0600
From: Ed Kubaitis <ejk@uiuc.edu>
Subject: Re: Restricting CGI Programs to Perl.
Message-Id: <34920704.5D139C7A@uiuc.edu>
djr@newcoast.com wrote:
> 1. Is their an easy way to have a web server restrict CGI programs to
> Perl in an UNIX environment (Solaris 2.6 running SWS 1.0)? 2. Is
> there a way to restrict Perl to what it can spawn, such as only
> sendmail, etc? Any information on how to accomplish this is
> greatly appreciated.
Check safecgiperl at ftp://ftp.ox.ac.uk/pub/perl/for-CPAN/
--------------------------
Ed Kubaitis - ejk@uiuc.edu
CCSO - University of Illinois at Urbana-Champaign
------------------------------
Date: Sat, 13 Dec 1997 04:37:21 -0600
From: "Don Badowski Jr." <ddbadowski@fedex.com>
Subject: Script calls embedded in web pages
Message-Id: <34926561.CB68CF41@fedex.com>
Can anyone tell what if any thing I may be doing wrong or assuming in
the following case?:
I created a simple perl script file named"test.cgi":
#!/usr/bin/perl/
print "Content-type: text/html\n\n";
print "hello";
Next I created a HTML file called testing.shtml:
<html>
<head><title>TITLE</title></head>
<body>
This is a test of CGI and PERL<br>
<!--#exec cgi="test.cgi"-->
</body>
</html>
I upload both files into a directory that is executable and make the
.cgi executable. When I point my browser to testing.shtml I receive
this:
[an error occurred while processing this directive]
so next I point my browser to the test.cgi file itself and I get the
desired response in the browser:
This is a test of CGI and PERL
hello
Why will it not execute the cgi script from within the html file?
Am I doing something wrong? Or is it something to do with the setup of
the server? If so is there any way to check it out?
Any help is greatly appreciated.
Thanks,
Don Badowski Jr.
------------------------------
Date: Sat, 13 Dec 1997 02:10:27 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: setting environment variable within perl script
Message-Id: <66tc04$orl@bgtnsc02.worldnet.att.net>
In article <Pine.GSO.3.96.971212184841.14102U-100000@user2.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:
> On Fri, 12 Dec 1997 rgay@palmetto.net wrote:
> > I have a script written that mails the contents of a form and
> > additionally utilizes pgp to encrypt a portion of the mail message.
>
> Why aren't you using a module? That's probably easier, more convenient,
> and already debugged. Hope this helps!
in all fairness, the PGP module on CPAN is an alpha module. it gave me
so many problems that i wrote my own :)
--
brian d foy <http://computerdog.com>
#!/usr/bin/perl
$_=q|osyrNewkecnaYhe.mlorsePptMskurj|;s;[NY.PM]; ;g;local$\=
qq$\n$;@pm=split//;while($NY=pop @pm){$pm.=$NY;$ny.=pop @pm}
$pm=join'',reverse($ny,$pm);open(NY,'>&STDOUT');print NY $pm
------------------------------
Date: Sat, 13 Dec 1997 05:34:07 GMT
From: John Nolan <nospam@domain.com>
Subject: Re: There's More Than One Way?
Message-Id: <34921F97.5C43@domain.com>
brian d foy wrote:
> In article <66o4o6$i6q@tekka.wwa.com>, scribble@tekka.wwa.com (Tushar Samant) wrote:
> >comdog@computerdog.com writes:
> >>so far it must either be proved by exhaustion (using Perl for every
> >>problem in the set), or disproved by a single counterexample (finding
> >>one problem Perl can't handle).
> >
> >I disagree, the statement can be proved very easily by benchmarking
> >5 examples. If someone wants really rigorous proofs you might have
> >to collect 5 expert opinions and get 5 articles written in computer
> >magazines with 5 pie charts and 5 screen shots apiece.
>
> how does benchmarking five examples prove anything about the problem
> space addressed by Perl? let's remember that opinions have no place
> in such proofs. if you want unjustified opinions, go to Internet World :)
Yes, but if you do find one opinion there, that itself would be
a counterexample. Remember, Perl addresses the problem space
using 32-bit addresses. There's room for a lot of experts,
certainly more than 5.
If you benchmark the pie chart, you'll find that you can generate
an exhaustive proof for every screen shot in the problem set.
Perl can defninitely handle it.
Hope this helps!!
--John Nolan
------------------------------
Date: Sat, 13 Dec 1997 02:21:07 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: what does qq() do?
Message-Id: <66tck4$orl@bgtnsc02.worldnet.att.net>
In article <eli$9712111416@qz.little-neck.ny.us>, Eli the Bearded
<usenet-tag@qz.little-neck.ny.us> wrote:
> Henry Hartley <henry@DotRose.com> wrote:
> > I've been using sprintf("select... Why should I use qq instead?
>
> Let's say you have the text:
>
> :r! perl -we'$c=1;for($i=32;$i<127;$i++){print chr($i);!($c++%70)&&print"\n"}'
> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcde
> fghijklmnopqrstuvwxyz{|}~
i would have thought that Eli would have shown some twisted code like
#!/usr/bin/perl
$string =~ s && qq qjust another new york perl hackerq&e &&
print $string, "\n"
__END__
do you know what all the q's do? (i know Eli does - let's see if Randal
remembers the closing moments of the spinning bar)
--
brian d foy <http://computerdog.com>
#!/usr/bin/perl
$_=q|osyrNewkecnaYhe.mlorsePptMskurj|;s;[NY.PM]; ;g;local$\=
qq$\n$;@pm=split//;while($NY=pop @pm){$pm.=$NY;$ny.=pop @pm}
$pm=join'',reverse($ny,$pm);open(NY,'>&STDOUT');print NY $pm
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 1466
**************************************