[13824] in Perl-Users-Digest
Perl-Users Digest, Issue: 1234 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 30 21:05:31 1999
Date: Sat, 30 Oct 1999 18:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <941331908-v9-i1234@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 30 Oct 1999 Volume: 9 Number: 1234
Today's topics:
Re: #!perl like <skilchen@swissonline.ch>
Re: Do you now an affordable Perl editor for Windows NT <samhobbs@mindspring.com>
Re: Help with regular expression (Tad McClellan)
How can I show a page-visitor his IP on my homepage ? (Gerhard Landauf)
Re: How can I show a page-visitor his IP on my homepage (Jed Parsons)
Re: How can I show a page-visitor his IP on my homepage (Abigail)
Re: How can I show a page-visitor his IP on my homepage <flavell@mail.cern.ch>
Re: How the heck does this regex match? <aqumsieh@matrox.com>
Re: It is always like this here? (Abigail)
Re: It is always like this here? <flavell@mail.cern.ch>
Need cgi script prodotes@my-deja.com
Newlines with nsgmls and sgmlspl (Jed Parsons)
Re: pass file handle <aqumsieh@matrox.com>
Re: Perl disallowed at ACM programming contests? (Abigail)
Re: perl double-split <aqumsieh@matrox.com>
Quick Question <revjack@radix.net>
Re: qxurl in sub <ltl@rgsun40.viasystems.com>
Re: qxurl in sub <skilchen@swissonline.ch>
Re: qxurl in sub <sun_tong@geocities.com>
Re: Searching within web pages for text (Eric Bohlman)
Re: Simple socket question (Alan Curry)
Re: Simple socket question <sconley@lightspeed.net>
Re: simplifying a script <uri@sysarch.com>
Telnet Question <jkuhnert@bellatlantic.net>
Re: Telnet Question <jkuhnert@bellatlantic.net>
use heredoc to assign var? <sun_tong@geocities.com>
Re: use heredoc to assign var? (Eric Bohlman)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 30 Oct 1999 20:22:31 GMT
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: #!perl like
Message-Id: <bsIS3.27708$m4.99749670@news.magma.ca>
* Tong * <sun_tong@geocities.com> wrote in message
news:381B2119.4397540E@geocities.com...
>
> #!/bin/sh -- # -*- perl -*-
> eval 'exec perl $0 -S ${1+"$@"}';
>
> and the result I got:
>
> Argument "" isn't numeric in add at (eval 1) line 1.
...
>
> My questions are:
>
> - How to make it works.
>
You forgot the "if $running_under_some_shell" which because its never
true will prevent that Perl executes the eval line.
Read the perlrun manpage where you will find the following example:
eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
if $running_under_some_shell;
> - what the -S mean? shouldn't it before $0?
>
According to the perlrun manpage -S tells Perl to search the script in
the path. Yes it should be before $0 and you probably want to use -wS
to enable some very useful warning messages.
------------------------------
Date: Sat, 30 Oct 1999 18:01:39 -0400
From: "Sam Hobbs" <samhobbs@mindspring.com>
Subject: Re: Do you now an affordable Perl editor for Windows NT
Message-Id: <7vfqe8$nl9$1@nntp4.atl.mindspring.net>
I'm using Multi-Edit and/or Notepad and/or Codewright. I have heard PFE
(Programmer's File Editor) highly recommended. There is also Vedit for
Windows or the old command line vedit (very compact and usable).
Sam
Don Sambrook <don@softwork-orange.com> wrote in message
news:381AD6C0.9929B132@softwork-orange.com...
> SitePad Pro
> http://www.modelworks.com
>
> Fantastic programming editor for may languages.
>
> Johnny 'Loopy' Ooi wrote:
>
> > What's wrong with Notepad? ;-)
> >
> > --
> > Johnny Ooi. Aliases: Loopy, Tuxedo Mask, Quote Master.....
> > E-Mail : jjyooi@dcs.qmw.ac.uk or jjyooi@yahoo.com
> > WWW : http://www.dcs.qmw.ac.uk/~jjyooi/
> > ICQ No : 6155774
> >
> > "Stay sane guys!"
> >
> > ===============================================================
>
------------------------------
Date: Sat, 30 Oct 1999 13:12:37 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Help with regular expression
Message-Id: <5u8fv7.ev2.ln@magna.metronet.com>
webmaster@vaticanart.com wrote:
: I have recently developed an application for a website that allows
: members to email each other using member id's instead of their real
: email address. Basically jon@doe.com would be member-5@my_domain.com
: Thus far this has worked great, until I discovered a flaw in the
: process: if the member replies to an email that was sent, the member's
: real email address will be in the quoted reply field,
: I thought the simple solution would be to take the @body_msg and do a
: substitution of the real email address for the member email address
: throughout the entire body.....but... if a member actually WANTED to
: send their real email address along to another member...yup, it would
: get replaced. Then I tried the following reg exp:
: $z =~ s/(To:.*)$from_email/$1$from/s;
: But this does not seem to work correctly.
It replaces the _last_ occurence, because it is doing a greedy match.
: I believe the problem is
: because that email can be in text or html:
: To: jon@doe.com -could really be- <b>To:</b> <a
: href="mailto:jon@doe.com">jon@doe.com</a> etc...,etc..,etc..
When there is more than one, you can see that the last one gets matched.
: Does anyone have a good solution for this?
Not really.
A non-greedy match would match the first one.
You don't want to match the first or last one.
You want to match some particular one.
So you need something else to "key on" to tell you which
one should be replaced.
: Do I have to conceive of
: every possible To: format and then accomodate this in the reg exp ?
No, but you may have to accomodate every possible quoting format :-(
In any case, you should make the most pathologic test case that
you can imagine, and try stuff.
The example I made below has the search string in 5 places.
----------------------------------
#!/usr/bin/perl -w
use strict;
my $msg = <<'ENDMAIL';
From: dapres@whitehouse.gov
To: jon@doe.com
Subject: is jon@doe.com your email address?
jon@doe.com wrote:
: Hi Bill,
:
: Send me email at jon@doe.com
:
: Bye, Jon
Hi Jon,
Here is the email that you asked me to send
to check out your new jon@doe.com email address.
ENDMAIL
my $real_email = 'jon@doe.com';
my $my_email = 'member-5@my_domain.com';
$msg =~ s/(To:.*)$real_email/$1$my_email/s;
#$msg =~ s/(To:.*?)$real_email/$1$my_email/s; # non-greedy
print $msg;
----------------------------------
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 30 Oct 1999 21:43:51 GMT
From: landauf@teleweb.at (Gerhard Landauf)
Subject: How can I show a page-visitor his IP on my homepage ?
Message-Id: <38206753.48099682@news.telekabel.at>
Hello !
Obviously this problem cannot be managed in (pure) Java.
So, can anyone of you experts tell me how thet can be done using
Perl/CGI ?
The specific problem is:
I'd like to show a visitor on my homepage from which IP (host address)
he is logging in. Don't need any routine for saving this information or
anything like that, just showing the IP to the visitor *himself*.
E.g. on my homepage a visitor then should read:
"... you are connecting from 245.0.10.45" or anything like that.
Does anyone of you know of a quick recipe for my problem and can also
tell me, how I could integrate the data from that CGI file in the HTML
code of the homepage ?
Thank you so much !
Greetings from Vienna,
Gerhard
Gerhard Landauf (Vienna/AUSTRIA) mailto:landauf@inode.at
--
phone (GSM): +43676 4139765
RSA/2048 ID: 6D094CC9 - FP: 2670 3D21 61B7 96C9 B57C 3AA8 3827 0F24
DSS/4096 ID: B3B51660 - FP: 7065 2B70 7927 5A9D 8282 8197 6327 235D B3B5 1660
------------------------------
Date: 30 Oct 1999 22:35:33 GMT
From: jed@socrates.berkeley.edu (Jed Parsons)
Subject: Re: How can I show a page-visitor his IP on my homepage ?
Message-Id: <7vfrrl$oek$1@agate.berkeley.edu>
You can use the environment variable REMOTE_ADDR. In perl, get it with
$ENV{'REMOTE_ADDR'}
- J
--
Jed Parsons mailto:jed@socrates.berkeley.edu
http://socrates.berkeley.edu/~jed/
----------------------------------------------------------
grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and
------------------------------
Date: 30 Oct 1999 19:01:21 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: How can I show a page-visitor his IP on my homepage ?
Message-Id: <slrn81n1lf.66b.abigail@alexandra.delanet.com>
Gerhard Landauf (landauf@teleweb.at) wrote on MMCCLI September MCMXCIII
in <URL:news:38206753.48099682@news.telekabel.at>:
;;
;; Obviously this problem cannot be managed in (pure) Java.
Eh? How so? Java's inability to print?
;; So, can anyone of you experts tell me how thet can be done using
;; Perl/CGI ?
;;
;; The specific problem is:
;;
;; I'd like to show a visitor on my homepage from which IP (host address)
;; he is logging in. Don't need any routine for saving this information or
;; anything like that, just showing the IP to the visitor *himself*.
Ah, yes, very useful information. As if the user doesn't already know
that himself.
<offtopic>
You cannot do that. All you can find out is the IP address of the
last proxy the request came through.
To find out the latter, check the CGI specification - which is not
the topic of this newsgroup.
</offtopic>
;; E.g. on my homepage a visitor then should read:
;;
;; "... you are connecting from 245.0.10.45" or anything like that.
;;
;; Does anyone of you know of a quick recipe for my problem and can also
;; tell me, how I could integrate the data from that CGI file in the HTML
;; code of the homepage ?
print "<p>245.0.10.45";
For more questions, go to an HTML newsgroup - HTML is not the topic of
this newsgroup.
Abigail
--
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Sun, 31 Oct 1999 02:25:20 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: How can I show a page-visitor his IP on my homepage ?
Message-Id: <Pine.HPP.3.95a.991031021747.14942D-100000@hpplus01.cern.ch>
On Sat, 30 Oct 1999, Gerhard Landauf wrote:
> Obviously this problem cannot be managed in (pure) Java.
Is that so? I'd have thought that Java (or indeed anything else running
on the client platform) was in a far better position to know the IP
address of the platform (mine's 127.0.0.1 by the way) than some remote
CGI process that can only reliably see the IP address of the last proxy
in the chain.
(Hint: the first will be webwasher, the second will by our group's
proxy cache, the third will be the campus's mandatory WWW cache, and
then maybe the UK academic national cache, and any other caches that it
chooses to consult).
> I'd like to show a visitor on my homepage from which IP (host address)
> he is logging in.
As I say, it will be 127.0.0.1 in my case, the address that I use for
accessing the Webwasher proxy. Until you have explained your
understanding of this issue, it's impossible to give you a meaningful
answer to your naive question.
> Greetings from Vienna,
Servus Wien, hab' die Ehere...
------------------------------
Date: Sat, 30 Oct 1999 16:43:38 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: How the heck does this regex match?
Message-Id: <x3yk8o4tw92.fsf@tigre.matrox.com>
"Douglas Garstang" <dgarstan@nsw.bigpond.net.au> writes:
> #!/usr/bin/perl
>
> $a = "[ sdt_shel ]";
> $b = "dtlogin";
>
> if ( $b =~ $a ) {
> print "YES\n";
> }
>
> .... That returns true!
> *is blown away*
>
> How can this be true?
>
> (something to do with the []'s getting in the way?)
Yes. If you read the docs properly, you would've known that the square
brackets in regexps define a character class. So, you're regexp will
match any string that has any of the following characters:
s d t h e l _
and a space.
And, another pice of advice:
Judging from a few posts I have seen from you over the past couple of
days, you seem to post at the first problem you encounter, before
checking the docs and FAQs.
Please don't do that as it may cause some people to ignore further
posts from you. Usenet should be your *LAST* resort for help.
HTH,
--Ala
------------------------------
Date: 30 Oct 1999 18:38:58 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: It is always like this here?
Message-Id: <slrn81n0bd.66b.abigail@alexandra.delanet.com>
David Foster (dfoster@panix.com) wrote on MMCCLI September MCMXCIII in
<URL:news:7vfbnq$cs3$1@panix.com>:
()
() No, you've missed the point. Newbie toasting doesn't mean new to the
() newsgroup, it means new to perl. And those people definitely *do* get
() toasted in here. If you've been using perl for less than a year, it's
() unlikely that you are going to have a perl question that isn't covered
() *someplace* in the docs. Of course, part of using the language is
() learning how to use that documentation effectively.
Noone gets flamed for a question whose answer is in the docs, but it
requires some time to find it. People get flamed for not doing the
most trivial search. ``What does the function foo do?''. Well, duh,
where do you think that's documented?
() Now it's reasonable to suggest that although newbies *do* need a place
() to discuss perl, perhaps clp.misc isn't that place. But insisting on
() this just brings you to the point where clp.misc is now. There's a few
() reasons, I'd suggest, why clp has this problem more than most.
()
() a) The .cgi group got buried. I mean, c'mon, comp.infosystems??? And
() the leading use of perl among new users is almost definitely cgi.
() Trying to keep .cgi questions out of here may be fighting the good
() fight, but it's a losing battle. If I were looking over Usenet for the
() first time, I'd probably assume this is the place to ask cgi questions
() (although, admittedly, I wouldn't ask them without reading the group
() first).
How hard can it be to search for '^comp.*.cgi'? Rather trivial, don't
you think? You can even do that by hand. The fact people keep asking
off-topic CGI posting in this group isn't a reason to allow them; it's
a reason to kick them even harder.
() b) .misc pretty much implies 'anything goes'. It's real tough to keep
() a .misc group on topic. comp.lang.perl.regex or clp.ipc probably
() wouldn't have this problem.
That of course implies the inability to grasp the "comp.lang.perl" part.
It's "comp.lang.perl.misc", not "misc". Anything goes - that might be
true in misc.misc, but even then they might point you to someother place.
And lots of people do seem to grasp the "comp.lang.perl"; we seldomly
get questions here on how to change the oil in your car, because ".misc"
is for "anything goes".
() c) perl has, well, a *different* way of doing things. When first
() learning it, I remember reading the same paragraph in the docs over and
() over, just knowing that it was answering my question but not being able
() to grok it.
We don't get many questions of people quoting the docs and asking to
explain it. Too bad, because that would be a good question, perhaps
eventually leading to a patch in the documentation.
() Now all this doesn't mean the flamers are wrong. Far from it, the group
() has a charter and tradition and that should be respected. But there's
() an inexhaustible supply of new users out there, and a certain
() percentage of them are going to blindly post to the first place they
() find; flaming doesn't help one bit, because if they read the group
() first they wouldn't post anyway.
We know that, and if you think "flamers" think it will keep that off-topic
poster away, you're wrong. But it will keep *others* away. If noone
complains about people asking off-topic questions, or of people not
reading the docs, then it will become `acceptable behaviour', and we
will even get *more* of those questions.
It's like trying to fix a leak. You aren't saying "oh, why bother, the
floor is already wet", are you?
() So you're in the situation where new perl users need a place to discuss
() perl, and the most obvious place to do it is trying to keep them out.
() Most new users will respect this, but there's always going to be a
() percentage that won't. There's really no good answer to this one.
You are totally wrong. 100% completely wrong. New perl users are welcome
here.
Off course, we have gone through all this over and over and over again.
It's all in deja news. Perhaps we need a perlfaq0, that discusses these
issues.
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Sun, 31 Oct 1999 02:16:09 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: It is always like this here?
Message-Id: <Pine.HPP.3.95a.991031021152.14942C-100000@hpplus01.cern.ch>
On 30 Oct 1999, Abigail wrote:
[much carefully-argued good sense omitted]
> You are totally wrong. 100% completely wrong. New perl users are welcome
> here.
>
> Off course, we have gone through all this over and over and over again.
> It's all in deja news. Perhaps we need a perlfaq0, that discusses these
> issues.
Yes, we probably do. The people who need to read it won't read it, of
course, while the people who don't need to read it will learn it by
heart; but at least the hon. Usenauts will have something concrete to
point to when the argument comes up for the 1,234th time.
--
World Egg Day "got off to a cracking start" -official.
------------------------------
Date: Sat, 30 Oct 1999 23:07:24 GMT
From: prodotes@my-deja.com
Subject: Need cgi script
Message-Id: <7vftnb$7ql$1@nnrp1.deja.com>
Hello...
I badly need and cgi script that sends an web form to an file on an
linux server.
Could anyone please help me.
Thanks.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 30 Oct 1999 20:39:27 GMT
From: jed@socrates.berkeley.edu (Jed Parsons)
Subject: Newlines with nsgmls and sgmlspl
Message-Id: <7vfl1v$nit$1@agate.berkeley.edu>
Greetings -
I'm trying to use the sgmlspl to filter output from nsgmls. nsgmls ends
up beginning all its output records (lines) with \012 (newline) and
concluding them with \n (newline). The nsgmls documentation says that
``most applications will need to ignore \012 and translate \n into
newline.'' sgmlspl does not do this by default, and consequently every
other line of output is a blank line. Can anyone tell me the best way to
fix this?
FWIW, I'm using the nsgmls and sgmlspl together like this
nsgmls -wxml my.dtd | sgmlspl my-rules.pl > my-output.format
(And (for the sake of completeness) I've set the environment variables
SP_ENCODING, SP_CHARSET_FIXED, and SGML_CATALOG_FILES so nsgmls can deal
with xml)
Many thanks for any suggestions,
Jed
--
Jed Parsons (Yet another Plautus hack?) mailto:jed@socrates.berkeley.edu
http://socrates.berkeley.edu/~jed/
( ``We supermonsters bruise easily, you know.'' -- Supergrover )
------------------------------
Date: Sat, 30 Oct 1999 15:55:10 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: pass file handle
Message-Id: <x3yln8ktyht.fsf@tigre.matrox.com>
nobody <nobody@nowhere.com> writes:
> I wish to open a file in one subroutine and write to it from another. I
> assigned the file handle to a scalar and returned it to the calling
> subroutine. It is using it as the first argument in printf, but all that
> results is the the name of the original file handle gets printed.
>
> What's wrong with this picture?
>
> open(HFILE, "temp.txt");
> $hfile = HFILE;
You can't assign a filehandle to a scalar. Here you are actually
assigning the string "HFILE" to the variable $hfile.
You should assign a reference to the glob into your variable:
$hfile = \*HFILE;
Your solution is in the FAQ (perlfaq5):
How can I make a filehandle local to a subroutine? How do I
pass filehandles between subroutines? How do I make an
array of filehandles?
I would also advise you to start using the IO::File module. Using it,
you can create lexical file handles:
use IO::File;
my $fh = new IO::File $file;
die $! unless defined $fh;
subroutine($fh);
HTH,
--Ala
------------------------------
Date: 30 Oct 1999 19:07:16 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Perl disallowed at ACM programming contests?
Message-Id: <slrn81n20i.66b.abigail@alexandra.delanet.com>
Mark W. Schumann (catfood@apk.net) wrote on MMCCLI September MCMXCIII in
<URL:news:7vfdda$mca@junior.apk.net>:
,, In article <m2c2v7.gf8.ln@magna.metronet.com>,
,, Tad McClellan <tadmc@metronet.com> wrote:
,, >These days, Keith is a sysadmin at Yahoo! Inc., and is
,, >wondering what to do with the copy of Visual C++ that was his
,, >prize.
,,
,, This is just killing me. ACM is now handing out Visual C++ as a
,, "prize"?
Considering this was a contest at a universtity, it wasn't organized
by the ACM; even though it beared the letters ACM in the name.
It's just something the local organizers came up with as a prize.
Abigail
--
perl -wleprint -eqq-@{[ -eqw\\- -eJust -eanother -ePerl -eHacker -e\\-]}-
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Sat, 30 Oct 1999 16:57:23 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: perl double-split
Message-Id: <x3yiu3otvmd.fsf@tigre.matrox.com>
[rearranged jeopardy-style post]
"Randy Smith" <randys@NOSPAMamigo.net> writes:
> Daniel Heiserer <daniel.heiserer@bmw.de> wrote in message
> news:3819A159.55C6D670@bmw.de...
> > Hi,
> >
> > assume I read a file into a variable in perl:
> >
> > undef $/;
> > $data=<>;
> >
> > I know how I can split the $data (according the lines) into field @Tmp
> > using
> > @Tmp=split('\n',$data);
You can save yourself the hassle. Don't undef $/, and just do:
chomp(@Tmp = <>);
> > But assume I read a table, or comma separated file:
> >
> > #-----------file------------
> > me,you,karl,mary,joan
> > 23,3455,34543,2343,34
> > #-----------file------------
> >
> > and I want to split it into a file using TWO separators:
> > "\n" for the "lines" and "," for the columns and the resultant
> > should be a double-indexed field @Tmp2:
you mean a 2d array? Did you read the following docs:
perllol
perlref
perldsc
??
> > @Tmp2=howtosplit_doubles('\n',',',$data);
> >
> > So $Tmp2[1][1]=3455
> >
> > How could that be done in a that simple and similar way??????
> >
> > I know perl can do that easily. ;-)
> >
> > Any hints?
Read the above docs, and see below.
> If at first you don't succeed, cheat.
What an advice!
> First, $data = <FH> only reads one line.You can read the entire file, line
Not if you undef $/, as the original poster did.
> by line, by doing @data = <FH>; Now each line of the file is an element in
> @data.
I suggest you chomp() @data now, but that's only my preference.
> Now you can do something like @stuff = split (",", $data[0]); to get the
> data from a line.
The use of a string as the first argument to split() is confusing. By
definition, the first argument to split() is a regular expression. I
prefer to make that explicit:
@stuff = split /,/, $data[0];
> EX:
> # you can, of course, do this from STDIN just replace
> # FH with STDIN and lose the open and close.
> open (FH, "myFile");
check the results of your open(), even if it's merely an example:
open FH, 'myFile' or die $!;
> my @data = <FH>;
chomp(my @data = <FH>);
> close FH;
or warn $!;
> foreach my $line (@data)
> {
> my @line_stuff = split (",", $line);
> # do stuff with the data here
> }
>
> You can get the double array thing by replacing the foreach loop with this
> for (my $i; $i < scalar @data; $i++)
> {
In the very first iteration of your for() loop, $i will be undefined
because you forgot to set it to zero.
> @data[$i] = [split (",", @data[$i])];
you probably mean:
$data[$i] = [split /,/ => $data[$i]];
> }
>
> Now you can access things as $data[0][43374].
aha.
> Have fun,
Where's the fun with fixing your broken code? Please test before you
post. Your little program contains multiple errors, and could easily
mislead the original poster.
Now, I would do it this way:
my @data;
while (<>) { # assuming input comes from here
push @data => [split /,/];
}
That's it! Now you can access your elements as you wanted:
Ex:
$data[1][1] will be 3455.
HTH,
--Ala
------------------------------
Date: 31 Oct 1999 00:49:29 GMT
From: revjack <revjack@radix.net>
Subject: Quick Question
Message-Id: <7vg3mp$5qd$2@news1.Radix.Net>
Keywords: Hexapodia as the key insight
Has anybody ever thought that maybe perl isn't real?
I mean, like, maybe it's some sort of weird media
invention, and not, in fact, real?
I have a friend who was wondering about this.
--
hey/don't look now/but there goes god/in sexy pants/with a sausage
dog/and he can't stand beelzebub/coz he looks so good in black
revjack@radix.net
------------------------------
Date: 30 Oct 1999 19:09:20 GMT
From: lt lindley <ltl@rgsun40.viasystems.com>
Subject: Re: qxurl in sub
Message-Id: <7vffp0$c9j$1@rguxd.viasystems.com>
* Tong * <sun_tong@geocities.com> wrote:
:>Hi,
:>I tested and proved the following code is working:
:>- - >8 - -
:> #!/usr/bin/perl -n00
:> # qxurl - tchrist@perl.com
:> print "$2\n" while m{
:> < \s*
:> A \s+ HREF \s* = \s* (["']) (.*?) \1
:> \s* >
:> }gsix;
:>- - >8 - -
:>But why it stops working after I put it into sub?
:>(The command is the same: "perl -n00 qxurl.pl <urlh.htm")
:>- - >8 - -
:>#!/usr/bin/perl -n00
Figure out what "-n00" does. See `perldoc perlrun`
But you are probably better off not using it until you
understand a lot more of Perl first. Those command line
switches are shortcuts. You need to learn the long way
first.
:>BEGIN { $/ = '' }
:>sub sub_url_qx{
:> print "$2\n" while m{
:> < \s*
:> A \s+ HREF \s* = \s* (["']) (.*?) \1
:> \s* >
:> }gsix;
:>}
:>&sub_url_qx;
:>exit;
How many times will this loop now?
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: Sat, 30 Oct 1999 20:00:18 GMT
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: qxurl in sub
Message-Id: <m7IS3.27704$m4.99738296@news.magma.ca>
* Tong * <sun_tong@geocities.com> wrote in message
news:381B2FDB.C68C1F43@geocities.com...
>
> I tested and proved the following code is working:
>
Then you did not test it very well. Anchor Tags can have many more
attributes than a simple HREF.
The most common example is a target attribute as in
<a href="maintoc.html#GettingStarted" target="TOC">
from ActiveState's Perl documentation.
> But why it stops working after I put it into sub?
> (The command is the same: "perl -n00 qxurl.pl <urlh.htm")
If your remark in parens is true, then i don't understand why it
should not work exactly the same, as the first example.
>
> - - >8 - -
> #!/usr/bin/perl -n00
> BEGIN { $/ = '' }
>
But this line lets me assume that you were playing around with
different command lines. The -n flag is really essential for this to
work. Without it you have to provide your own while (<>) {...} loop to
read the input, or you need to add "$_ = <>;" if you undef the input
record separator.
> sub sub_url_qx{
>
> print "$2\n" while m{
> < \s*
> A \s+ HREF \s* = \s* (["']) (.*?) \1
> \s* >
> }gsix;
>
> }
>
# if you don't call the script with the -n flag then you have to add
while (<>) {
&sub_url_qx;
}
> exit;
>
> And how should I fix it? thanks
>
Don't try to fix it. Just throw it away and use Gisle Aas's
HTML::LinkExtor instead or wait until somebody comes up with a true
HTML parser.
------------------------------
Date: Sat, 30 Oct 1999 17:18:46 -0400
From: * Tong * <sun_tong@geocities.com>
Subject: Re: qxurl in sub
Message-Id: <381B60B6.4B3B2BE7@geocities.com>
Thank you Samuel, your explanation is very clear, to both of my
questions. I understand them both now. thanks again! and Have a good
day!
-- Tong
Anti-spam: remove underscore to reply.
Welcome to my homepage http://maxpages.com/suntong
- All free contribution & collection
- freeware & music from the heavens
------------------------------
Date: 31 Oct 1999 00:29:26 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Searching within web pages for text
Message-Id: <7vg2h6$god$1@nntp1.atl.mindspring.net>
Jonathan Stowe (gellyfish@gellyfish.com) wrote:
: sub text
: {
: my ($self, $text) = @_;
:
: $self->{FOUND} += $text =~ /$self->{SEARCH}/s;
: }
This makes the unsupportable assumption that any run of text in the
document will result in a single call to text() with the entire run
passed as an argument. This behavior is not guaranteed; it's possible
for a run of text to be split between two calls, and you're code will
miss a matching string that spans two "adjacent" calls.
------------------------------
Date: Sat, 30 Oct 1999 19:24:22 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: Simple socket question
Message-Id: <GBHS3.10508$23.595263@typ11.nn.bcandid.com>
In article <381AA1E4.D5CBC795@lightspeed.net>,
Sean Conley <seanc@jps.net> wrote:
>Okay, here's an easy one. I am writing a telnet client, actually a MUD
>client, in perl. How do I tell if the remote side has closed the
>socket?
When a socket it closed remotely, you will read an EOF.
> $data = $stdin->getline();
and getline() will return undef to show you the EOF.
If you happen to write to a socket that's been closed remotely, you will get
a SIGPIPE and, if that doesn't kill you, a write error with $! set to EPIPE.
--
Alan Curry |Declaration of | _../\. ./\.._ ____. ____.
pacman@cqc.com|bigotries (should| [ | | ] / _> / _>
--------------+save some time): | \__/ \__/ \___: \___:
Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman
------------------------------
Date: Sat, 30 Oct 1999 13:07:13 -0700
From: Sean Conley <sconley@lightspeed.net>
Subject: Re: Simple socket question
Message-Id: <381B4FF1.C3D40E6@lightspeed.net>
This is what I originally thought. However, when I check to see if
$data is EOF it picks it up everywhere. So, I try to check if $data is
undef, this never returns true. So, where do I break out of my little
loop?
Thanks in advance,
Sean
Alan Curry wrote:
>
> In article <381AA1E4.D5CBC795@lightspeed.net>,
> Sean Conley <seanc@jps.net> wrote:
> >Okay, here's an easy one. I am writing a telnet client, actually a MUD
> >client, in perl. How do I tell if the remote side has closed the
> >socket?
>
> When a socket it closed remotely, you will read an EOF.
>
> > $data = $stdin->getline();
>
> and getline() will return undef to show you the EOF.
>
> If you happen to write to a socket that's been closed remotely, you will get
> a SIGPIPE and, if that doesn't kill you, a write error with $! set to EPIPE.
> --
> Alan Curry |Declaration of | _../\. ./\.._ ____. ____.
> pacman@cqc.com|bigotries (should| [ | | ] / _> / _>
> --------------+save some time): | \__/ \__/ \___: \___:
> Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman
------------------------------
Date: 30 Oct 1999 16:42:22 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: simplifying a script
Message-Id: <x7zox0bmxd.fsf@home.sysarch.com>
>>>>> "WvdB" == Walter van den Berg <vandenbNOSPAM@cistron.nl> writes:
WvdB> All of you are saying something likewise, but I am not yet put
WvdB> off by the book. I like Perl, everything I want to do can be
WvdB> done with Perl, and the book showed me that. I trust you all
WvdB> when you say I'm not learning good code, but I do not yet
WvdB> dislike Perl because of the book.
the problem is you don't know enough perl to recognize where the book is
wrong! so it can't put you off, as you are a perl newbie. though i am
surprised you can stomach its condescending tone. it purports to be a
reference too but it has many errors in just that alone. here's a nice
one:
in appendix A (the great perl reference, HA!) it mentions
eof, but only in the form eof( HANDLE ). there are 2 other major
forms eof and eof() of which the latter is extremely valuable as
it looks at the pseudo handle of <>.
you wouldn't knwo that was missing nor how important the eof() form
is. that is why it is such an evil book. it purports to be complete and
clear but it is not. learning perl aims to be a tutorial and does not
claim to be a complete reference. so it is much more honest than
dummies.
i think they should change the title of the series:
s/for/by/g;
WvdB> I've learned a lot about various things just by reading
WvdB> newsgroups, you're absolutely right, but man, a few hundred
WvdB> postings a day... Ah well.
just search for subjects which seem interesting to you. maybe look at
some of the newbie posts to see what problems others have. you can
filter by subject fairly easily by eye or kill file.
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: Sat, 30 Oct 1999 21:46:30 GMT
From: "G. Jesse Kuhnert" <jkuhnert@bellatlantic.net>
Subject: Telnet Question
Message-Id: <381B66BB.A8404EBE@bellatlantic.net>
I'm not suer if this is the right place to post this question, but here
it goes:
I am trying to invoke a simple script to login to a telnet server and
change a users password based on input data through an html form.
..After doing some research on the man-pages, as well as the Perl FAQ I
have been unable to find a solution to my particular problem. My server
will not allow me to install any extra modules, like Net::Telnet,
therefore I have to do some manual scripting. I have read some of the
open2() documentation, but my current grasp of Perl is not quite up to
par I think for implementing this code successfully. Does anyone know a
solution to this, or a URL/FAQ/anything? Any help would be greatly
appreciated.
G. Jesse Kuhnert
jkuhnert@bellatlantic.net
Commands needed to send to Telnet:
telnet <host>
<username>
<password>
passwd
<oldpasswd>
<newpasswd>
<newpasswd>
exit
------------------------------
Date: Sat, 30 Oct 1999 23:49:33 GMT
From: "G. Jesse Kuhnert" <jkuhnert@bellatlantic.net>
Subject: Re: Telnet Question
Message-Id: <381B8391.4A98EAED@bellatlantic.net>
Ughhh...I/o sockets, telnet host language, etc....I think I'm in over my
head on this one. Is it possible for me to use the Net::Telnet module
without installing it on the server(which I'm not allowed to do...) by
using the 'require telnet.pm' command at the top of my script? This
would help me out tremendously..And if I can do this, how would I start
a new telnet object? The documentation specifies stating:
new Net::Telnet ------>>>>>>>etc....
Would I still be able to use this style? Or would I simply say:
new Telnet>>whatver else....
I know you guys hate newbie questions, but please feel pity for a humble
little Perl beginner. I have read the FAQ's/man-pages/etc....It's not
like I haven't tried to solve the problem myself. I'm just not
experienced enough in Perl to write my own socket connection to a remote
Telnet host yet...
G. Jesse Kuhnert
jkuhnert@bellatlantic.net
"G. Jesse Kuhnert" wrote:
>
> I'm not suer if this is the right place to post this question, but here
> it goes:
>
> I am trying to invoke a simple script to login to a telnet server and
> change a users password based on input data through an html form.
> ..After doing some research on the man-pages, as well as the Perl FAQ I
> have been unable to find a solution to my particular problem. My server
> will not allow me to install any extra modules, like Net::Telnet,
> therefore I have to do some manual scripting. I have read some of the
> open2() documentation, but my current grasp of Perl is not quite up to
> par I think for implementing this code successfully. Does anyone know a
> solution to this, or a URL/FAQ/anything? Any help would be greatly
> appreciated.
>
> G. Jesse Kuhnert
> jkuhnert@bellatlantic.net
>
> Commands needed to send to Telnet:
>
> telnet <host>
> <username>
> <password>
> passwd
> <oldpasswd>
> <newpasswd>
> <newpasswd>
> exit
------------------------------
Date: Sat, 30 Oct 1999 19:10:14 -0400
From: * Tong * <sun_tong@geocities.com>
Subject: use heredoc to assign var?
Message-Id: <381B7AD6.815E2F67@geocities.com>
Hi,
Can I use heredoc to assign a bunck of txt to a varible?
Like,
$var=<< "EOF"
bla bla bla
EOF
how can I do that? thanks
-- Tong
Anti-spam: remove underscore to reply.
Welcome to my homepage http://maxpages.com/suntong
- All free contribution & collection
- freeware & music from the heavens
------------------------------
Date: 31 Oct 1999 00:43:44 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: use heredoc to assign var?
Message-Id: <7vg3c0$god$2@nntp1.atl.mindspring.net>
* Tong * (sun_tong@geocities.com) wrote:
: Can I use heredoc to assign a bunck of txt to a varible?
Yes.
:
: Like,
:
: $var=<< "EOF"
: bla bla bla
: EOF
:
: how can I do that? thanks
You just need to make two changes:
1) Drop the space before "EOF"
2) Put a semicolon after "EOF"
------------------------------
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 V9 Issue 1234
**************************************