[7849] in Perl-Users-Digest
Perl-Users Digest, Issue: 1474 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 15 06:17:18 1997
Date: Mon, 15 Dec 97 03:00:22 -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 Mon, 15 Dec 1997 Volume: 8 Number: 1474
Today's topics:
Re: @a = m// bug in 5.004_04? (David M. Jones)
Re: @a = m// bug in 5.004_04? (David M. Jones)
Check User ID <clanger@csd.sgi.com>
Re: Check User ID (Jeff Fisher)
Re: Check User ID (brian d foy)
Compiling PERL for win95 cdd2@gpu.srv.ualberta.ca
Re: Dynamically Sending an Adobe Acrobat PDF File to th (Martien Verbruggen)
Re: Improve my Perl Loop <lach@lach.net>
Newbie Help: Removing or ReDimensioning an Array (Howard Hull)
Re: Newbie question. Do you recommend moving from C? <opthalamion@pobox.com.unspam>
Re: perl puzzler (Kevin Buhr)
Perl script works when initiated from the unix shell, b <wcl@netrox.net>
Re: pgp encrypion via perl script (brian d foy)
Re: Please advise. Fastest way to line-count files (Michael Ward)
Re: prevent download of images (brian d foy)
Problem Compiling PERL cdd2@gpu.srv.ualberta.ca
Re: Problem with getc? <rjk@coos.dartmouth.edu>
Re: Solution: getting list of directories, returned as (Tushar Samant)
terminate input on CGI.pm in Win95 Gurusamy Sarathy por (Brian Lavender)
Re: text wrap (brian d foy)
Re: Which language pays most 17457 -- C++ vs. Java? <carla@ici.net>
Re: Workaround for FLOCK? (Nathan V. Patwardhan)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 14 Dec 1997 20:47:49 -0500
From: dmjones@theory.lcs.mit.edu (David M. Jones)
Subject: Re: @a = m// bug in 5.004_04?
Message-Id: <s3pbtyj8ji2.fsf@sandpiper.lcs.mit.edu>
dmjones@theory.lcs.mit.edu (David M. Jones) writes:
> And, sure enough, I just checked that after
>
> @a = "a" =~ /a/
>
> we have
>
> @a = (1)
...which proves absolutely nothing, since this is, of course, the
documented behaviour.
David (who's not going to post anything else until he's had a _lot_ of
sleep).
------------------------------
Date: 14 Dec 1997 20:08:56 -0500
From: dmjones@theory.lcs.mit.edu (David M. Jones)
Subject: Re: @a = m// bug in 5.004_04?
Message-Id: <s3pyb1n5s5z.fsf@sandpiper.lcs.mit.edu>
Before jumping into my response, I should apologize for the terseness
of my earlier message. I should have give a bit more of my analysis
of the problem, especially since one of the reasons for posting the
bug report to this group rather than just submitting it via perlbug
was to let other users know about the problem.
I also don't know why I left the "?" in the Subject line. My only
excuse is that it was late and I was tired.
mgjv@comdyn.com.au (Martien Verbruggen) writes:
> In article <s3p90toejof.fsf@sandpiper.lcs.mit.edu>,
> dmjones@theory.lcs.mit.edu (David M. Jones) writes:
> > According to Devel::Peek, @a is set to ("") rather than (),
> > as I would expect,
>
> Hmmm... The documentation clearly states that a failed match should
> return a null array.
Yes, that's why it's what I would expect. :-)
> It doesn't in this case. Now the question is if
> this is a bug in perl, or in the documenation?
I hope it's considered a bug in perl. Otherwise there's no way to
distinguish the following two cases.
@a = "a" =~ /b/
and
@a = "a" =~ /(.*)a/
Note that the match fails in the first case, but succeeds in the
second, and yet @a is set to ("") in both cases.
Incidentally, there's a connection between this and a recent thread
about why perl is considered to be weakly typed. My guess is that
when a pattern contains no backreferences, perl5 is doing the
equivalent of forgetting to check whether the match is being evaluated
in a scalar or list context, which means that if the match fails, we
get
@a = ""
And, since perl allows you to assign a scalar to an array, this is
equivalent to
@a = ("")
And, sure enough, I just checked that after
@a = "a" =~ /a/
we have
@a = (1)
> > and as an old version of perl4 does.
>
> I wouldn't rely on a test with perl4 to always give the same results
> as a test in perl5.
Quite so, but it's at least proof that this was the behaviour once
upon a time. For what it's worth, all the versions of perl 5 that I
have access to behave the same way as 5.004_04.
David M. Jones "Trifles! Trifles light as air!"
dmjones@theory.lcs.mit.edu -- the Hystricide
------------------------------
Date: Sun, 14 Dec 1997 17:47:10 -0800
From: Christina Langer <clanger@csd.sgi.com>
Subject: Check User ID
Message-Id: <34948C1E.794B@csd.sgi.com>
Hey guys !
Can somebody help me here with a small piece of code ?
That's the problem:
I have an access restricted survey, which submits data in a file called
survey.txt. The user name gets captured in this file when you hit submit
in the form:
UserID: xxx
Since every user should just be allowed to submit the survey once, I
want to check in my cgi script, if this UserID exists already.
Something like:
-------------------------------------
open file survey.txt
If you find pattern "userID: $ruser (thats the name of the cgi
variable)", send message "submitted already"
else: go ahead with the script.....
--------------------------------------
Thats the part I need in perl please :)
Anybody willing to translate ?
Thanks,
Christina
--
__________________________________________________________________
Christina Langer clanger@csd.sgi.com
Technical Support Engineer 1-800-800-4744
Silicon Graphics Inc.
__________________________________________________________________
------------------------------
Date: 15 Dec 1997 06:21:47 GMT
From: rzxtlg@dogbert.ies-energy.com (Jeff Fisher)
Subject: Re: Check User ID
Message-Id: <slrn699j3r.h45.rzxtlg@dogbert.ies-energy.com>
[posted and mailed]
On Sun, 14 Dec 1997 17:47:10 -0800, Christina Langer
<clanger@csd.sgi.com> said:
> Hey guys !
>
> Can somebody help me here with a small piece of code ?
>
> That's the problem:
>
> I have an access restricted survey, which submits data in a file called
> survey.txt. The user name gets captured in this file when you hit submit
> in the form:
>
> UserID: xxx
>
> Since every user should just be allowed to submit the survey once, I
> want to check in my cgi script, if this UserID exists already.
>
> Something like:
> -------------------------------------
> open file survey.txt
>
> If you find pattern "userID: $ruser (thats the name of the cgi
> variable)", send message "submitted already"
>
> else: go ahead with the script.....
> --------------------------------------
>
> Thats the part I need in perl please :)
This is assuming the user id is one word.
# get list of users in file
open( IN, "<survey.txt");
while (<IN>){
next if ( ! /^userID:\s*(\w*)/ );
$used{$1} = 1;
}
close IN;
# check current user agianst list
if( $used{$ruser}){
print "submitted already\n";
exit 0;
}
# rest of script
Of course, everybody can feel free to critique my code.
But then, I don't think you need the invitation....
--
Jeff Fisher | ...I want to be on the side of the many.
UNIX Sys Admin - IES Industries | Therefore, I take great pains to explain
http://opus.ies-energy.com/jeff/ | to as many people as possible.
| - Johannes Kepler
------------------------------
Date: Mon, 15 Dec 1997 01:55:48 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Check User ID
Message-Id: <672jsn$of9@bgtnsc01.worldnet.att.net>
In article <slrn699j3r.h45.rzxtlg@dogbert.ies-energy.com>,
jeff@dogbert.ies-energy.com wrote:
> On Sun, 14 Dec 1997 17:47:10 -0800, Christina Langer
> <clanger@csd.sgi.com> said:
> > UserID: xxx
> >
> > Since every user should just be allowed to submit the survey once, I
> > want to check in my cgi script, if this UserID exists already.
> open( IN, "<survey.txt");
> while (<IN>){
> next if ( ! /^userID:\s*(\w*)/ );
> $used{$1} = 1;
> }
since you are only looking for one UserID, you can stop after you
find it. let's say that we are looking for $user:
my $found = 0;
while( $_ = <INPUT> )
{
next unless m/^UserID: \Q$user\E$/oi;
$found = 1;
last;
}
--
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: Mon, 15 Dec 1997 03:20:21 GMT
From: cdd2@gpu.srv.ualberta.ca
Subject: Compiling PERL for win95
Message-Id: <67242m$u0k$1@pulp.ucs.ualberta.ca>
I am in the process of trying to compile a large script of mine into C
source using M. Beattie's perl compiler. My goal is to make a fully
functional Win95 executable out of this script.
My question is this... When I do convert my PERL source into C
source, will I be able to simply compile it using something like
Microsoft Visual C++ or another Windows product? My script only uses
one module (Sockets).
Please respond to: cdd2@gpu.srv.ualberta.ca
Thanks in advance,
Colin
------------------------------
Date: 15 Dec 1997 01:58:47 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Dynamically Sending an Adobe Acrobat PDF File to the Browser using PERL in a CGI Script
Message-Id: <6722sn$hav$1@comdyn.comdyn.com.au>
In article <671ggc$l71@news.microsoft.com>,
"Daniel F. Van Der Werken, Jr." <danvdw@microsoft.com> writes:
> print "Content-type: application/pdf\n\n";
>
> open(PDFFILE, "c:\\ntreskit\\perl\\samples.pdf");
> binmode PDFFILE;
> while(<PDFFILE>)
> print $_;
> }
> close (PDFFILE);
Since pdf files are binary, and <PDFFILE> reads the next 'line', this
could cause some pain with buffers overflowing and such. When using
big binary files, don't do it this way. Use read() or sysread();
> What someone who's smarter than I am has done:
>
> $filename="d:\MyFile.PDF";
>
> print <<END_OF_HEADER
> Content-Type: application/pdf
> Content-Length: 50
Content-Length really should reflect the REAL length of the content,
not some imaginary random number.
>
> END_OF_HEADER
> ;
>
> # $buffer = "";
>
> $fhandle = "\:\:$filename";
> open($fhandle,$filename) || die "Couldn't open file";
> binmode($fhandle);
> chmod 0666,$filename;
Huh? Why the chmod?
> while ($bytesread = sysread($filename,$buffer,1)) {
> $totalbytes += $bytesread;
> print $buffer;
> }
> close(INFILE);
ok, what about something like the following?
This gets called as
http://www.someserver/cgi-bin/getpdf.pl/filename.pdf
----SNIP----
#!/usr/local/bin/perl5 -w
# script: getpdf.pl
use strict;
my $buffer = "";
my $PDF_DIR = "/path/to/pdf/files";
my $filename = $ENV{PATH_INFO} or cgi_error("No file name supplied");
$filename = $PDF_DIR . $filename;
open(PDF, $filename) or cgi_error("Error opening $filename: $!");
binmode(PDF);
my $filesize = (stat(PDF))[7] or cgi_error("Cannot stat $filename: $!");
print "Content-Type: application/pdf\n";
print "Content-Length: $filesize\n\n";
while(read(PDF,$buffer,4096))
{
print $buffer;
}
close(PDF);
sub cgi_error
{
my $error = shift;
print "Content-type: text/plain\n\n";
print "Some error occurred:\n\n";
print $error . "\n" if (defined($error));
exit;
}
----SNIP----
Of course, using CGI, you can make this behave a bit nicer (instead of
using cgi_error), but the general idea, complete with error checking
is here. Also, you'll only need one cgi script for all your pdf files.
You could think of adding a bit more flexibility using a query string,
or instead of assuming a fixed path for pdf files, you could make that
a bit more flexible, but I would have to start charging you money if
you want me to do that :)
An added advantage of using the script this way, is that when people
use the 'Save As...' feature on their browsers, that the browsers will
actually suggest the real file name, instead of the script's file
name.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | The gene pool could use a little
Commercial Dynamics Pty. Ltd. | chlorine.
NSW, Australia |
------------------------------
Date: Sun, 14 Dec 1997 20:52:26 -0600
From: Lachlan Dunlop <lach@lach.net>
To: Martien Verbruggen <mgjv@comdyn.com.au>
Subject: Re: Improve my Perl Loop
Message-Id: <34949B6A.942AFDB4@lach.net>
Martien Verbruggen wrote:
> In article <3491BE27.635DDC94@lach.net>,
> Lachlan Dunlop <lach@lach.net> writes:
>
> > @ln =
> > (aa,9,ab,6,ac,10,ad,16,ae,22, [snip ...] );
>
> You didn't use perl -w, did you? It should have warned you not to use
> unquoted strings...
>
> You could use a hash table for this array. That will make it at least
> more readable.
>
> %ln = ( 'aa' => 9, 'ab' => 6 .....);
>
> or even, with minimal reformatting:
>
> %ln = ('aa', 9, 'ab', 6, 'ac', 10, 'ad' ... );
>
> Since they are in sorted order, you could use a foreach loop with a
> sort on the keys further down.
>
> [SNIP]
>
> > while (($name=shift(@e)) ne "") {
> > $len = shift(@e);
> > $result{$name} = substr($value, $startpos, $len);
> > $startpos += $len;
> > }
>
> If you have a hash here:
>
> foreach $name (sort keys %ln)
> {
> $len = $ln{$name};
> $result{$name} = substr($value, $startpos, $len);
> $startpos += $len;
> }
>
> Wether this is actually faster, you'd need to find out with the
> Benchmarking stuff. It is, IMO, a lot more readable though :)
>
> But.. the question is, why do you use those names at all? If I
> understand correctly, all you use the names for is to store part of
> the string in a hash. Unless those names (aa, ab, etc) actually mean
> anything, I would probably just store the result in an array.
>
> define an array with lengths
>
> @ln = (9, 6, 10, 16, ...);
>
> [other code]
>
> foreach $len (@ln)
> {
> push(@results, substr($value, $startpos, $len));
> $startpos += $len;
> }
>
> @results will now contain the substrings in the order they appeared in
> the line.
>
> I think this last one is probably most efficient, but again, it needs
> a bit of benchmarking to be sure.
>
> If you really need those names aa .. bv, I think that you will find
> that the array
>
> ( 'aa' .. 'bv' )
>
> will give them to you at any time you need them :)
>
> Martien
> --
> Martien Verbruggen |
> Webmaster www.tradingpost.com.au | Little girls, like butterflies, need no
> Commercial Dynamics Pty. Ltd. | excuse - Lazarus Long
> NSW, Australia |
Hi Martien,
Thanks for the feedback! The names I used where just test names to see if my
ideas where going to work (as it turns out they where a bad choice). This code
is being used to parse sequential data records. The variable names are like
'dhs_customer_profit' and 'dhs_customer_insurance'. I have like 200 different
record types that I will be parsing (The format of the records could change).
So as you can see the sorted order idea is out. I want to put all these
definitions in an include file or a module so they will be consistent across the
system.
My thoughts where that after the record is parsed I could access the data
conveniently and in a self documenting way with the associative array.
Again thanks!
Lach
------------------------------
Date: Sun, 14 Dec 1997 23:17:12 -0500
From: phantom@tp.net (Howard Hull)
Subject: Newbie Help: Removing or ReDimensioning an Array
Message-Id: <MPG.efe795895e195f0989680@news.tp.net>
Is there an easy way to completely destroy or at least remove all
elements of an array. I've tried a couple of things but haven't gotten
anything to work correctly.
Any help would be great.
Thanks.
------------------------------
Date: Thu, 11 Dec 1997 16:10:54 -0600
From: opthalamion <opthalamion@pobox.com.unspam>
Subject: Re: Newbie question. Do you recommend moving from C?
Message-Id: <349064EE.167EB0E7@pobox.com.unspam>
Jason Smith wrote:
>
> The transition to
> Java 1.1 is under way, 1.2 is just around the corner, and 2.0 is slated for
> sometime next year. During this time, it will be difficult to write once
> and run anywhere at all
As mentioned elsewhere, Sun now provides a plug-in for Netscape and
Explorer which allow those browsers to run Java code correctly:
http://java.sun.com/products/activator
Anyone using java on a webpage should provide an "install Java"
link, IMHO, and every managed network should be upgraded ASAP.
Here are the major points, quoting Sun PR:
1) Java Activator delivers full JDK 1.1 support and JCK compliance to
Internet Explorer 3.02 or later and Netwcape Navigator 3.0 or later on
Microsoft's desktop operationg systems.
2) Java Activator ensures that enterprises that desire the "write once,
run anywhere" benefits of teh Java platform are realized on Win32
systems
on the most widely used Web browsers.
3) Java Activator is ready for JFC, the next JDK and HotSpot with a
future-ready architecture that allows Sun to bring new features and
functionality to IE and Navigator on Win32 as soon as they become
availalbe from Sun.
4) Java Activator offers easy, low cost Web-based distribution of
the latest Java Platform release direct to Windows users' desktops.
------------------------------
Date: 14 Dec 1997 21:28:08 -0600
From: buhr@stat.wisc.edu (Kevin Buhr)
To: Max Luther Tuinstra <tuinstra@ti.com>
Subject: Re: perl puzzler
Message-Id: <vba4t4bmgjb.fsf@mozart.stat.wisc.edu>
Max Luther Tuinstra <tuinstra@ti.com> writes:
>
> Why does $var have the value undef rather than "tarzan" in the print statement
> below?
This is a "perl" bug, fixed in version 5.004. In multiple-block
constructs (like "if/elsif/else" and "while/continue"), the first
simple statement of second or later blocks was interpreted lexically
as if it belonged to the previous block.
For example, in your program, the variable "$var" in the print
statement is interpreted as if it appeared at the end of the previous
block. In the previous block, it was a "my" variable, but that block
was never executed, so now it's undefined. For a real laugh, try the
following modification:
> #!/usr/local/bin/perl -w
>
> $var = 'tarzan';
>
> if (0)
> {
> my $var = 'jane'; # if my is used here, $var is undefed
> }
> elsif (1)
> {
> print "\$var = $var\n";
print "but now, \$var = $var\n"; ##### ADD THIS LINE
> }
In the first "print" statement, "$var" is an undefined "my" variable,
but in the second "print" statement, "$var" is a global variable
which, of course, has value "tarzan".
Enough of this history lesson. Upgrade your "perl"!
Kevin <buhr@stat.wisc.edu>
------------------------------
Date: Sun, 14 Dec 1997 23:04:46 -0500
From: "Wayne" <wcl@netrox.net>
Subject: Perl script works when initiated from the unix shell, but not from web server.
Message-Id: <672aeu$kdm$1@usenet88.supernews.com>
Consider the following perl script used in a cgi setting.
#!/usr/bin/perl
open (USER_INFO, ">" . "/home/pico/john/DATA/data.txt");
print USER_INFO "Have a nice day\n";
print "Content-type: text/plain\n\n";
print "Done\n";
When I run this script from my Unix account, which is where my perl script
and the data.txt file reside, the script works fine, and the data.txt file
ends up with the string "Have a nice day". But when I run the script from a
web browser, i.e., the web server is involved, this same script writes the
empty string to data.txt thus leaving it empty. Now I know that it is
writing to it because what I did was have data.txt initialized to have some
data in it. Then after running the script via a web browser, data.txt was
left empty. Any ideas as to what is going on?? Thanks. If you could
e-mail your responses to me that would be great. Wayne.
------------------------------
Date: Mon, 15 Dec 1997 01:23:44 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: pgp encrypion via perl script
Message-Id: <672i0j$gu2@bgtnsc01.worldnet.att.net>
In article <mbudash-1412971654550001@d108.pm3.sonic.net>,
mbudash@sonic.net (Michael Budash) wrote:
> In article <671d0v$35p@bgtnsc02.worldnet.att.net>, comdog@computerdog.com
> (brian d foy) wrote:
>
> >> i'm sory, i thought you were trying to get the data off disk and had
> >> used echo by mistake.
>
> nope. said echo and meant echo.
>
> >> you didn't show anything that prepared the data
> >> to be echo-ed (there are embedded characters that will give you
> >> trouble), or any sanitizing of data being sent to the shell.
>
> what chars are those (that would give my statement trouble if they were in
> $unencrypted_data?
i tried your code, passing data with an embedded ", which ended the echo
command. after that, i could pass commands directly to the shell, including
mailing a copy of the private key.
to succesfully use the echo method you gave is a lot more work than
IPC::Open3. there are many more issues involved. the perlipc and perlsec
man pages would be a good place to start reading about these issues.
you can avoid the backticks in this case.
--
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: Sun, 14 Dec 1997 18:24:20 -0800
From: mward@veelos.com (Michael Ward)
Subject: Re: Please advise. Fastest way to line-count files
Message-Id: <mward-ya023580001412971824200001@news.slip.net>
>You realize, I hope, that that's not a proper text file! Text files
>contain 0 or more newline-terminated records.
Good Lord, now we have proper and improper text files? And when our
wonderful users use vi to create files full of text and no final
termination, we should tell them that it's not our fault, they should make
proper text files?
It's nowhere near April, but please tell me you're joking.
--
Michael Ward
mward@veelos.com
------------------------------
Date: Mon, 15 Dec 1997 01:36:06 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: prevent download of images
Message-Id: <672inn$gu2@bgtnsc01.worldnet.att.net>
In article <Pine.GSO.3.96.971214123446.29505F-100000@user2.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:
> On Sat, 13 Dec 1997 psyclone@twd.net wrote:
>
> > Is it possible to check the HTTP_REFERER variable and use 'expires' and
> > 'pragma: no-cache' headers in a script to block browsers from saving and
> > image on a web site (either in cache or storing to disk)?
>
> If it's possible at all, there's nothing Perl-specific about it. You could
> try looking in the CGI docs and FAQs, and the ones about servers and
> browsers. If you don't find your answer there, you could ask in a
> newsgroup about CGI, browsers, or servers. Thanks!
it's no use. invent a scheme and i'll subvert it. i'm not a browser, but
i play one in telnet. :)
--
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: Mon, 15 Dec 1997 03:11:56 GMT
From: cdd2@gpu.srv.ualberta.ca
Subject: Problem Compiling PERL
Message-Id: <6723iu$i16$1@pulp.ucs.ualberta.ca>
Hello. I'm trying to use Malcolm Beattie's PERL compiler (alpha 3) on
my slackware linux system. When I try to compile phone.pl into
phone.c, I get the following error message:
Yogibear:~# perl -MO=C,-ophone.c phone.pl
Can't find loadable object for module B in @INC
(/usr/lib/perl5/i586-linux/5.003 /usr/lib/perl5
/usr/lib/perl5/site_perl/i586-linux /usr/lib/perl5/site_perl .)
at /usr/lib/perl5/B.pm line 201
BEGIN failed--compilation aborted at /usr/lib/perl5/O.pm line 2.
BEGIN failed--compilation aborted.
Yogibear:~#
To me this looks like a pretty simple problem but I lack the skills to
figure out what is going wrong. Does anybody know?
Please respond to : cdd2@gpu.srv.ualberta.ca
Thanks in advance,
Colin
------------------------------
Date: Sun, 14 Dec 1997 22:15:19 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: Ivan Kourtev <ivan@ultimatech.com>
Subject: Re: Problem with getc?
Message-Id: <3494A0C6.E5026DBD@coos.dartmouth.edu>
Ivan Kourtev wrote:
>
> *********** Script text ****************
> #!/usr/local/bin/perl -w
>
> print "Name of file to read from > "; # prompt user
> $InFile = <STDIN>; # get a filename
> print "Name of file to write to > "; # prompt user
> $OutFile = <STDIN>; # get a filename
>
> open (INFILE, $InFile) or die "Can't read $InFile\n";
> open (OUTFILE, ">$OutFile") or die "Can't write $OutFile\n";
>
> $line_no = 0; # initialize line counter
> $char_no = 0; # initialize character counter
>
> printf(OUTFILE "%5d: ", ++$line_no); # print $line_no
> while ($Char = getc INFILE) {
> ++$char_no;
> if ($Char eq "\n") {
> printf(OUTFILE "\n%5d: %s", ++$line_no, $Line);
> }
> else {
> printf(OUTFILE $Char);
> }
> }
> printf("Read %d lines and %d characters\n", $line_no, $char_no);
>
> *********** Output file when script above is run on itself ***********
[output as expected until...]
> 11: $line_no =
^^^^^^^^^^^
Did you ever consider just what character your program is ending on?
Let's look at line 11.
$line_no = 0; # initialize line counter
^^^^^^^^^^^
It looks like your program may be ending prematurely when it reads the
character 0.
Why would that be?
while ($Char = getc INFILE) {
Because the expression '$Char = getc INFILE' evauluates to '0' at this point in
the input file. And '0' is FALSE.
So you need an expression which returns TRUE if the getc is successful, even
if the
character read is '0'.
Looking at the description for getc in man perlfunc, I find:
getc Returns the next character from the input file attached to
FILEHANDLE, or a null string at end of file.
So getc returns the character, or ''. Not undef, so defined() won't work.
But the length of '' is 0, while the length of a one-character string is 1,
so this will work:
while (length ($Char = getc INFILE)) {
That should fix the problem you are having.
Chipmunk
------------------------------
Date: 14 Dec 1997 22:00:07 -0600
From: scribble@tekka.wwa.com (Tushar Samant)
Subject: Re: Solution: getting list of directories, returned as an array
Message-Id: <672a07$qdg@tekka.wwa.com>
jkugler@inreach.com writes:
>use File::Find;
>my @dirlist
>
>find(sub {push(@dirlist, $File::Find::name) if -d;}, '.');
>-----
>
>Now, wasn't that easy? :) On large trees, this may be slow as it
>cycles through EVERY file, directory or not.
I guess I still don't understand the problem. If you already knew
which entries were directories, why would you be writing a program?
------------------------------
Date: Mon, 15 Dec 1997 04:46:33 GMT
From: brian@brie.com (Brian Lavender)
Subject: terminate input on CGI.pm in Win95 Gurusamy Sarathy port
Message-Id: <3494b4cd.31726973@news.jps.net>
When testing the cgi module on win 95 using the Gurusamy Sarathy port
how do you terminate data input in offline mode. In UNIX I use Ctrl-D
and enter on a single line. It does not work on win95. The mode I am
talking about is:
(offline mode: enter name=value pairs on standard input)
How do I indicate end of input?
Brian
----------------
Brian Lavender
Sacramento,CA
Brie Business Directory - Napa Valley http://www.brie.com/bbd/
(916) 443-6195
"I hate to advocate drugs, alcohol, violence, or insanity to
anyone, but they've always worked for me."
-- Hunter S. Thompson
------------------------------
Date: Mon, 15 Dec 1997 01:41:42 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: text wrap
Message-Id: <672j27$gu2@bgtnsc01.worldnet.att.net>
In article <mbudash-1412971602190001@d108.pm3.sonic.net>,
mbudash@sonic.net (Michael Budash) wrote:
> In article <344ae17f.262941158@news.west.net>, name@server.com (Mike
> Rambour) wrote:
> >> p.s. What I am trying to do is take text from a textarea and save it
> >> to a file but I need the output in 70 chars and it comes out as one
> >> big line. From my searching of the web, what I think I need is
> >> text:::wrap.
Text::Wrap could do what you want. you can get it at CPAN. [1]
> I've had good luck with this in the html, not some perl trick:
>
> <textarea name="body" rows=10 cols=70 wrap="hard">
it only takes one client to mess up your data file. never rely on the
client to do anything. :)
[1]
Comprehensive Perl Archive Network
find one near you at
<URL:http://www.perl.com>
--
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: Sun, 14 Dec 1997 23:53:46 -0500
From: Alicia Carla Longstreet <carla@ici.net>
Subject: Re: Which language pays most 17457 -- C++ vs. Java?
Message-Id: <3494B7DA.5463@ici.net>
Kurt Watzka wrote:
> Guillermo Schwarz <gschwarz@netup.cl> writes:
> >For a language to be succesful, 6 things must happen:
> >1. Actual programs must be written in it.
> >2. Lots of libraries must be written for it.
> >3. Most computer architectures must have a compatible version of it.
> >4. Source code must be easily understable (by good coders).
> >5. Lots of programmers must know the language in deep.
> >6. The syntax must be simple. The semantics must be well defined.
> > C is ok with 1, 2 and 3, but not with 4, 5 and 6.
You got this wrong:
As for number 6, C has one of the smallest sets of keywords (excluding
the library) of any language available. C provides the needed
primitives to do anything you need. Like chess, C is simple to learn
but difficult to master. Only because no matter how good you ever get
there is still more to learn.
Number 5, there are a lot of programmers who know C inside and out,
probabaly more than any other language (possibly excepting COBOL and
FORTRAN). I can name a dozen or more on this forum alone.
C is quite understandable to anyone who knows it.
In my opinion C easily meets all six of your criteria.
> >Smalltalk is ok with 1, 2, 3, 4, 5 and 6.
I suppose that there are some programs written in Smalltalk. I just
don't have any on my system. I don't believe that there are many for
the Intel platform.
As for number 2, I have never seen a library written in Smalltalk
available for purchase. I have numerous sources. As far as I can tell
there are very few libs written in Smalltalk.
Does Smalltalk have a standard? If not then 3 doesn't apply.
> >Take a look at Squeak.
> You forgot to mention that this is your opinion, and nothing but
> your opinion. C is a relatively simple language, and I doubt that
> there are too many people around who both qualify as good coders
> and do not understand C after learning it.
> Can you come up with any substantial facts that support the claim
> that more programmers know Smalltalk "in deep" than C? The syntax
> of C is well defined. As long as you write code with well defined
> semantics, well, the semantics are well defined in C. Whether
> the liberty to write code with undefined or implementation defined
> semantics is a weak or a strong point for C, even I do not care to
> argue about.
He probably can't.
--
****************************************************************
What is the speed of dark?
When you're sending someone Styrofoam, what do you pack it in?
Why are there Braille signs on drive-up ATM's?
How come you never hear about gruntled employees?
I have an answering machine in my car.
It says "I'm home now.
But leave a message and I'll call when I'm out."
=========================================
Alicia Carla Longstreet carla@ici.net
=========================================
READ THE FAQ for more information:
C-FAQ ftp sites: ftp://ftp.eskimo.com or ftp://rtfm.mit.edu
Hypertext C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
------------------------------
Date: 15 Dec 1997 05:48:11 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Workaround for FLOCK?
Message-Id: <672gar$no2@fridge.shore.net>
Vik Rubenfeld (VikR@aol.com) wrote:
: I've got a machine that doesn't support FLOCK. (Error message "# The flock()
: function is unimplemented.") I'd rather not tell my client to update his PERL
: installation. Is there a workaround I can use instead of FLOCK? Also, is there
Which OS (and version) are they running?
--
Nathan V. Patwardhan
please don't send spam to pres@whitehouse.gov
------------------------------
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 1474
**************************************