[17898] in Perl-Users-Digest
Perl-Users Digest, Issue: 58 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jan 14 03:09:27 2001
Date: Sun, 14 Jan 2001 00:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <979459510-v10-i58@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 14 Jan 2001 Volume: 10 Number: 58
Today's topics:
$query->param('textarea'); <jason@generationterrorists.com>
Re: $query->param('textarea'); <joe+usenet@sunstarsys.com>
Re: Can't associate .PL files in Win98 <johngros.NOSPAM@bigpond.net.au>
Re: Code breaking <james@NOSPAM.demon.co.uk>
Re: Help me append <comdog@panix.com>
Re: Help me append (Colin Watson)
Net::POP3 <gpwillatt@crosswinds.net>
Re: Net::Telnet with W2K NTLM <davidkirk@mediaone.net>
Perl 5.6.0 lib/io_unix.t fails at $sock = $listen- (Matt Schalit)
Re: Perl 5.6.0 lib/io_unix.t fails at $sock = $lis (J. L. Schilling)
Re: Perl 5.6.0 lib/io_unix.t fails at $sock = $lis (Matt Schalit)
Re: Perl and AOL. How is this possible? (Abigail)
Re: References <johngros.NOSPAM@bigpond.net.au>
Re: References (Colin Watson)
Re: Replacing the "\" character using s///. (Mike Stok)
Syntactic symbol for continuing one line into another <jaymax@sac.verio.net>
Re: Syntactic symbol for continuing one line into anoth <uri@sysarch.com>
Re: Syntactic symbol for continuing one line into anoth <joe+usenet@sunstarsys.com>
Re: Trouble with range operator and unitialized variabl (Mark Jason Dominus)
Re: Trouble with range operator and unitialized variabl <uri@sysarch.com>
Re: Trouble with range operator and unitialized variabl <jbritain@home.com>
Win32 compile issue for 5.6.0 <a565a87@my-deja.com>
word combinations? <zigouras@mail.med.upenn.edu>
Re: word combinations? <joe+usenet@sunstarsys.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 14 Jan 2001 15:07:14 +0800
From: "Jason Q." <jason@generationterrorists.com>
Subject: $query->param('textarea');
Message-Id: <3A615022.EC59D988@generationterrorists.com>
Hi all,
I am using the following lines to retrieve the values of a html form's
textarea:
use CGI;
$query = new CGI;
$textarea = $query->param('textarea');
$textarea =~ s/\n/<BR>/g;
print $textarea;
However, there seems to be some other character
, which comes before the linefeed.
What is this character and how do I remove it?
Any help would be appreciated.
Thanks.
JQ
------------------------------
Date: 14 Jan 2001 02:49:30 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: $query->param('textarea');
Message-Id: <m3snmmzi7p.fsf@mumonkan.sunstarsys.com>
"Jason Q." <jason@generationterrorists.com> writes:
use strict;
> use CGI;
> $query = new CGI;
^^
my
> $textarea = $query->param('textarea');
^^
my
> $textarea =~ s/\n/<BR>/g;
> print $textarea;
>
> However, there seems to be some other character
> , which comes before the linefeed.
^^^^^^^^^^^^^^^^^^^^^^^^
Usually that's a carriage return "\r" which you can
strip with
$textarea =~ y[\r][]d;
HTH
--
Joe Schaefer
------------------------------
Date: Sun, 14 Jan 2001 05:16:23 GMT
From: "John Boy Walton" <johngros.NOSPAM@bigpond.net.au>
Subject: Re: Can't associate .PL files in Win98
Message-Id: <HCa86.59417$xW4.477832@news-server.bigpond.net.au>
"Gary Burton" <glburton@mindspring.com> wrote in message
news:3A60BD09.B0DAA9F6@mindspring.com...
> I am a newbie using Win98. I am using ActivePerl v5.6, and working from
the ActivePerl online documentation. I can run my example programs from a
DOS window by typing in "Perl filename"; but when I associate the .PL
extension as the literature suggest, all I get is a DOS window that closes
so quickly that I can't read the error message.
That means your scripts are associated with perl.
Run them from the commandline rather than double clicking on them. The
errors will stay around long enough to read then.
The FAQs can be hard to understand just read them until you get it. I have
read some of the docs four or five times and still don't understand the
subjects.
------------------------------
Date: Sun, 14 Jan 2001 04:49:12 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Code breaking
Message-Id: <ant1404120b0fNdQ@oakseed.demon.co.uk>
In article <93pjqp$7e6$1@newsg1.svr.pol.co.uk>, James Boulter
<URL:mailto:jbou@bunker79.fsnet.co.uk> wrote:
> I am writting a perl program to translate normal words into code. In order
> to do this I need to be able to put each letter in a variable through the
> same process. Is there a way of saying:
>
> foreach (letter in the $data variable) {
> translate the letter
> }
Yes, just say something like this:
foreach my $letter (split //, $data) {
# Do something with $letter
}
If $data is large it might be better to avoid the creation of a temporary
array that essentially duplicates $data by using an index into $data eg:
for (my $i = 0; $i <= length $data; $i++) {
my $letter = substr $data, $i, 1;
# Do something with $letter
}
> Also, each letter could be put into an array, if so, how?
Use the split technique from above:
@array_of_letters = split //, $data;
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Sat, 13 Jan 2001 18:11:10 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: Help me append
Message-Id: <comdog-B80896.18111013012001@news.panix.com>
In article <N2586.8300$U4.402153@newsread1.prod.itd.earthlink.net>,
"E.Neal" <eddyneal@earthlink.net> wrote:
> I'm trying to update a text. For some reason the way I'm trying to
> append doesn't work.
> open (APPEND, '>> contact.txt');
what is the return value from open()? what is in $! ?
--
brian d foy <comdog@panix.com>
no longer for hire ;)
------------------------------
Date: 13 Jan 2001 23:28:43 GMT
From: cjw44@flatline.org.uk (Colin Watson)
Subject: Re: Help me append
Message-Id: <93qobb$b60$1@riva.ucam.org>
E.Neal <eddyneal@earthlink.net> wrote:
>I'm trying to update a text. For some reason the way I'm trying to
>append doesn't work. I have scoured the net and my local help files for the
>answer, but I haven't been able to find it. I can append when running local
>scripts, but through the browser is where I'm running into trouble. I would
>appreciate any help.
>#!perl
>
>use CGI ':standard';
>
>print header();
>print start_html();
>
>$firstname = param(firstname);
>$lastname = param(lastname);
>$telephone = param(telephone);
>
>open (APPEND, '>> contact.txt');
What Brian Foy said (check $!). You could 'use CGI::Carp
qw(fatalsToBrowser)' to see fatal error messages, such as from something
like 'open (...) or die "open contact.txt failed: $!";'. Chances are the
current directory of your program isn't what you expect it to be when
run as a CGI script.
>print APPEND $firstname," ",$lastname," ",$telephone;
'print APPEND "$firstname $lastname $telephone";' is probably clearer.
--
Colin Watson [cjw44@flatline.org.uk]
"Give us a chance. We grow on you. Like fungus." - sjk25 on ucam.chat
------------------------------
Date: Sun, 14 Jan 2001 01:56:29 +0000
From: Greg Willatt <gpwillatt@crosswinds.net>
Subject: Net::POP3
Message-Id: <3A61074D.16E6C9E1@crosswinds.net>
Hi, can anyone possibly point me to a docuementation on using Net::POP3
to retrieve mail that contains some examples?
Thanks you :)
------------------------------
Date: Sun, 14 Jan 2001 02:10:40 GMT
From: David Kirkpatrick <davidkirk@mediaone.net>
Subject: Re: Net::Telnet with W2K NTLM
Message-Id: <3A610AEF.C47AA191@mediaone.net>
Crew,
In case anyone is following this - here are the developments - although somewhat
shaky as I still "getting it".
I was setting the Prompt to Microsoft Telnet instead of the shell C:\>. I then
experimented with C:\> It turns out it needs 4 slashes c:\\\\> to succeed. Got the
clue along with others from this excellent page.
http://velocity.activestate.com/docs/ActivePerl/site/lib/Net/Telnet.html#examples
So telnet can be done from Unix (solaris 2.6 anyway) to W2K with a little grief..
Required are changing the behavior of NTLM -if you have a w2k box search on NTLM for an
explanation of how to do that. With the example from the page above commands succeed
when the prompt is done correctly. The page also shows how to log the session, input
and outupt from both sides. The log files are on the initiating side.
davidk
------------------------------
Date: Sat, 13 Jan 2001 18:28:57 -0800
From: mschalit@pacbell.net (Matt Schalit)
Subject: Perl 5.6.0 lib/io_unix.t fails at $sock = $listen->accept()
Message-Id: <MPG.14caaec7a47103849896f6@news.pacbell.net>
Hey now,
I'm new to perl, but have experience with Unix, C,
and the like. I posted this seperately to the newsgroups
comp.lang.perl.misc and comp.unix.sco.programmer.
I'm trying to build 5.6.0 on UnixWare 7.1.1 using cc,
while logged in as root. Thanks to the everyone's
excellent work, I can build a great perl with thread
support, 64all, dynamic, shared, etc....
Every test script passes except one, the lib/io_unix.t
test. Here are the relevant lines of code and what they
produce for output:
$| = 1;
print "1..5\n";
use IO::Socket;
$listen = IO::Socket::UNIX->new(Local=>$PATH, Listen=>0) || die "$!";
print "ok 1\n"
My reading of the other test scripts told me that the || is
incorrect syntax, so I changed it to or and that made no
difference in the results which are:
1..5
listen gets the value IO::Socket::UNIX=GLOB(0x8176cdc)
ok 1
Next are these commands:
if($pid = fork()) {
$sock = $listen->accept();
print "ok 2\nThe value of SOCK is --$sock--\n";
print $sock->getline();
print $sock "ok 4\n";
....
}....
And the result is:
ok 2
The value of SOCK is ----
Can't call method "getline" on an undefined value @ lib/io_unix.t
line 65.
So what happened to the accept() call?
Here's what the output of truss shows happened to those calls:
-------------------------------------------------------------------
write(1, " 1 . . 5\n", 5) = 5
getcontext(0x080476A8)
xsocket(UW71|XPG4, AF_UNIX, SOCK_STREAM, 0) = 3
fcntl(3, F_GETFL, 0xBFF7B9BC) = 2
fcntl(3, F_GETFL, 0xBFF7B9BC) = 2
fcntl(3, F_SETFD, 0x00000001) = 0
xbind(UW71|XPG4, 3, 0x080880BC, 110) = 0
xlisten(UW71|XPG4, 3, 5) = 0
ok 1
write(1, " o k 1\n", 5) = 5
forkall() = 21642
getcontext(0x080476A8)
xaccept(UW71|XPG4, 3, 0x08047994, 0x080479A8) = 4
fcntl(4, F_GETFL, 0xBFF7B9BC) = 2
fcntl(4, F_GETFL, 0xBFF7B9BC) = 2
fcntl(4, F_SETFD, 0x00000001) = 0
brk(0x08180000) = 0
brk(0x08180800) = 0
getcontext(0x080476A8)
getcontext(0x080475FC)
close(4) = 0
Received signal #18, SIGCLD [default]
siginfo: SIGCLD CLD_EXITED pid=21642 uid=0 status=0x0000
close(4) Err#9 EBADF
ok 2
The value of SOCK is ----
write(1, " o k 2\n T h e v a l".., 31) = 31
The value of LISTEN is --IO::Socket::UNIX=GLOB(0x8176cdc)--
write(1, " T h e v a l u e o f".., 60) = 60
Can't call method "getline" on an undefined value at lib/io_unix.t line 67.
write(2, " C a n ' t c a l l m".., 76) = 76
----------------------------------------------------------------------------
When xaccept() returned a 4, I think that's ok as stated in the
accept(3sock) page that you can find at http://uw7doc.sco.com/
--------------------------------------------------
accept -- accept a connection on a socket
Synopsis
cc [options] file -lsocket -lnsl
#include <sys/types.h>
#include <sys/socket.h>
int accept(int s, struct sockaddr *addr, size_t *addrlen);
.....
Return values
accept returns -1 on error. If it succeeds, it returns a
non-negative integer that is a descriptor for the accepted socket.
Errors
accept will fail if:
EBADF
The descriptor is invalid.
.........
Notice:
The type of address structure passed to accept depends on
the address family. UNIX domain sockets (address family
AF_UNIX) require a sockaddr_un structure as defined in
sys/un.h;
--------------------------------------------------
And my reading of sys/un.h refers to AF_UNIX and the following:
struct sockaddr_un {
u_char sun_len;
u_char sun_family;
u_short sun_path[108];
};
I inluded -lsocket and -lnsl in my compile. I'm not sure what info
you all may need, but that's all I have off the top of my head.
I was wondering if someone could hack out a quick test of this
UNIX socket thing that's different from io_unix.t, so I could test
it out? I would have written one myself, but I don't know perl from
my big toe.
Thanks for taking to time to read this :)
Matt
------------------------------
Date: 14 Jan 2001 02:52:11 GMT
From: jls@sco.com (J. L. Schilling)
Subject: Re: Perl 5.6.0 lib/io_unix.t fails at $sock = $listen->accept()
Message-Id: <93r48r$ki5$1@hobbes.sco.com>
Matt Schalit (mschalit@pacbell.net) wrote:
: I'm trying to build 5.6.0 on UnixWare 7.1.1 using cc, [...]
: Every test script passes except one, the lib/io_unix.t
: test. [...]
This test failure was raised on few weeks ago in one of the SCO newsgroups.
I'm told it has to do with a networking problem that was introduced with
SCO's in-kernel sockets (a ptf in UW 7.1.0, part of the baselinein UW 7.1.1).
--
Jonathan Schilling SCO, Inc. jls@sco.com
------------------------------
Date: Sat, 13 Jan 2001 20:26:09 -0800
From: mschalit@pacbell.net (Matt Schalit)
Subject: Re: Perl 5.6.0 lib/io_unix.t fails at $sock = $listen->accept()
Message-Id: <MPG.14caca3e1d2301219896fb@news.pacbell.net>
In article <93r48r$ki5$1@hobbes.sco.com>, jls@sco.com says...
> Matt Schalit (mschalit@pacbell.net) wrote:
>
> : I'm trying to build 5.6.0 on UnixWare 7.1.1 using cc, [...]
>
> : Every test script passes except one, the lib/io_unix.t
> : test. [...]
>
> This test failure was raised on few weeks ago in one of the SCO newsgroups.
>
> I'm told it has to do with a networking problem that was introduced with
> SCO's in-kernel sockets (a ptf in UW 7.1.0, part of the baselinein UW 7.1.1).
>
> --
> Jonathan Schilling SCO, Inc. jls@sco.com
Thanks for the heads up.
I was pretty sure that perl compiled like a charm.
Thanks again to the dev team.
Matt
------------------------------
Date: 14 Jan 2001 00:40:14 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Perl and AOL. How is this possible?
Message-Id: <slrn961tbe.qth.abigail@tsathoggua.rlyeh.net>
G.A.D.Miles (usad1@gadnet.com) wrote on MMDCXCII September MCMXCIII in
<URL:news:3a605397.7747790@news.newsguy.com>:
.. I have written some perl scripts for running your own banner exchange.
.. When you click on a banner it takes you to the appropriate site. This
.. works fine in all browsers. However, if you right click on a banner
.. and opt to open the page in a new browser window, it works fine in IE
.. and Netscape, but in AOL the script cannot find the site and returns
.. the default URL location.
"the script cannot find the site".
*What site* and how are you searching for the site? Why does the program
need to `find' a site anyway, as nothing in the status purpose of program
needs to `find' a site?
.. How can this be possible since it is the server, not the browser that
.. is running the code?
According to your status problem, the program can't find a site.
Or are you utterly clueless and should you be asking in a browser group?
Abigail
--
$"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_=sub{print/::(.*)/};
$\=$/;q<Just another Perl Hacker>->();
------------------------------
Date: Sun, 14 Jan 2001 01:06:12 GMT
From: "John Boy Walton" <johngros.NOSPAM@bigpond.net.au>
Subject: Re: References
Message-Id: <8Y686.59047$xW4.475352@news-server.bigpond.net.au>
"Colin Watson" <cjw44@flatline.org.uk> wrote in message
news:93pogm$ror$1@riva.ucam.org...
> John Boy Walton <johngros.NOSPAM@bigpond.net.au> wrote:
> >"Joe Schaefer" <joe+usenet@sunstarsys.com> wrote in message
> >news:m3u2740yyq.fsf@mumonkan.sunstarsys.com...
> >> btw - are "xaxis" and "yaxis" scalars or arrays?
> >
> >xaxis and yaxis are both arrays and scalars.
> >I was trying to access them as arrays if an indice was passed to the sub
and
> >as scalars if no indice was passed.
>
> I don't think you really understand Perl's data types, then ('perldoc
> perldata'). Nothing can be both an array and a scalar. On the other
> hand, a given variable might be a *reference* to either an array or a
> scalar, and you can find out which by using ref().
Sorry I was not clear I have the scalars $xaxis and $yaxis and the arrays
@xaxis and @yaxis.
I will check out perlref again to see the difference.
------------------------------
Date: 14 Jan 2001 02:01:22 GMT
From: cjw44@flatline.org.uk (Colin Watson)
Subject: Re: References
Message-Id: <93r19i$f3d$1@riva.ucam.org>
John Boy Walton <johngros.NOSPAM@bigpond.net.au> wrote:
>"Colin Watson" <cjw44@flatline.org.uk> wrote in message
>news:93pogm$ror$1@riva.ucam.org...
>> John Boy Walton <johngros.NOSPAM@bigpond.net.au> wrote:
>> >xaxis and yaxis are both arrays and scalars.
>> >I was trying to access them as arrays if an indice was passed to the
>> >sub and as scalars if no indice was passed.
>>
>> I don't think you really understand Perl's data types, then ('perldoc
>> perldata'). Nothing can be both an array and a scalar. On the other
>> hand, a given variable might be a *reference* to either an array or a
>> scalar, and you can find out which by using ref().
>
>Sorry I was not clear I have the scalars $xaxis and $yaxis and the arrays
>@xaxis and @yaxis.
Oh, right. :) Sorry, ignore me then, that's fine (albeit usually a
little confusing IMHO).
--
Colin Watson [cjw44@flatline.org.uk]
Jam wants colonies. I am a jest on clowns.
------------------------------
Date: Sat, 13 Jan 2001 19:22:07 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Replacing the "\" character using s///.
Message-Id: <zV186.1516$nb4.87812@typhoon.austin.rr.com>
In article <93q86u$sdc$1@nnrp1.deja.com>, <shiloam@my-deja.com> wrote:
>I am using ActivePerl, or Perl for Win32. And I
>am creating an error log parser/analyzer I need
>to find file names with the "\" in them and
>replace it with the "/" character for opening
>purposes. I am trying to use the $variable=~s///
>syntax to do this and have had no luck.
>
>Does anyone know a way to search a string for
>this character and replace it?
What have you tried so far, and how doesn't it work (e.g. perl gives you
an error message and doesn't run the script, the script runs but doesn't
do what you expected it to etc.)
On my PC at home $file_name =~ s(\\)(/)g; seems to work as I would expect,
but you may want to read the perlop documentation (at least) to see what's
going on - in particular the 'Quote and Quote-like Operators' and 'Regexp
Quote-Like Operators' and 's/PATTERN/REPLACEMENT/egimosx' sections.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ |
GPG PGP Key 1024D/059913DA | Fingerprint 0570 71CD 6790 7C28 3D60
stok@colltech.com (CT - work) | 75D2 9EC4 C1C0 0599 13DA
------------------------------
Date: Sun, 14 Jan 2001 04:13:07 GMT
From: Joseph Maxwell <jaymax@sac.verio.net>
Subject: Syntactic symbol for continuing one line into another
Message-Id: <3A612829.70EE4A3E@sac.verio.net>
Hi Community,
Must be in the throes of a mental block, and do not have my ref. docs.
w/ me -
What is the syntactic symbol for continuing one line into another
Thanks
-- Joe --
------------------------------
Date: Sun, 14 Jan 2001 04:25:08 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Syntactic symbol for continuing one line into another
Message-Id: <x7hf32221n.fsf@home.sysarch.com>
>>>>> "JM" == Joseph Maxwell <jaymax@sac.verio.net> writes:
JM> Must be in the throes of a mental block, and do not have my ref. docs.
JM> w/ me -
if you can post to usenet you have access to the docs on the net. that
is no excuse. and if you can run perl, you most likely have access to
the docs there.
JM> What is the syntactic symbol for continuing one line into another
huh? what language are you programming in? where did you get the idea
that you need a symbol to continue a line of perl?
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 13 Jan 2001 23:36:17 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Syntactic symbol for continuing one line into another
Message-Id: <m31yu621j2.fsf@mumonkan.sunstarsys.com>
Joseph Maxwell <jaymax@sac.verio.net> writes:
> Hi Community,
>
> Must be in the throes of a mental block, and do not have my ref. docs.
> w/ me -
> What is the syntactic symbol for continuing one line into another
> Thanks
Dunno, have you tried
^J, <enter key> or <down arrow> ?
Perl doesn't have statement terminators, you know. If you want
to finish your thoughts on another line, usually you can just
stick the rest of it on the next line without any special
"syntactic symbol" (sort of like a familiar, natural language-
but w/o statement terminators, though :)
--
Joe Schaefer
------------------------------
Date: Sat, 13 Jan 2001 23:08:54 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Trouble with range operator and unitialized variable.
Message-Id: <3a60e003.734c$181@news.op.net>
[mailed and posted]
In article <TtZgOhNhJyr1gJgfIrZoqpfnqwzr@4ax.com>,
Jim Britain <jbritain@home.com> wrote:
>I've been messing with this for a long long time.
> foreach $line (@text){
>
> if ($line =~ /LAST ISSUE/ .. /TOP 20/){ # error here ( line 25)
> print $line;
> }
> }
You need to replace this with:
> if ($line =~ /LAST ISSUE/ .. $line =~ /TOP 20/){ # error here ( line 25)
You didn't say what should be matched against /TOP 20/, and the
default is to match $_.
$_ has no value, so you got the warning, which in this case did
indicate a real, serious bug in your program.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Sat, 13 Jan 2001 23:13:54 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Trouble with range operator and unitialized variable.
Message-Id: <x7puhr11vx.fsf@home.sysarch.com>
>>>>> "JB" == Jim Britain <jbritain@home.com> writes:
JB> #!/usr/bin/perl -w
JB> use strict;
JB> use Carp;
using -w and strict. excellent. we must be training some folks better here.
JB> sub readfile{
JB> my ( $file_name ) = @_ ;
JB> my( $text, @lines ) ;
JB> local( *FH ) ;
JB> open( FH, $file_name ) || carp "cant open '$file_name' $!" ;
JB> if ( wantarray ) {
JB> @lines = <FH> ;
JB> close( FH ) ;
JB> return @lines ;
JB> }
JB> local( $/ ) ;
JB> $text = <FH> ;
JB> close( FH ) ;
JB> return( $text ) ;
JB> }
glad to see that sub. here is my version which is shorter and faster:
sub read_file {
my( $file_name ) = shift ;
my( $buf ) ;
local( *FH ) ;
open( FH, $file_name ) || carp "can't open $file_name $!" ;
return <FH> if wantarray ;
read( FH, $buf, -s FH ) ;
return $buf ;
}
i had this code in the older slower version:
# local( $/ ) unless wantarray ;
# <FH>
the older way had no local vars and very short code. no file close is
needed in either case as it is closed when the handle goes out of scope.
JB> use vars qw(@text );
why the use vars? use my at the file level as well.
JB> my $line;
JB> foreach $line (@text){
here you could put my in the foreach line:
foreach my $line (@text){
JB> if ($line =~ /LAST ISSUE/ .. /TOP 20/){ # error here ( line 25)
well, that looks cute but perl doesn't apply more than one regex to a
value at a time. =~ binds only to /LAST ISSUE/ and who knows what the
.. is seeing on the left side (i won't even bother to analyze the actual
pasring of that).
if ( $line =~ /LAST ISSUE/ .. $line =~ /TOP 20/ ) {
is the right way to do that. .. needs 2 normal expressions to make its
range and in this case they both need to be fully bound regexes.
if you used $_ as the implict loop var, you could have done:
foreach ( @text ) {
if ( /LAST ISSUE/ .. /TOP 20/ ) {
which is what you probably have seen and you incorrectly crossed it with
=~ to make your code.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Sun, 14 Jan 2001 00:37:57 GMT
From: Jim Britain <jbritain@home.com>
Subject: Re: Trouble with range operator and unitialized variable.
Message-Id: <hu1gOv9IFXyLafKAeLo7V5wmRAGg@4ax.com>
On Sat, 13 Jan 2001 23:13:54 GMT, Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "JB" == Jim Britain <jbritain@home.com> writes:
>
> JB> my $line;
> JB> foreach $line (@text){
>
>here you could put my in the foreach line:
>
> foreach my $line (@text){
>
> JB> if ($line =~ /LAST ISSUE/ .. /TOP 20/){ # error here ( line 25)
>
>well, that looks cute but perl doesn't apply more than one regex to a
>value at a time. =~ binds only to /LAST ISSUE/ and who knows what the
>.. is seeing on the left side (i won't even bother to analyze the actual
>pasring of that).
>
> if ( $line =~ /LAST ISSUE/ .. $line =~ /TOP 20/ ) {
>
>is the right way to do that. .. needs 2 normal expressions to make its
>range and in this case they both need to be fully bound regexes.
>
>if you used $_ as the implict loop var, you could have done:
>
> foreach ( @text ) {
>
> if ( /LAST ISSUE/ .. /TOP 20/ ) {
>
>which is what you probably have seen and you incorrectly crossed it with
>=~ to make your code.
Yes, I can never remember the exact construct -- looking at it now, if
I want an explicit variable name (such as $line), I need to do the
assignment in the body itself (if for instance I need to duplicate the
contents of a control variable for other purposes..)
I go through the: while (<@text>)
foreach (<@text>)
do {} while (@text)
variations... (as well as $text as an input..)
That's the frustrating part ... all the possible variations,
multiplies the possibility for error -- I seem to ocassionally get
stuck with cases, where the implicit loop variable ( $_ ) contains
nothing... C is so much easier in this situation, but is no match for
the ease of text/stream manipulation/processing.
Thanks to all respondents for the help..
------------------------------
Date: Sun, 14 Jan 2001 05:11:49 GMT
From: Rob <a565a87@my-deja.com>
Subject: Win32 compile issue for 5.6.0
Message-Id: <93rcei$nko$1@nnrp1.deja.com>
I can't give up on building this Win32 perl distribution. There's a
first time for everything.
Using MSVC 6.0, nmmake.
I've actually had to manually add a few paths to the directory that
contains the build environment in order for everything specified by the
makefile to fall into place without throwing an error. I don't know
how to handle this following contingency though:
---
if not exist ..\lib\auto mkdir ..\lib\auto
cd ..\ext\Dynaloader
..\..\miniperl.exe -I..\..\lib DynaLoader_pm.PL
Can't open perl script "DynaLoader_pm.PL": No such file or
directory
NMAKE : fatal error U1077: '..\..\miniperl.exe' : return code '0x2'
Stop.
---
The build I'm working on, 5.6.0. I have a hunch that DynaLoader_pm.PL
is involved in this error somehow. I have never seen a file called
DynaLoader_pm.PL, though, in all my years. I ran a Google search on
that file and came up with a bunch of old usenet conversations and
other stuff, but no single file or script that could be
called "DynaLoader_pm.PL" seems to be out there. I don't know whether
the build is supposed to create this file.
Does anyone on the board have experience with this topic? Thank you
for any help that you can provide.
-Rob
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Sun, 14 Jan 2001 01:49:48 -0500
From: Nico F Zigouras <zigouras@mail.med.upenn.edu>
Subject: word combinations?
Message-Id: <Pine.OSF.4.10.10101140147580.14142-100000@dolphin.upenn.edu>
Can anyone give me or point me to Perl code on how to find all possible
combinations of a word? i.e. I have a word:
hello
I want to find all words like:
helol
ehllo
...
I know there are (number of letters)! possible combinations but how would
I find those exact words?
I am writing this in Perl but any code would be fine.
Thanks in advance.
------------------------------
Date: 14 Jan 2001 02:41:19 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: word combinations?
Message-Id: <m3wvbyzilc.fsf@mumonkan.sunstarsys.com>
Nico F Zigouras <zigouras@mail.med.upenn.edu> writes:
> Can anyone give me or point me to Perl code on how to find all possible
> combinations of a word? i.e. I have a word:
>
> hello
>
> I want to find all words like:
> helol
> ehllo
> ...
>
>
> I know there are (number of letters)! possible combinations but how would
> I find those exact words?
>
List::Permutor on CPAN appears to do what you want.
--
Joe Schaefer
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 58
*************************************