[6376] in Perl-Users-Digest
Perl-Users Digest, Issue: 1 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 24 00:07:51 1997
Date: Sun, 23 Feb 97 21:00:21 -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 Sun, 23 Feb 1997 Volume: 8 Number: 1
Today's topics:
Re: a2p awk-to-Perl question ... (Russell Schulz)
Append to 1st line only variable (Carl Payne)
Re: ARGV fails on Win32/NT <mchase@ix.netcom.com>
Re: Difference between use and require? <mgjv@comdyn.com.au>
downloading cgi script ? (Paul S. Cutt)
Re: for god sake <mchase@ix.netcom.com>
help. perl Q. (fwd) <daftary@ecn.purdue.edu>
Re: How to convert tab delimited file to space delimite (Russell Schulz)
How to delete a line? 8684tgree@umbsky.cc.umb.edu
Re: How to delete a line? (Nathan V. Patwardhan)
Re: Leading zero in print format <sadd@msc.cornell.edu>
Re: localtime() year value broken? <tchrist@mox.perl.com>
Re: Perl on Windows 95 (Christopher Russo)
Re: Random Temp File in Perl 5.002 (Tad McClellan)
Re: Random Temp File in Perl 5.002 <rootbeer@teleport.com>
Regular Expression question <riekhof@primenet.com>
Re: Regular Expression question (Tad McClellan)
Re: Regular Expression question <rootbeer@teleport.com>
Sending long file names to NT Perl (Mr Green)
Re: Sending long file names to NT Perl (Nathan V. Patwardhan)
Re: split() matches, but returns no values <tchrist@mox.perl.com>
syntax check when embedding perl code in a (large) here (Jim Fondren)
Re: Time-efficiency question (Tad McClellan)
Re: WEB DEVELOPER'S VIRTUAL LIBRARY is Top Dog's Site O (Tad McClellan)
Re: Win95 Build 110: `cd` fails in install (Nathan V. Patwardhan)
Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 23 Feb 1997 12:18:17 -0700
From: Russell_Schulz@locutus.ofB.ORG (Russell Schulz)
Subject: Re: a2p awk-to-Perl question ...
Message-Id: <19970223.121817.3W8.rnr.w164w@locutus.ofB.ORG>
"Troy A. Evans" <tevans@cas.org> writes:
> It's choking on line 8, the concatenation operation:
>
> isssn = a b c
>
> which is a trivial 'awk' construct appearing everywhere in my scripts.
> The debugging output of 'a2p' is not helpful. What gives?
this is the only a2p bug mentioned in the comp.lang.awk FAQ.
FAQ> doesn't handle multiple concatenations in a row: e.g., "x" "y" "z"
FAQ> -> must be in pairs: i.e., ( "x" "y" ) "z"
I haven't re-done the yacc for this, nor do I know anyone who has...
--
Russell_Schulz@locutus.ofB.ORG Shad 86c
------------------------------
Date: 23 Feb 1997 21:05:03 -0700
From: cpayne@xmission.xmission.com (Carl Payne)
Subject: Append to 1st line only variable
Message-Id: <5er41f$9h1$1@xmission.xmission.com>
Thanks a lot for the path help last week.
On a new front:
Trying to open a datafile, append the day to ONE LINE of the file and
read in the rest.
Background:
I have a file. Let's say it charts the snacks I sell each day, and it looks
like this:
17,18,19,20,21 #these are the days the file covers
5,2,1,383 #the # of apples, cakes, pies and Jolts sold on the 17th
13,0,1,426 #18th
8,2,2,0,360 #and so on
2,1,5,1,225
9,0,1,2,135
It's kind of archaic because the total of snacks is tabulated automatically
each day and appended to this file in this awkian format. Right now, that
first line in the file with the days it covers isn't edited automatically,
only the data lines below it.
What I want to do:
each day, append today's number to the end of the first line of the file.
As long as perl can handle it, this line can go on ad nauseum. While the
datA lines in my example will always be 5 fields long, the datE line can be
45, 60, however many fields.
The end result is that I will have a routine that can tell me how many of
what snack were sold on what day. I think I can handle that part. What has
me stuck is opening the file, appending the day (with a comma) to that one
line, adding that day's totals (the way it already does) to the end of the
file and closing the file without harming all that data.
Would something like this work:
{
open(SNACKFILE," >$snackdata");
$newdline=$firstline,$currdate(day)
print SNACKFILE <<EOF;
$newdline;
$the_rest_of_snackdata_without_the_first_line;
$todaysnacks;
EOF
}
What is that variable I don't yet know? If $1 is the first field, what is
the first line?
$^ ??
$seen{$^} ??
This seems like it could be simpler, and it also seems like pulling that
file in has to be done through a pipe. I think I've been at this too long
today
Thanks in advance.
Carl
------------------------------
Date: 24 Feb 1997 02:14:05 GMT
From: "Michael A. Chase" <mchase@ix.netcom.com>
Subject: Re: ARGV fails on Win32/NT
Message-Id: <01bc21d8$aa50b600$LocalHost@mchase.ix.netcom.com>
You need to have certain entries in the registry. This and much more is
discussed in the Perl for Win32 FAQ:
http://www.endcontsw.com/people/evangelo/Perl_for_Win32_FAQ.html
Mac :})
Trond Ruud <troruud@online.no> wrote in article
<01bc1e78$1932ce00$15e17a94@troruud.sol.no>...
> Hi,
> Does anyone know about this problem on NT installations:
> The script argument list ARGV is always empty!
> I.E:
> when issuing:
>
> $ test.pl arg1 arg2
>
> the error message below is always displayed and the script is killed
> but the script name, ($0), never appears in the message!
> So no ARGV values seem to be set at all !?
>
> die "$0 requires a command line argument$#argv \n\a" if $#argv <0;
------------------------------
Date: Mon, 24 Feb 1997 13:04:24 +1100
From: Martien Verbruggen <mgjv@comdyn.com.au>
To: "Thomas A. Bennedum" <tab@albany.net>
Subject: Re: Difference between use and require?
Message-Id: <3310F728.308F@comdyn.com.au>
Thomas A. Bennedum wrote:
>
> What is the difference?
This difference is described in the perlmod documentation (which you
should probably read), together with the global list @ISA, which you
would use to 'subclass' stuff.
Basically 'use' is equivalent to
BEGIN { require "Module.pm"; import Module; }
That means that a use also imports a Modules namespace into the current
namespace (depending on @EXPORT and @EXPORT_OK)
>
> I've begun writing a multi-module, object oriented API for something at
> work, I'm a little confused about how to use these two commands
Normally, you would just use 'use'...
> effectively. To be more specific, I have something like this:
Also have a look at the perl OO tutorial:
http://www.perl.com/perl/everything_to_know/perltoot.html
> What would be the use/require statements at the beginning of each file,
> as well as the 'client' app, so that I don't get compile errors/memory
> overuse (if this is even an issue)?
package a;
require Exporter;
@ISA = qw( Exporter );
@EXPORT_OK = qw( some functions and variables );
package c;
require Exporter;
use b;
use Msql;
@ISA = qw( Exporter b );
@EXPORT_OK = qw ( stuff );
I'm sure you will be able to work it out with the documentation I
mentioned before :)
Martien
--
Martien Verbruggen
Webmaster www.tradingpost.com.au
Commercial Dynamics Pty Ltd, N.S.W., Australia
------------------------------
Date: Mon, 24 Feb 1997 01:16:44 GMT
From: cutt@netcom.com (Paul S. Cutt)
Subject: downloading cgi script ?
Message-Id: <cuttE6327w.7Ep@netcom.com>
Tried a couple of perl scripts on windows NT to download. Has anyone got
a working download script I can use ?
Basically I tired the following script. It works for download BUT adds
control chars. So if xx.exe has
123456789 as a line the downloaded file has 123456789^M
WHERE is the ^M coming from ? This is on Windows NT with perl 5.003 from
activeware.
Thanks,
paul
#!/usr/bin/perl
$path = "h:/plugins/xx.exe";
open(File, $path) || die "$path: $!"; # $path is path/filename
binmode (File);
$size = -s File;
$size || die "$path: empty file";
print "Content-type: application/octet-stream\n";
print "Content-disposition: attachment; filename=\"$path\"\n";
print "Content-length: $size\n\n";
while ($len = sysread(File,$buf,16384)){
if (!defined $len){
next if $! =~ /~Interrupted/;
die "read error $!\n";
}
$offset = 0;
while ($len){
$written = syswrite(STDOUT,$buf,$len,$offset);
die "system write error $!\n" unless defined $written;
$len -= $written;
$offset += $written;
};
}
close (File);
------------------------------
Date: 24 Feb 1997 02:14:09 GMT
From: "Michael A. Chase" <mchase@ix.netcom.com>
Subject: Re: for god sake
Message-Id: <01bc21f0$1d14c7a0$LocalHost@mchase.ix.netcom.com>
Ever since MSDOS 1.0, certain file names (including AUX.*) are assumed to
be device names and will cause any extraction program to choke.
I've mentioned the problem to the WinZip folk and working around this
problem is on their todo list, but heaven knows when they'll get to it.
Under WinZip the workaround is to select all files in the archive and then
UNSELECT aux.sh and then extract only selected files. The problem isn't in
the archive, but in the Windows/MSDOS file system.
BTW, aux.sh was been renamed aux_3.sh in Perl 5.003_22, so instead of
latest.tar.gz, you might want to get the latest beta. I like to keep it on
hand so I can see any utilities and fixes that haven't been included in the
ActiveWare Perl 5.003_7.
For actual use, go to http://www.activeware.com/ and download Build 303.
It's a reasonable port to an unreasonable environment.
Mac :})
------------------------------
Date: Sun, 23 Feb 1997 22:56:07 -0500
From: "Kuntal M. Daftary" <daftary@ecn.purdue.edu>
Subject: help. perl Q. (fwd)
Message-Id: <Pine.SOL.3.91.970223225531.5629C-100000@purcell.ecn.purdue.edu>
i have a program around which i want to build a perl wrapper.
the wrapper is supposed to accept stuff from user via keyboard and pass
it on to the program, then accept whatever the program outputs and
display it on the screen for the user. thus it is a wrapper in true sense.
now i had two problems implementing the thing in perl:
1. i did the usual thing of opening a pipe and forking a child process
and exec-ing the program in the child. now, i dont know how to dup2 the
stdin of the child to a particular file handle in perl. any ideas?
2. the program itself is weird. it nornammly outputs like this
line 1 of output
<user presses 'b'>
line 2 of output (prolly after spawing some new process)
.
.
.
now whenever i start my wrapper, it does not display the line 1, but if i
press 'q', it does display line 2 and normal interaction starts...
now again when i close the wrapper, it displays line 1 at the end, which
it shud have in the first place. why is that? i know it is difficult to
say without looking ast the thing but any suggestions?
someone said it does console-io and asked me to use expect.
surely enuff it behaved well under expect.
what is console-io? is it different from stdio? if so, how? how can i
bring a program doing console-io to behave (like it is doing stdio and
hence dup2 stdout) ?
thnx
kuntal
------------------------------
Date: Sat, 22 Feb 1997 23:35:06 -0700
From: Russell_Schulz@locutus.ofB.ORG (Russell Schulz)
Subject: Re: How to convert tab delimited file to space delimited file
Message-Id: <19970222.233505.4i8.rnr.w164w@locutus.ofB.ORG>
"Jack L. Owens" <jlowens@ptconnect.infi.net> writes:
> I have several tab delimited ASCII files that I need to convert to fixed
> length space delimited fields.
what do you mean, `fixed length' `space delimited'? the program here will
do the first one. if you just want to add a space between the fixed-length
fields (to make it easier to read), this is easy to do.
> Some of the fields consist of multiple words.
it can't be space-delimeted if it's got spaces inside fields, so I'll
assume you mostly care about the fixed-length aspect.
> Is there an easy way to do this using Perl?
here's an awk solution I wrote not long ago. conversion to perl should
be trivial (even automatic, with a2p), but I've redirected to c.l.awk
just in case.
some bits could be done with sprintf(), and I could use NR's persistence
instead of my own numrecs, but... some things I don't bother remembering.
# tab2fix.awk -- change tab-delimited to fixed-width
BEGIN \
{
FS="\t";
exitcode=0;
STDERR="/dev/stderr";
numrecs=0;
}
function savedata()
{
for (j=1;j<=NF;j++)
data[numrecs,j]=$j
}
(NR==1) \
{
numrecs++;
numf=NF;
for (i=1;i<=NF;i++)
widths[i]=length($i);
savedata();
next;
}
{
numrecs++;
if (numf!=NF)
{
print("record " NR " has odd number of fields") > STDERR;
exitcode=1;
exit(exitcode);
}
for (i=1;i<=NF;i++)
if (length($i)>widths[i])
widths[i]=length($i);
savedata();
}
END \
{
if (exitcode)
exit(exitcode);
for (r=1;r<=numrecs;r++)
{
aline="";
for (i=1;i<=numf;i++)
{
afield=data[r,i];
while (length(afield)<widths[i])
afield=afield " ";
aline=aline afield;
}
print aline;
}
}
--
Russell_Schulz@locutus.ofB.ORG Shad 86c
------------------------------
Date: Sun, 23 Feb 97 21:37:32 +500
From: 8684tgree@umbsky.cc.umb.edu
Subject: How to delete a line?
Message-Id: <5equu2$t71@hydra.umb.edu>
Please bear with me, I'm new to programming.
I have a question of which I'm sure that a lot of you
will have the answer for you. I need to write subroutine
that reads the contents of an ascii file, and when it
finds, "\t\t\t\n" it deletes that line. Any ideas?
Thanks for the help.
------------------------------
Date: 24 Feb 1997 03:07:48 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: How to delete a line?
Message-Id: <5er0m4$rv9@fridge-nf0.shore.net>
8684tgree@umbsky.cc.umb.edu wrote:
: I have a question of which I'm sure that a lot of you
: will have the answer for you. I need to write subroutine
: that reads the contents of an ascii file, and when it
: finds, "\t\t\t\n" it deletes that line. Any ideas?
How 'bout this:
#!/usr/local/bin/perl -w
$file = 'testfile.test';
open(INFILE, "$file") || die("No: $!\n");
@lines = <INFILE>;
close(INFILE);
open(OUTFILE, ">$file.out") || die("No: $!\n");
foreach $line (@lines) {
next if $line =~ /\t\t\t\n/;
print OUTFILE $line;
}
close(OUTFILE);
OR you can do the substitution from the command-line, like:
perl -pi.bak -e 's/\t\t\t\n//g' filename
--
Nathan V. Patwardhan
nvp@shore.net
"A stitch in time saves nine."
------------------------------
Date: Sun, 23 Feb 1997 20:37:24 -0500
From: Michael Sadd <sadd@msc.cornell.edu>
To: Chris Plachta <stats9@mail.idt.net>
Subject: Re: Leading zero in print format
Message-Id: <3310F0D4.296E8F54@msc.cornell.edu>
Did you get any responses explaining how best to do this?
I suppose one could strip off the zero with s//, but one
would think there would be a format for what you want...
Mike
#perl
$temp=sprintf "%.3f\n",0.2345;
print $temp;
$temp =~ s/0(\.\d+)$/$1/;
print $temp;
__END__
0.234
.234
Chris Plachta wrote:
>
> Does anyone know how to get rid of the leading zero in a fixed
> precision numeric value in a print format? I wnat to print a
> value that looks like this:
>
> .323
>
> rather than this:
>
> 0.323
>
> When I use the notation:
>
> @.###
>
> in my print format it still gives me the leading zero. Any clever
> tricks or do I have to hack the field up before calling the write
> command?
>
> Thanks for you time.
------------------------------
Date: 24 Feb 1997 02:39:17 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: localtime() year value broken?
Message-Id: <5eqv0l$b3u$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, dribbs@netspace.org (Keith Dreibelbis) writes:
:$year += 1900 will give a proper 4 digit year, even past the year 2000.
:However, after 2037 it stops working. Here's some sample output:
Welcome to the world of 32-bit quantities.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
: 1. What is the possibility of this being added in the future?
In the near future, the probability is close to zero. In the distant
future, I'll be dead, and posterity can do whatever they like... :-) --lwall
------------------------------
Date: 24 Feb 1997 02:02:58 GMT
From: crusso@mit.edu (Christopher Russo)
Subject: Re: Perl on Windows 95
Message-Id: <5eqssi$be8@senator-bedfellow.MIT.EDU>
>>Mark Perry <mdperry@cougar.netutah.net> wrote:
>>
>>} I am setting up a website and I want to use some scripts. I want to
>>} test them to make sure they work befor sending them to the ISP. I
>>} downloaded Perl for Windows 95/NT. I can see if a script compiles and
>>} what its output is in a dos box by typing C:\>perl myscript.pl.
If you're using CGI.pm (and if you're not, you should be) you can 1) specify
the name/value pairs on th command line, or 2) read them in from a file. Then
just pipe the output of the script to foo.html. If you're lazy, use
open(STDOUT,"foo.html");
Chris Russo
crusso@mit.edu
------------------------------
Date: Sun, 23 Feb 1997 16:20:50 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Random Temp File in Perl 5.002
Message-Id: <2sfqe5.qv2.ln@localhost>
Mark Thompson (mwt@cyberg8t.com) wrote:
: I need to make a random temporary file, sortof like tmpnam() in C.
: Does Perl offer this functionality? If not, any suggestions on how to
: implement something like this?
This is not in the least bit "random", nor is it the least bit
sophisticated, but it's what I usually do (I'm a non-random,
unsophisticated type of guy ;-). I also don't want to spend more
than 20 seconds figuring out how to get the temp file name that
I want.
for ($num=0; -e "/tmp/file.$num"; $num++) {}
print "/tmp/file.$num is a unique filename\n";
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Sun, 23 Feb 1997 19:26:36 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Mark Thompson <mwt@cyberg8t.com>
Subject: Re: Random Temp File in Perl 5.002
Message-Id: <Pine.GSO.3.95q.970223192308.15989E-100000@kelly.teleport.com>
On Sun, 23 Feb 1997, Mark Thompson wrote:
> Subject: Random Temp File in Perl 5.002
Why 5.002? :-)
> I need to make a random temporary file, sortof like tmpnam() in C.
> Does Perl offer this functionality? If not, any suggestions on how to
> implement something like this?
Here's a method I use. Enjoy!
$temp_base = "/tmp/myprog.$$.$^T";
$first_temp_file = "$temp_base.A";
$second_temp_file = "$temp_base.B";
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 23 Feb 1997 16:59:08 -0700
From: Darrel Riekhof <riekhof@primenet.com>
Subject: Regular Expression question
Message-Id: <3310E61C.5591@primenet.com>
Hello.
What is the correct output for
((a*)(b*))* Input: abbbababb?
I recently installed the win32 perl5 package and am unsure if
it's giving me correct output. It matches the above, but says
$1, $2, and $3 are all empty. Here's the perl code I used to
test it (I'm a newbie Perl programmer, as you can tell from
this code):
$_=abbbababb;
if (/((a*)(b*))*/) {
print "Matched: ";
print "$_";
print "\n";
print "1=", $1;
print "\n";
print "2=", $2;
print "\n";
print "3=", $3;
}
Seems to me like $1 should have "abbbababb", $2 "a", and $3 "bb"
if it's doing a maximal match. Could someone explain what's
going on?
Thanks, Darrel
--
------------------------------
Date: Sun, 23 Feb 1997 18:56:32 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Regular Expression question
Message-Id: <00pqe5.cp3.ln@localhost>
Darrel Riekhof (riekhof@primenet.com) wrote:
: Hello.
: What is the correct output for
: ((a*)(b*))* Input: abbbababb?
: I recently installed the win32 perl5 package and am unsure if
: it's giving me correct output.
It gives me the same output with 5.003 on Linux...
: It matches the above, but says
: $1, $2, and $3 are all empty. Here's the perl code I used to
: test it (I'm a newbie Perl programmer, as you can tell from
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You should be using the -w switch to enable compiler warnings.
The code below generates two warnings...
: this code):
:
: $_=abbbababb;
^^^^^^^^^
"Unquoted string "abbbababb" may clash with future reserved word at..."
You should put quotes around your strings (though this has nothing to
do with your current problem).
: if (/((a*)(b*))*/) {
"((a*)(b*))* matches null string many times at ..."
^^^^^^^^^^^^^^^^^^^
There is your problem. If $_='';, then it would _still_ match.
You shouldn't allow zero length matches (*) unless, ...well, ...unless
you really want zero length matches ;-)
Perl doesn't really match the longest possible string (maybe Jeffrey
will jump in here?).
So it is matching null strings, and dutifully putting them into
the backreference variables...
: print "Matched: ";
: print "$_";
: print "\n";
: print "1=", $1;
: print "\n";
: print "2=", $2;
: print "\n";
: print "3=", $3;
: }
: Seems to me like $1 should have "abbbababb", $2 "a", and $3 "bb"
: if it's doing a maximal match. Could someone explain what's
: going on?
-----------
#! /usr/bin/perl -w
$_='abbbababb';
if (/((a+)(b+))*/) {
# ^ ^
print "Matched: $_\n";
print "1=$1\n";
print "2=$2\n";
print "3=$3\n";
}
-----------
Outputs:
Matched: abbbababb
1=abb
2=a
3=bb
You already understand the $2 and $3 values.
The value of $1 is because of the last *, it appears that the
backreference variable gets reset when reentered (I didn't
know that either, 'til now ;-).
Hope this helped!
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Sun, 23 Feb 1997 19:22:10 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Darrel Riekhof <riekhof@primenet.com>
Subject: Re: Regular Expression question
Message-Id: <Pine.GSO.3.95q.970223190531.15989D-100000@kelly.teleport.com>
On 23 Feb 1997, Darrel Riekhof wrote:
> $_=abbbababb;
That's a bareword. Try putting it in quotes.
> if (/((a*)(b*))*/) {
The problem here is that each * is trying to match zero or more times. So
let's imagine what happens when it is trying to match and it reaches the
end of the string: First, (a*) matches zero a's, then (b*) matches zero
b's. Now, since there's a star wrapped around those, it has to go back and
match zero a's again!
Fortunately, Perl is smart enough to catch this infinite loop, or your
script would still be running. And Perl will even warn you about it if you
use the -w flag (highly recommended).
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 23 Feb 1997 23:23:08 GMT
From: sspraggs@bridges.com (Mr Green)
Subject: Sending long file names to NT Perl
Message-Id: <5eqjgs$65j@fountain.mindlink.net>
I'm looking to send the full name of a file to a perl script using the "right
click" feature in Windows 95.
Background:
- The perl script is on a NT box.
- Win 95 users need to access the script
- Uses associations to make use of the Win 95 Right click
(ie:perl.exe script.pl "%1")
- Currently passes 8,3 file names and those STUPID ~1's
if it's any longer.
- Long filenames can be passed to it using the msdos prompt.
Any ideas?
--
When You're This green, They Call You Mister
------------------------------
Date: 23 Feb 1997 23:30:48 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Sending long file names to NT Perl
Message-Id: <5eqjv8$dgj@fridge-nf0.shore.net>
Mr Green (sspraggs@bridges.com) wrote:
: - The perl script is on a NT box.
: - Uses associations to make use of the Win 95 Right click
: (ie:perl.exe script.pl "%1")
: - Currently passes 8,3 file names and those STUPID ~1's
: if it's any longer.
I thought long filenames could be enclosed in quotes, like:
cd "Program Files" instead of cd program~1 ? Users could pass the
program long filenames if they put the name in quotes.
Example:
print("Enter a filename: ");
chop($filename = <STDIN>);
$filename =~ s/\"//g;
open(FILE, $filename);
etc etc etc
To do the button association, I hesitate to say that you should edit
the perl.exe entry in your Windows 95 registry. :-)
--
Nathan V. Patwardhan
nvp@shore.net
"A stitch in time saves nine."
------------------------------
Date: 24 Feb 1997 02:43:22 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: split() matches, but returns no values
Message-Id: <5eqv8a$b3u$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
dmacks@netspace.org (Daniel Macks) writes:
:Say I've got a string that is a colon-delimited set of fields in a
You mean colon-separated, don't you, not colon-delimited?
:database (relax...this is *not* a sort() question:) I want to split up a
:line into its component fields, so I figured I'd use split(), but the
:(external non-modifiable) program that generates the strings passes a set
:of all null fields, the result of split() is a 0-item list.
:
:Example (perl 5.002)
: @foo = split( ':', 'this:one:seems:normal' ));
: @bar = split( ':', ':::fine' ));
: @ack = split( ':', ':::' ));
:gives
: @foo = ( 'this', 'one', 'seems', 'normal' );
: @bar = ( undef, undef, undef, 'fine' );
: @ack = ();
:Why doesn't @ack=(undef,undef,undef,undef)?
Because leading null fields are by default preserved, but trailing
ones are deleted. It says this in the sort entry in the perlfunc
manpage.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"...we will have peace, when you and all your works have perished--and
the works of your dark master to whom you would deliver us. You are a
liar, Saruman, and a corrupter of men's hearts." --Larry Wall in perl/taint.c, citing Theoden from LOTR
------------------------------
Date: Sun, 23 Feb 1997 20:47:46 GMT
From: nomail@imaji.net (Jim Fondren)
Subject: syntax check when embedding perl code in a (large) here document
Message-Id: <3310acee.7060707@news.wisp.net>
Greetings,
I've learned to use the expression:
@{[$any_perl_expression_returning_a_scalar]}
inside of large here documents to avoid the clumsy necessity of
closing and re-opening the here document. (yes, for CGI, generally).
A problem I've noticed on those rare occasions when I maek a typo is
that the perl interpreter won't be able to call out the physical line
of a syntax error in the file if the error is embedded in the here
document. The line indicated is the line using the <<"FOO" syntax.
I'm just curious as to whether this is just the price I must pay or if
others have run across this problem and have discovered a mechanism
for spotting syntax errors faster than by eye.
Thanks for your time,
Jim F
IMAJI
Deliberately munged email: "jf" at "imaji.net"
------------------------------
Date: Sun, 23 Feb 1997 16:12:38 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Time-efficiency question
Message-Id: <mcfqe5.st2.ln@localhost>
Sara Young (syoung@actcom.co.il) wrote:
: I have a Perl CGI script that reads an HTML form, inserts data into it,
: and then prints it out to the browser.
: The form looks something like this:
: <HTML><BODY>
: some stuff
: <!-- data1 here -->
: some more stuff
: <!-- data2 here -->
: some more stuff
: </BODY></HTML>
: The question is this: what is the most time-efficient way to do this?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
use Benchmark, and find out for sure.
: 1. open(FILE, $file);
: while <FILE> {
^^^^^^
syntax error! But I get the idea ;-)
: if (/!-- data1 here -->/) {
: print something;
: } elsif (/!-- data2 here -->/) {
: print something_else;
: }
: print;
: }
: close(FILE);
: 2. open(FILE, $file);
: @fileLines = <FILE>;
: $fileString = join(" ",@fileLines);
You don't need that intermediate @fileLines array.
You are also changing the file in many places _besides_ where you
said you want to (you're adding a bunch of spaces)
$fileString = join '', <FILE>; # works just fine!
: $fileString =~ s/<!-- data1 here -->/something/;
: $fileString =~ s/<!-- data2 here -->/something else/;
: print "$fileString";
You don't need the double quotes either, they are not doing anything
other than slowing things down).
print $fileString; # this works fine too!
: I have a feeling that #2 is faster, but I don't know how costly the join
^^^^^^^^^^^^^^^^
Use Benchmark, and then you'll _know_ ...
: is, and how costly it is to do a substitution on a long string.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Sun, 23 Feb 1997 17:13:12 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: WEB DEVELOPER'S VIRTUAL LIBRARY is Top Dog's Site Of The Day @ http://www.statsplus.com/TopDog/
Message-Id: <8uiqe5.083.ln@localhost>
[ emailed (to original poster), posted]
Mike Heins (mheins@prairienet.org) wrote:
: Rich (rich@cris.com) wrote:
: : The Web Developer's Virtual Library is a great resource for
: : webmasters and Internet developers, with over 500 pages and thousands
: : of references.
: : http://www.statsplus.com/TopDog/
: How come I don't believe that? Does it have something to do with
: the promoters of it not knowing enough about the Internet to cross-post
: rather than post separately to different groups?
Hmmm. That would make them 'canned meaters'. Or something like that...
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 23 Feb 1997 23:23:48 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Win95 Build 110: `cd` fails in install
Message-Id: <5eqji4$dgj@fridge-nf0.shore.net>
Charles Henkel (csh@henktech.com) wrote:
: On some machines, the perl installation script "install.bat"
: fails to determine the current directory name. The script is doing
: something like "$curdir = `cd`", and it's the command substitution
: that fails.
You'd be much happier if you'd run perl5.003_07, available from
http://www.activeware.com. I noticed the same bug way back in the
001m NT Perl distribution(s), but hacked the install.bat file to do
what I wanted (I wish I remember what that was). :-)
--
Nathan V. Patwardhan
nvp@shore.net
"A stitch in time saves nine."
------------------------------
Date: 8 Jan 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Jan 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.
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 1
***********************************