[7014] in Perl-Users-Digest
Perl-Users Digest, Issue: 639 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 20 10:07:25 1997
Date: Fri, 20 Jun 97 07:00:29 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 20 Jun 1997 Volume: 8 Number: 639
Today's topics:
Re: Case-matching substitution? (Tad McClellan)
CGI_Lite <papadopo@shfj.cea.fr>
code/module for Fisher Exact Test <marc@farm.rug.nl>
Re: Delete specific element from list <sfairey@metrica.co.uk>
Re: Delete specific element from list (M.J.T. Guy)
Re: Delete specific element from list (Brian Jepson)
Errornous read/sysread for PC-Perl? <hartje@etech.hs-bremen.de>
Example in PF doesn't work <eric@hilding.com>
Re: HELP: How to limit the length of contents in guestb (Chris Nandor)
Re: Install PERL5 (Clay Irving)
Japanese (or Unicode) support in PERL For Win32 <ingram@shljapan.co.jp>
Re: Julian Date Function Needed (Clay Irving)
Re: print "Hi", last ... (M.J.T. Guy)
Re: Problem reading lines with Win95 <flg@vhojd.skovde.se>
Re: reading end-of-line in a string <wesley@woais.com>
Reset an EOF condition - HowTo (Helmut Jarausch)
Re: scalar vs array <Harald.Joerg@mch.sni.de>
Re: socket programming <kevinl@casc.com>
Re: Sorting Associative Array? (Urgent) <ajohnson@gpu.srv.ualberta.ca>
Re: Splitting large file (50MB+)? <ravn@amrose.spo.dk>
sysread/syswrite mangle data on Win32? <norm@berkshire.net>
Re: Testing for the non-existence of a variable. (Tung-chiang Yang)
Re: Testing for the non-existence of a variable. <sfairey@metrica.co.uk>
Re: Testing for the non-existence of a variable. (Andrew Starr)
Re: Testing for the non-existence of a variable. <jhi@alpha.hut.fi>
Re: Traslate or other method? (Michael Slone)
Re: Trouble opening a file with date modified (Clay Irving)
Re: what module to use for sysopen? (P.M.Wong )
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 20 Jun 1997 06:20:30 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Case-matching substitution?
Message-Id: <u1pdo5.3a8.ln@localhost>
William C Ralph (ralphwc@mail.auburn.edu) wrote:
: I'm looking for a case-matching substitute commmand for words in a long
: string of text.
: For example:
: I want to substitue all the instances of the word cat with the word
: feline. The regular substitute operator works grand if all instances are
: lowercase.
: $text = <STDIN>;
: $find = "cat";
: $replace = "feline";
: $text =~ s/ $find / $replace /g;
: But what happens when someone inputs Cat, or CAT. I don't want to have to
: type in every variation of every word into my find and replace file. Is
: there some kind of tag (-i just replaces Cat and CAT with feline instead
: of Feline and FELINE) that I can use in the substitute operator.
You could put the mapping to the replacement string in a hash:
------------------------
#! /usr/bin/perl -w
%cats = (
cat => 'feline',
Cat => 'Feline',
CAT => 'FELINE'
);
$_ = "cat and Cat and CAT\n"; # lookup replacement in the hash
s/\b(cat)\b/$cats{$1}/gi;
print;
------------------------
: Even if
: I could find a way to cap the first letter, that might be sufficient.
You mean something like this?
$_ = "cat and Cat and CAT\n"; # lookup replacement in the hash
s/\b(c)at\b/$1 eq 'C' ? "Feline" : "feline"/gie;
print;
or maybe you are looking for the ucfirst() function?
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Fri, 20 Jun 1997 10:30:36 +0200
From: Dimitri Papadopoulos <papadopo@shfj.cea.fr>
Subject: CGI_Lite
Message-Id: <33AA3FAC.233D@shfj.cea.fr>
Hi,
Do you know where to find CGI_Lite v1.8?
I can find only CGI_Lite v1.7 on CPAN.
Version 1.7 has a bug when trying to upload an HTML file.
It leads to "Out of memory!" messages in the Web server
error log and "no more processes" messages on the command
line. Have you experienced such problems with version 1.7?
With version 1.8?
Thank you,
--
Dimitri Papadopoulos
papadopo@shfj.cea.fr
------------------------------
Date: 20 Jun 1997 13:38:58 +0200
From: Marc Weeber <marc@farm.rug.nl>
Subject: code/module for Fisher Exact Test
Message-Id: <87u3it7bcd.fsf@linda.farm.rug.nl>
Hello perl-people,
I'm looking for perl code or a perl module for a Fisher Exact test for
contingency tables. Does anyone have it/knows something about it? If
you do, please post or mail a message.
thanks and regards,
Marc
--
------------------------------------------------------------------
Marc Weeber http://www.farm.rug.nl/marc/home.html
Groningen University Centre for Pharmacy
marc@farm.rug.nl Social Pharmacy and Pharmacoepidemiology
tel: +31 50 3637571 ___ A. Deusinglaan 2
fax: +31 50 3633311 | 9713 AW Groningen, The Netherlands
----------------------0-------------------------------------------
------------------------------
Date: Fri, 20 Jun 1997 10:12:05 +0100
From: Simon Fairey <sfairey@metrica.co.uk>
To: Chris Mason <cmason@ros.res.cmu.edu>
Subject: Re: Delete specific element from list
Message-Id: <33AA4965.41C6@metrica.co.uk>
Chris Mason wrote:
>
> All-
>
> This is frustrating. I'm trying to write a subroutine to delete a
> specific element in a array. It would work like:
>
> @arr = qw(red green blue yellow);
>
> listdel(@arr, 'blue');
>
> # @arr = ('red', 'green', 'yellow');
>
>
>
> I thought of something like:
>
> sub listdel {
> local (@arr, $del) = @_;
I think you will have a problem here with @arr swallowing up everything
from @_ you would probably be better off passing a reference to the
array to your function.
> for (@arr) {
> push @new shift @arr unless ($_ eq $del);
> }
> @arr = @new;
> }
>
> but I know that isn't right.
>
> Thanks for any help. I know this is really simple, and that's why its
> making me mad.
>
> -c
How about the following, its nothing spectacular but it removes the need
for copying the entire array and would also finish as soon as the match
is found.
@arr = qw( red yellow green blue );
listdel( \@arr, 'blue' );
print "\n",join(" ", @arr),"\n";
sub listdel {
my( $array_ref, $del ) = @_;
my $i=0;
for(@arr) {
/^$del$/ and splice( @$array_ref, $i, 1 ) and last;
$i++;
}
}
Have fun,
Simon
------------------------------
Date: 20 Jun 1997 09:06:52 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Delete specific element from list
Message-Id: <5odh7c$2pp@lyra.csx.cam.ac.uk>
Chris Mason <cmason@ros.res.cmu.edu> wrote:
>I thought of something like:
>
> sub listdel {
> local (@arr, $del) = @_;
> for (@arr) {
> push @new shift @arr unless ($_ eq $del);
> }
> @arr = @new;
> }
>
>but I know that isn't right.
That indeed isn't right. Firstly, if you add or delete elements from
@arr inside a for (@arr) loop (for example with shift), Perl will get
very confused. Sadly, Perl doesn't generate any warning for this.
Secondly, you have problems with your argument passing. That
local (@arr, $del) = @_;
will suck all the arguments into @arr, leaving nothing for $del.
Thirdly, you want the subroutine to update @arr, but it only updates
the local copy inside the subroutine; this will be lost when the
subroutine returns. You need to pass a _reference_ to @arr to the
subroutine.
'grep' is a convenient function for selecting elements from an array,
so this subroutine would do what you want:
[ Warning - all code examples untested ]
sub listdel {
my ($arrayref, $del) = @_; # use my rather than local
@$arrayref = grep { $_ ne $del } @$arrayref;
};
called with
listdel(\@arr, 'blue');
This does unneccessary copying of the array; if efficiency is crucial,
it's probably better to remove the elements using split:
sub listdel {
my ($arrayref, $del) = @_;
for (0..$#$arrayref) {
splice @$arrayref, $_, 1 if $arrayref->[$_] eq $del;
};
};
If you don't like writing references in your calling sequence, you can
get Perl to do it for you by using prototypes. Declare the
subroutine as
sub listdel (\@$) {
and then call as
listdel @arr, 'blue';
(If you do this, remember to declare the subroutine _before_ any call.)
Mike Guy
------------------------------
Date: 20 Jun 1997 12:59:20 GMT
From: bjepson@ids.net (Brian Jepson)
Subject: Re: Delete specific element from list
Message-Id: <slrn5qkvcu.1ua.bjepson@Sol2-5.ids.net>
In article <5od4j7$50o@news.onramp.net>, Chris Mason wrote:
>All-
>
> This is frustrating. I'm trying to write a subroutine to delete a
>specific element in a array. It would work like:
>
> @arr = qw(red green blue yellow);
>
> listdel(@arr, 'blue');
>
> # @arr = ('red', 'green', 'yellow');
>
[...]
How about:
@arr = qw(red green blue yellow);
@arr = grep( ! /^blue$/, @arr);
print join("\n", @arr);
or:
@arr = qw(red green blue yellow);
@arr = grep( $_ ne 'blue', @arr);
print join("\n", @arr);
Hope this helps,
--
Brian Jepson * (bjepson@ids.net) * http://www.ids.net/~bjepson
Int(ra|er)net Database Developer, Author, Crypto-Fluxologist
Non-Prophet Arts Technology Flux: http://www.ids.net/~as220
WWW/Database/NT,Java/Database: http://www.ids.net/~bjepson/books
------------------------------
Date: Fri, 20 Jun 1997 15:32:33 +0200
From: "Dr. Michael Hartje" <hartje@etech.hs-bremen.de>
Subject: Errornous read/sysread for PC-Perl?
Message-Id: <33AA8671.736D@etech.hs-bremen.de>
to do a binary read to a file, I use read or sysread on a PC / Perl32
like the procedure down there.
The errornous problem is:
Assume file length of 220 bytes as input.
The result (depending on the blocklength) is _less_ than 220!!
for example: a text file of 216 result 209 bytes!
a binary file 1210 Bytes, result 267 bytes!!!!!
To compare it, I tried on Macintosh with Per 4.036: excellent and
errorfree
What switch, What special $sign varables have to be set in special
manner?
Any ideas out there?
Thank You for reading an thinking about this problem
Michael
Code follows:
#Start of code example
#!perl
# just to check sysread or read
# count ByteBlocks of a file and display
open (INFILE, @ARGV[0]) || die ("$ARGV[0]: $!\n"); # nothing to do
#init all $var
$lenByte = 2; # length of block read from the file
$z =0; # counter of blocks read
for (;;) {
$a = read (INFILE, $bb, $lenByte);
# may be also
# $a = sysread (INFILE, $bb, $lenByte);
$z++; # set counter up
if ($a != $lenByte) { # Read error?
last # break out of loop
};
}
$totalread = $z * $lenByte + $a;
print ("$lenByte Bytes Blocklength \n"); # results
print ("$z Blocks read, in the last Block $a\n");
print ("Read $totalread Bytes\n");
close (INFILE);
#end of code example
Version of Perl:
> This is perl, version 5.001
>
> Unofficial patchlevel 1m.
>
> Copyright 1987-1994, Larry Wall
> Win32 port Copyright (c) 1995 Microsoft Corporation. All rights reserved.
> Developed by hip communications inc., http://info.hip.com/info/
>
> Perl for Win32 Build 110
> Built Aug 13 1996@08:18:50
--
Hochschule Bremen Labor fuer Hochspannungstechnik
Prof. Dr. Michael Hartje Neustadtswall 30; 28199 Bremen
Telefon: +49 421 5905-444 FAX: +49 421 5905-476
mailto:hartje@etech.hs-bremen.de http://www.hs-bremen.de
------------------------------
Date: Fri, 20 Jun 1997 01:07:16 -0700
From: Eric Hilding <eric@hilding.com>
Subject: Example in PF doesn't work
Message-Id: <33AA3A34.5344@hilding.com>
I culled this from the Perl FAQ:
s/^\s+|\s+$//g; # perl4 or perl5
It is supposed to strip blank space from the beginning and
end of a string. I've tried it on:
"DAWSON DRIVE - LOT "
It doesn't work...it actually axes out *all* the text.
Hmmm. Help! Tnx.
Eric
------------------------------
Date: Fri, 20 Jun 1997 08:18:59 -0500
From: pudge@pobox.com (Chris Nandor)
Subject: Re: HELP: How to limit the length of contents in guestbook script?
Message-Id: <pudge-ya02408000R2006970818590001@news.idt.net>
In article <33A8E24D.25FF@hotmail.com>, perlprogrammer@hotmail.com wrote:
# Don't get me wrong. java is ok for some things.. some things not..
# someone emailed me about how java SCRIPT is not *java*.. two different
# things.. I suppose I should have mentioned that I program in java.. oh
# well.. anyway.. for what this person wanted, it was a few lines of
# perl.. you didn't even give the java script. You don't need a java
# browser for some things.. but when uyou have to have it.. no one will
# want to go and download a browser and then come back.. most people just
# pass it up.. not a big deal.. but I just didn't see the point in using
# java.. but to each his own.. I'm not bashing either jave or perl.. it
# just seems that most people would have to learn java.. it doesn't
# matter.. it's great to learn as much about as many languages as you can,
# and java is worth leanring.. just with asp sites, and other up and
# comming things, it's getting more and more useless.. or so it seems (to
# me). I agree perl is better. that's why I'm here looking like an idiot
# posting my opinions.
You are still talking about Java. I'm not going to post on this again
after this, but Java and JavaScript are not the same thing. I don't care
if you program in Java, and yes, you mentioned it before. That's why it
surprised me then and surprises me now that you are even discussing Java
when Java has nothing at all to do with anything that we are discussing.
You might as well be talking about Tcl. That has as much -- or more -- to
do with Java than JavaScript does.
--
Chris Nandor pudge@pobox.com http://pudge.net/
%PGPKey=('B76E72AD',[1024,'08 24 09 0B CE 73 CA 10 1F F7 7F 13 81 80 B6 B6'])
------------------------------
Date: 20 Jun 1997 09:43:39 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: Install PERL5
Message-Id: <5oe1eb$srl@panix.com>
In <01bc7cdc$bd6b33a0$6b96efc2@default> "Dennis Hansen" <cyberdh@post2.tele.dk> writes:
>My server haven't PERL5, where can I get it??
>Please mail me at cyberdh@post2.tele.dk
http://www.perl.com
[posted and mailed]
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: Fri, 20 Jun 1997 17:01:53 +0900
From: Lee Ingram <ingram@shljapan.co.jp>
Subject: Japanese (or Unicode) support in PERL For Win32
Message-Id: <33AA38F1.E3CE8C74@shljapan.co.jp>
Does anyone know if the Win32 port of PERL supports multibyte character sets? Does one need to use a
specially written module? If so, where could one find such a module? (I've done a quick scan of CPAN
already).
THanks,
Lee
------------------------------
Date: 20 Jun 1997 09:33:56 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: Julian Date Function Needed
Message-Id: <5oe0s4$qm9@panix.com>
In <33a8bbbb.1597349@news.earthlink.net> frank@primemail.com (Frank Fisher) writes:
>I need to count days into the future; example, today() + 45 days to
>get a mm/dd/yy date. Is there a julian date function I can use or
>some other perl function that will do the same thing?
The most excellent Date:Manip module perhaps? Check this out:
#!/usr/local/bin/perl -w
use Date::Manip;
$today = UnixDate("today", "%m/%d/%y");
print "Today is $today\n";
$err = 0;
$date = DateCalc("today","+ 45 days",$err);
if (!($err)) {
$date = UnixDate($date, "%m/%d/%y");
print "$date is 45 days from today\n";
}
$err = 0;
$bdate = DateCalc("today","+ 45 business days",$err);
if (!($err)) {
$bdate = UnixDate($bdate, "%m/%d/%y");
print "$bdate is 45 business days from today\n";
}
__END__
The output of this program is:
Today is 06/20/97
08/04/97 is 45 days from today
08/22/97 is 45 business days from today
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: 20 Jun 1997 08:10:10 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: print "Hi", last ...
Message-Id: <5oddt2$sp7@lyra.csx.cam.ac.uk>
Mike Stok <mike@stok.co.uk> wrote:
>
>It is executing the print, it's just that you're effectively saying
>
> print ("Yes\n", last if 1);
Not quite. It's actually parsed as
print ("Yes\n", last) if 1;
>You can say
>
> print ("Yes\n"), last if 1;
>
>and perl -w will inform you
>
> print (...) interpreted as function at ...
>
>but it'll do what you want, or you can say
>
> do {print "Yes\n"; last} if 1;
>
>which doesn't provoke any warnings.
The form I prefer, which doesn't generate warnings, is
(print "Yes\n"), last if 1;
Mike Guy
------------------------------
Date: 20 Jun 97 10:16:28 GMT
From: "Fredrik Lindberg" <flg@vhojd.skovde.se>
Subject: Re: Problem reading lines with Win95
Message-Id: <01bc7d63$05fafb60$e20f10c2@odens.di.vhojd.skovde.se>
>>> Ronald L. Parker <ron@farmworks.com> wrote in article
> >>> dsisco@learningco.com (Dick Sisco) wrote:
> > # if blank line seperator
> > } elsif ($line eq "") {
>
> If normal people are editing this file by hand, you should probably
> check ($line =~ /\s*/) instead.
>
Ouch, it better be /^\s*$/ since /\s*/ matches everything !
/Fredrik
------------------------------
Date: Fri, 20 Jun 1997 01:30:59 -0500
From: Wesley Miaw <wesley@woais.com>
Subject: Re: reading end-of-line in a string
Message-Id: <33AA23A3.2300@woais.com>
Maelstrom wrote:
>
> Hi. I've just downloaded a Perl script that converts form input from the
> WWW into Email. The problem is that the field 'comments' which is
> submitted from a text box is printed as one long string. Does anyone
> know how to catch end-of-line characters in a string returned from a form?
> Eventually I'd like to frame the text and perform other manipulations on
> the string.
<TEXTAREA> boxes on a web page return a single long string. There are no
end-of-line characters passed to the CGI. Instead, you will need to edit
the script so that it counts of say, 40 characters, and inserts a
newline character there.
--
Wesley Miaw wesley@woais.com
World of Artists Internet Services http://www.woais.com/
71 Middlesex Drive Tel: 518-439-0412
Slingerlands, NY 12159 FAX: 518-439-9722
------------------------------
Date: 20 Jun 1997 12:28:21 GMT
From: jarausch@numa1.igpm.rwth-aachen.de (Helmut Jarausch)
Subject: Reset an EOF condition - HowTo
Message-Id: <5odt15$9qb$1@news.rwth-aachen.de>
Hi,
I couldn't find it in the docs.
I want to
open FILE,....
while( define(<FILE>) ) { ... scan the file }
# now I want to process FILE again without close/open
# reset the error conditon (EOF) on FILE -- HowTo
seek FILE,0,0;
while( define(<FILE>) ) { ... process again }
Thanks for any hints,
Helmut.
--
Helmut Jarausch
Lehrstuhl f. Numerische Mathematik
Institute of Technology
RWTH Aachen
D 52056 Aachen, Germany
------------------------------
Date: Fri, 20 Jun 1997 14:09:21 +0000
From: Harald Joerg <Harald.Joerg@mch.sni.de>
To: Mats Larsson <matlar@rsv.se>
Subject: Re: scalar vs array
Message-Id: <33AA8F11.4906@mch.sni.de>
Mats Larsson wrote:
>
> I tried to call a subroutine in a "smart" way like this, i.e I want
> the subrotine to recieve the minussign when no arguments given.
>
> &fil_utskr (@ARGV||"-") unless $opt_P;
>
> if the script is called without arguments it reads STDIN as intended
> but if I run the script with one or more arguments, @ARGV will be treated
> as a scalar value and the subroutine recieves the number of arguments.
> It's just interesting to know if there is some way to force ARGV to be
> array or is it incompatible whith the || operator.
It's incompatible with ||, sort of. To see whether an array is
'false', || evaluates it in a scalar context.
You can write
&fil_utskr (@ARGV?@ARGV:"-") unless $opt_P;
though some spaces or even an extra statement might enhance readability.
--
Oook,
--haj--
------------------------------
Date: 20 Jun 1997 09:33:03 -0400
From: Kevin Lambright <kevinl@casc.com>
Subject: Re: socket programming
Message-Id: <yhfpvth4cxc.fsf@casc.com>
ddougal@gte.net (David Dougal) writes:
David,
sockets.pl is no longer the way to go with Perl5. Try 'use Socket;' and
things should work much better.
>
>
> I have a perl script with the following line:
>
> require "sockets.pl";
>
> I get the following error
> Can't locate sockets.pl in @INC at ./socket-demo1 line 3.
>
> The script is rather old
> has sockets.pl changed? I can't locate this module. What do I need for
> socket programming with Perl 5.003?
>
>
------------------------------------------------------------------------------
Kevin Lambright email: kevinl@casc.com
Cascade Communications Corp. voice: 508-952-7407
5 Carlisle Road fax: 508-692-1510
Westord, Ma. 01886
------------------------------
Date: Thu, 19 Jun 1997 08:59:48 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Sorting Associative Array? (Urgent)
Message-Id: <33A93B54.7EEE8D3C@gpu.srv.ualberta.ca>
Doug Seay wrote:
!
[snip]
! Your second line needs some cleaning up. To the right of
! the equal should be $hash{$key}, not %hash{$key}. But your
! fundamental problem is that you are copying elements one by
! %one from %hash to key_sorted_hash. There is nothing magic
! about %key_sorted_hash, so it will be ordered in a "random"
! fashion (probably the same order as %hash, but I don't know
! that for sure). There is nothing sorted about this. The
! fundamental reason is that YOU CANNOT SORT HASHES. The
! definition of a hash table doesn't allow ordering.
!
! Wesley, sorry but the only real solution is John's solution,
! or a variation on that theme.
!
and for one variation: you could always use DB_File for the
berkeley db, and have your hash tied to a btree ($DB_BTREE)
see Camel 2; page 389 for an in-memory example.
regards
andrew
------------------------------
Date: Fri, 20 Jun 1997 08:28:42 +0200
From: Thorbjoern Ravn Andersen <ravn@amrose.spo.dk>
To: ckng@global.com.my
Subject: Re: Splitting large file (50MB+)?
Message-Id: <33AA231A.41C6@amrose.spo.dk>
Ng Chin Kiong wrote:
>
> I'm currently using perl to write a program that will process a large
> TEXT file (50MB+) and to extract the data into a new file. However,
> because of the size of the file (50MB+), the system has ran out of
> memory. So, I'm thinking is there anyway I can split the text file
> into smaller pieces before processing? Or any other suggestion?
> Thanks in advance.
If you process the file via the <> handle, then don't read it all in at
once, but process the file line by line.
Check the hints at the end of the Perl book, and look for the
perl faq.
Regards,
--
Thorbjxrn Ravn Andersen "...and...Tubular Bells!"
http://www.dit.ou.dk/~ravn
------------------------------
Date: 20 Jun 1997 08:28:59 -0400
From: Norman Walsh <norm@berkshire.net>
Subject: sysread/syswrite mangle data on Win32?
Message-Id: <ug1ud4fw4.fsf@berkshire.net>
Hello World,
Is there any way to read/write binary data under Win32? I
discovered this morning that read(), sysread(), print, and
syswrite() all do CR/LF conversion on Win32. In other words,
if you attempt to write a buffer that contains a bare ^J,
it will always get turned into ^M^J.
Try this test:
$file1 = "\@\@TEST\@\@.1";
$file2 = "\@\@TEST\@\@.2";
$_ = "A\012B";
open (F, ">$file1");
print F $_;
close (F);
open (F, ">$file2");
syswrite (F, $_, length($_));
close (F);
Both of these files are four bytes long! For even more fun, consider
this fragment:
$file1 = "\@\@TEST\@\@.1";
open (F, $file1);
sysread (F, $_, -s $file1);
close (F);
print "Size: ", -s $file1, "\n";
print "Len : ", length($_), "\n";
It prints
Size: 4
Len : 3
So sysread() is mangling things as well. Is there some local
wierdness on my machine? If not, is there a workaround?
Cheers,
norm
--
Norman Walsh <nwalsh@arbortext.com> | Life is like arriving late for a
Senior Application Analyst | movie, having to figure out what
ArborText, Inc. (www.arbortext.com) | was going on without bothering
413.549.3868 Voice/FAX | everybody with a lot of
| questions, and then being
------------------------------
Date: Fri, 20 Jun 1997 08:21:19 GMT
From: tcyang@netcom.com (Tung-chiang Yang)
Subject: Re: Testing for the non-existence of a variable.
Message-Id: <tcyangEC2F7J.4J3@netcom.com>
Perl 5 provides 'defined' so you can just use
if (defined $var) {}
===================================
Joshua J. Kugler typed when the mommy tyrannosaurus found him:
: [Note, this is the second (I think) time I have posted this. My ISP's
: newserver has been acting up, so I don't know if this every got
: out/got any responses. Thanks for you patience]
: Hello All.
: I have written a few Perl5 scripts, and have had much success, but I
: have run up against something that has me stumped.
: I know you can test for the existence of a variable by using:
: if ($var) {#code here}
: But how can you test to see if $var is NOT defined?
: I have tried
: if not ($var), ifnot ($var), if !($var), and some I don't even
: remember.
: I know it is probably simple, but I have looked everywhere I know in
: the perldocs, and can't find anything to this effect.
: Right now I am using
: if ($var) {} else {Code here}, but I know there has to be something
: more elegant than that! :)
: Any help is greatly appreciated. Thanks!
: URLs would be fine too.
: Please respond to e-mail too.
--
========= Try the low-crossposting robomoderated 'alt.culture.taiwan' ===
soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
http://www.iglou.com/tcyang/Taiwan_faq.shtml, China_faq.shtml
------------------------------
Date: Fri, 20 Jun 1997 10:17:09 +0100
From: Simon Fairey <sfairey@metrica.co.uk>
To: "Joshua J. Kugler" <FIGHT-SPAMjkugler@inreach.com>
Subject: Re: Testing for the non-existence of a variable.
Message-Id: <33AA4A95.167E@metrica.co.uk>
Joshua J. Kugler wrote:
>
> [Note, this is the second (I think) time I have posted this. My ISP's
> newserver has been acting up, so I don't know if this every got
> out/got any responses. Thanks for you patience]
>
> Hello All.
>
> I have written a few Perl5 scripts, and have had much success, but I
> have run up against something that has me stumped.
>
> I know you can test for the existence of a variable by using:
>
> if ($var) {#code here}
>
> But how can you test to see if $var is NOT defined?
>
> I have tried
>
> if not ($var), ifnot ($var), if !($var), and some I don't even
> remember.
>
> I know it is probably simple, but I have looked everywhere I know in
> the perldocs, and can't find anything to this effect.
I always find the man pages a good place to start ;)
>
> Right now I am using
>
> if ($var) {} else {Code here}, but I know there has to be something
> more elegant than that! :)
>
> Any help is greatly appreciated. Thanks!
>
> URLs would be fine too.
>
> Please respond to e-mail too.
>
> j----- k-----
>
> Joshua J. Kugler
> Computer Consultant--Web Developer
> Real e-mail address spelled out to prevent spam. jkugler at inreach dot com
> http://www.cwebpages.com/jkugler
> Every knee shall bow, and every tongue confess, in heaven, on earth, and under the earth, that Jesus Christ is LORD -- Count on it!
> - - - - -
> To reply via e-mail, please remove 'FIGHT-SPAM' from my e-mail address. Thanks.
Try the perlfunc manpage for 'defined' and 'undef'
Have fun.
Simon
------------------------------
Date: Fri, 20 Jun 1997 06:08:08 -0600
From: atspublic@bigfoot.com (Andrew Starr)
Subject: Re: Testing for the non-existence of a variable.
Message-Id: <atspublic-2006970608080001@max02-24.qni.com>
In article <33aa1583.34610604@news.inreach.com>,
FIGHT-SPAMjkugler@inreach.com (Joshua J. Kugler) wrote:
> I know you can test for the existence of a variable by using:
>
> if ($var) {#code here}
>
> But how can you test to see if $var is NOT defined?
>
> I have tried
>
> if not ($var), ifnot ($var), if !($var), and some I don't even
> remember.
>
[snip]
>
> Right now I am using
>
> if ($var) {} else {Code here}, but I know there has to be something
> more elegant than that! :)
unless($var) {do this}
BUT: I'm not sure if this is what you want. You asked about "existence" of
a variable. If $var exists, but is set to 0, then I believe (but could be
wrong) that if($var) or unless($var) would treat the situation of $var==0
to the same as $var not existing (which are not equivalent, in my opinion,
so I'm hoping I'm wrong.)
-Andrew
--
Andrew Starr <mailto:atspublic@bigfoot.com>
http://www.amherst.edu/~atstarr/eudora has my unoff. Eudora Site
http://www.amherst.edu/~atstarr/eudora/faq.html by Hank Zimmerman
I have no connection to Qualcomm other than being a happy customer!
If I am answering a question: please post followup questions to the newsgroup as well as mailing me a copy. For new questions, please just post to the newsgroup. Thank you.
------------------------------
Date: 20 Jun 1997 11:48:21 +0300
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: Testing for the non-existence of a variable.
Message-Id: <oeelo45bqy2.fsf@alpha.hut.fi>
: I know you can test for the existence of a variable by using:
:
: if ($var) {#code here}
No you cannot. Here, you are testing for
"is-the-numeric-version-of-$var-non-zero".
: But how can you test to see if $var is NOT defined?
:
: I have tried
:
: if not ($var), ifnot ($var), if !($var), and some I don't even
: remember.
You already know the answer. You already said it yourself.
if (not defined $var)
: I know it is probably simple, but I have looked everywhere I know in
: the perldocs, and can't find anything to this effect.
You have not been looking hard enough. I suggest you study all of
the "perldata" manual page.
--
$jhi++; # http://www.iki.fi/~jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen
------------------------------
Date: 19 Jun 1997 12:56:09 -0400
From: harvel@maxwell.ml.org (Michael Slone)
To: David Cheitel <david1@earthlink.net>
Subject: Re: Traslate or other method?
Message-Id: <lnoh92mt0q.fsf@valjean.sfhs.floyd.k12.ky.us>
[posted & mailed]
In article <33A8158A.E72E1B6E@earthlink.net> David Cheitel
<david1@earthlink.net> writes:
>I am trying to convert a alphanumeric string to ascii equiv.
>
>I would like to use a tr/A-Z/027-053/ but as it stands perl looks at
>that as 0 2 7 as individual substitutions.
>
>I would like a string ie. CR000027 converted to the ascii equiv.
>
>Thanks.
>
I didn't put the result in the initial string, but here is my stab at it:
(See man perlfunc for most likely better ways of doing it.)
#! /usr/bin/perl -w
#
# cvt2asc
#
# Copyright (C) 1997 by Michael Slone. Permission is given to use, copy,
# rewrite, delete, etc., this file, and pass it on to others, so long as
# subsequent freedom to do the same is not infringed.
#
# Converts a string to ASCII.
#
use strict;
my $example = "Jackson Pollock";
my @answer = map(ord, split(//, $example));
print "\"$example\" is composed of the ASCII values:\n";
print "@answer\n";
__END__
Hope this helps.
--
Michael Slone harvel@maxwell.ml.org
Home: http://harvel.home.ml.org/
Liten Project: http://harvel.home.ml.org/leten/
------------------------------
Date: 20 Jun 1997 09:41:01 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: Trouble opening a file with date modified
Message-Id: <5oe19d$sel@panix.com>
In <33A936CA.2501@vanoise.sps.mot.com> Manuel Valente <mvale@vanoise.sps.mot.com> writes:
>Hi !
Hi.
>Perl allows me to modify the modification date of a file (utime
>function), not the creation date. But if the modified date is before the
>creation date, Perl won't open the file any more whereas Unix still
>does.
How do you get the creation date of a file? Are you confusing the inode
change date (ctime) with creation date?
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: 20 Jun 1997 10:02:33 GMT
From: s11976@ctsc.hkbc.hk (P.M.Wong )
Subject: Re: what module to use for sysopen?
Message-Id: <5odkfp$a3o$1@power42t.hkbu.edu.hk>
Tad McClellan (tadmc@flash.net) wrote:
: Pui Ming WONG (s11976@net2.hkbu.edu.hk) wrote:
: : I simply tried out the example listed in the FAQ. Here it is:
: : Use Fcntl;
: ^
: ^
: use Fcntl;
: : sysopen(FH,"/tmp/filename", O_WRONLY|O_EXCL|O_CREAT, 0644);
: : The error that came up is:
: : Undefined subroutine &main::sysopen called at line 3
I did type
use
not Use
Just typo mistake in my posting
--
__
/ \_/ ) __ Pui Ming WONG (E-mail: pm@hkbu.edu.hk)
/ ( ------------- } System Support Programmer,
( =l=ll===============__} Computing & Telecomm. Services Centre
\ _ ( Hong Kong Baptist University
\_/ \__) 224 Waterloo Road, Hong Kong
------------------------------
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 639
*************************************