[11777] in Perl-Users-Digest
Perl-Users Digest, Issue: 5377 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 14 00:07:33 1999
Date: Tue, 13 Apr 99 21:00:18 -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 Tue, 13 Apr 1999 Volume: 8 Number: 5377
Today's topics:
Re: CGI embedded in html (Milko Kretschmann)
Re: Convert two newlines to \n<p> <mickv@home.com>
FAQ 1.1: What is Perl? <perlfaq-suggestions@perl.com>
File::Find::name question. bhaskaracharya@my-dejanews.com
Re: How to write a format to an array instead of a file <rick.delaney@home.com>
Re: MLDBM <jdf@pobox.com>
Re: Novice needs learning suggestions <mickv@home.com>
Re: pattern matching <jbostwic@valinor.cargill.com>
Peeking/Seeking STDIN by Inheriting From FileHandle <dwc3q@mamba.cs.Virginia.EDU>
Re: Perl rmdir (Abigail)
Re: Printing a file <a_branson_1998@yahoo.com>
Re: Printing a file <a_branson_1998@yahoo.com>
Re: Printing a file <rick.delaney@home.com>
Re: Problem with my & local declarations (Tad McClellan)
Re: Q: Convert two newlines to \n<p> (Tim Herzog)
Re: referring to form generated variables (Tim Herzog)
Re: referring to form generated variables (Ronald J Kimball)
Re: regex - camel and llama cannot help (Ronald J Kimball)
simple perl variable assigning qu (Nina Hung)
Re: simple perl variable assigning qu <tchrist@mox.perl.com>
Re: String matching (Ronald J Kimball)
Re: stumped on regex - onto array (Ronald J Kimball)
Re: Use of LWP Modules (Martin Kuchlmayr)
Re: Weird behavior with connect() and IP numbers from @ (Ronald J Kimball)
Re: What is the end of file character for Mac (Ronald J Kimball)
win32 api UserDel problem doug_allan@my-dejanews.com
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 13 Apr 1999 11:47:29 GMT
From: mkretsch@infotech.nl (Milko Kretschmann)
Subject: Re: CGI embedded in html
Message-Id: <7evasj$3fk$1@beta.infotech.nl>
In article <linberg-1204991049510001@ltl1.literacy.upenn.edu>, linberg@literacy.upenn.edu (Steve Linberg) wrote:
>In article <7esmcj$eq$1@beta.infotech.nl>, mkretsch@infotech.nl (Milko
>Kretschmann) wrote:
>
>> Is it possible to 'embed' a cgi-script in a html-page.
>
>No.
>
>> I know this is for instance possible via an image, but then
>> the script has to return an image. I want to have it return text.
>
>The "gif trick" doesn't have to return an image. It can be a shell or
>Perl script that can do other things.
>
I tried this but it doesn't work. Can you give a short example how it should
work ?
(I'm sorry for having posted this question here, however I tried the
cgi-related newsgroup as you recommended, but my message doesn't seem to be
able to reach it (???)).
Sincerely,
Milko Kretschmann.
------------------------------
Date: Wed, 14 Apr 1999 02:23:27 GMT
From: "Michael Villeneuve" <mickv@home.com>
Subject: Re: Convert two newlines to \n<p>
Message-Id: <z_SQ2.4836$Ay2.437465@news1.rdc1.on.wave.home.com>
Hi Mike,
Here's what you will probably want. Each newline is actually a "record"
delimiter. You will not get two consecutive newline (\n) characters in a
single record.
How about changing your statement to:
while (<TXTFILE>){
s/^\n$/<p>/g;
print;
}
(I'm not sure what the
undef $/;
does. )
If I'm way off base, don't flame me. I'm just trying to give my two cents.
Cheers,
Mike
Mike Collins wrote in message <3713f2cf.15977653@news.netway.com>...
>Trying to match two newlines to produce one newline and a paragraph
>tag <p>.
>
>The code shown and many, many variations all fail.
>
>undef $/;
>while (<TXTFILE>){
> s/\n\n/\n<p>/sg; #Not even close!
> print;
>}
>
------------------------------
Date: 13 Apr 1999 21:21:14 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 1.1: What is Perl?
Message-Id: <371409aa@cs.colorado.edu>
(This excerpt from perlfaq1 - General Questions About Perl
($Revision: 1.21 $, $Date: 1999/01/26 09:55:05 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq1.html
if your negligent system adminstrator has been remiss in his duties.)
What is Perl?
Perl is a high-level programming language with an eclectic heritage
written by Larry Wall and a cast of thousands. It derives from the
ubiquitous C programming language and to a lesser extent from sed,
awk, the Unix shell, and at least a dozen other tools and
languages. Perl's process, file, and text manipulation facilities
make it particularly well-suited for tasks involving quick
prototyping, system utilities, software tools, system management
tasks, database access, graphical programming, networking, and
world wide web programming. These strengths make it especially
popular with system administrators and CGI script authors, but
mathematicians, geneticists, journalists, and even managers also
use Perl. Maybe you should, too.
--
"There are two ways of disliking poetry; one way is to dislike it, the
other is to read Pope."
-- Oscar Wilde
------------------------------
Date: Wed, 14 Apr 1999 02:10:22 GMT
From: bhaskaracharya@my-dejanews.com
Subject: File::Find::name question.
Message-Id: <7f0tea$5g9$1@nnrp1.dejanews.com>
hi
why does tests
(! -d "$File::Find::name")
(-f "$File::Find::name"")
seemingly not work i.e it does not behave the way i think it works. i want
only all the files in a list but it grabs directory's also into the list.
Basically , i get all files, from a library (all heirarchies down) with
the following code:
#!/local/perl5 -w
use strict;
use File::Find;
use vars qw(@list);
my $lib = 'full/path/to/lib';
my @newlist = grabFiles("$lib");
sub grabFiles {
####other irelevant code snipped
my $lib = shift @_;
my $file;
find (\&checkfiles , "$lib");
return @list;
}
sub checkfiles {
####other checks snipped
if ( ! /^\.$/) {
{
### the if check has no use!!!! even -f check fails???
### it pushes in directories as well.
### i also put into a variable and still not works
if (! -d "$File::Find::name")
{
push (@list, "$File::Find::name") ;
}
}
}
############workaround i had was
############ suddenly it recognizes the directories...hmm
@list = grep { (! -d "$_") } @list;
thx
-bhaskar
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 14 Apr 1999 03:58:01 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: How to write a format to an array instead of a filehandle?
Message-Id: <3714144F.80E7E007@home.com>
[posted & mailed]
Earl Hood wrote:
>
> Footers can be emulated by setting the page size to some huge
> value. Then track the line number output yourself and switch
> between formats (you'll have to manually do headers also) when
> you hit the spot to print a footer, or header.
Yes, but after I've implemented the code to do all that there is no more
need of format. The nice thing about format is that perl figures out
where the headers go without me doing much in the way of code. Take
away this advantage and I might as well keep track of everything myself
and use printf.
I find it distasteful to have to write perl code to replace some of the
stuff that format does or should be doing. I decide to abandon format
before it gets to that point.
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: 13 Apr 1999 22:52:02 -0400
From: Jonathan Feinberg <jdf@pobox.com>
To: "Soulier, Michael (EXCHANGE:SKY:1Z22)" <msoulier@americasm01.nt.com>
Subject: Re: MLDBM
Message-Id: <m33e23kj71.fsf@joshua.panix.com>
"Soulier, Michael (EXCHANGE:SKY:1Z22)" <msoulier@americasm01.nt.com> writes:
> But, I've used the same code here, built MLDBM with no errors, and I
> can't get it working past the first level of referencing.
It would help us to help you if
1) You showed us some code that doesn't do what you expect it to do,
and
2) You tell us what you expect it to do!
Can you post a brief code sample?
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Wed, 14 Apr 1999 02:32:26 GMT
From: "Michael Villeneuve" <mickv@home.com>
Subject: Re: Novice needs learning suggestions
Message-Id: <_6TQ2.4841$Ay2.437264@news1.rdc1.on.wave.home.com>
Here's how it's done:
1) Buy a good book on Perl (O'reilly has a couple)
2) Dive right in! It's the best way to learn. There are quite a few
tutorials and reference sources online. Do a web search. You'll be
surprised. :-)
m_stelly@my-dejanews.com wrote in message
<7evo5v$439$1@nnrp1.dejanews.com>...
> Hi all,
>
>Where can a start-from-scratch CGI novice best learn quickly about using
>PERL? I am familiar with other web languages, but I'm now itching to learn
>how to get more power out of my pages.
>
>All help is appreciated.
>--
>Michael Stelly
>m_stelly@my-dejanews.com
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 13 Apr 1999 19:28:54 -0500
From: Jim Bostwick <jbostwic@valinor.cargill.com>
Subject: Re: pattern matching
Message-Id: <3713E146.4475E6FE@valinor.cargill.com>
"There's more than one way to do it. (also more than shown here)..."
$var = (your input);
if ($var =~ /^\d+$/) {
# it's all digits
# begin-string, one-or-more digits, end-string
# change '+' to '*' for zero-or-more digits
}
if ($var =~ /![0..9]+/ {
# it's got something else in it
# string contains something NOT in [0..9] set
}
if ($var eq int($var)) {
# string == number - wierd! (even for me)
# how many conversions does this do anyway? ;-)
}
if ($var == ($var+0)) {
# DON'T do this!!
# it'll return a false positive long as $var begins with a digit!
}
Seriously, the first above is one good method. Later methods are sort of
because it's been a long day.
Try reading 'perldoc perlre', for lots more ways to do it...
enjoy
-j
bing-du@tamu.edu wrote:
> Hello there,
>
> How to judge if a variable is composed of digits only?
>
> Thanks in advance for your hints.
>
> Bing
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 13 Apr 1999 22:25:10 -0400
From: David Coppit <dwc3q@mamba.cs.Virginia.EDU>
Subject: Peeking/Seeking STDIN by Inheriting From FileHandle
Message-Id: <Pine.GSO.4.05.9904132205120.5074-100000@mamba.cs.Virginia.EDU>
I've got a couple nagging problems:
- The -B and -s file test operators consume characters on STDIN. I'd
really prefer to be able to peek the characters on STDIN and test them, or
be able to "put them back" on STDIN after reading them. (Right now I've
implemented my own -B and -s, and keep the test characters around. When I
begin reading from STDIN, I first use up the test characters and then
begin reading the rest of the data from the stream.)
- As I read a record of data, I have to read the header for the next
record (or hit EOF) to know when I've reached the end of the record. I'd
like to be able to "put back" the next record's header, instead of having
to lug it around until I'm ready to begin reading the next record.
---------------------------------------------------------------------
As far as I know, peeking STDIN and putting data back on to STDIN are not
possible. The solution I was thinking of would be to derive a class from
FileHandle that contains an internal buffer. This internal buffer would be
used to store data that was "put back" or data that was "peeked". During
reading, the buffer would be first emptied, and then reads would occur
from the stream like normal.
Has anyone already implemented this? Does it sound feasible? Does anyone
have an example of a class that inherits from FileHandle?
Thanks!
David
_________________________________________________________________________
David Coppit - Graduate Student coppit@cs.virginia.edu
The University of Virginia http://www.cs.virginia.edu/~dwc3q
"Yes," said Piglet, "Rabbit has Brain." There was a long silence.
"I suppose," said Pooh, "that that's why he never understands anything."
------------------------------
Date: 14 Apr 1999 03:12:26 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Perl rmdir
Message-Id: <7f112q$mr$1@client2.news.psi.net>
Mike (support@counter.w-dt.com) wrote on MMLII September MCMXCIII in
<URL:news:3713F39F.5FE38936@counter.w-dt.com>:
<> How do you know what UID or GID they are running under? They are run on
<> the same server and both put there by me.
You've no idea what you're talking about. Who put it there is irrelevant.
Who runs it is.
Please ask your sysadmin for a bag of clues.
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
------------------------------
Date: 14 Apr 1999 03:15:53 GMT
From: "Andrew Branson" <a_branson_1998@yahoo.com>
Subject: Re: Printing a file
Message-Id: <7f1199$8us$0@208.231.50.177>
Rick,
I was using a perl script to construct web pages and amongst other things
insert a footer (a separate file) into each page served. Presently, I was
reading and print()ing it line by line. I'll give your method a shot.
Thanks.
Andy
Rick Delaney wrote in message <37133C32.AA72656A@home.com>...
>[posted & mailed]
>
>Andrew Branson wrote:
>>
>> I am sorry if this is a stupid question, but I am fairly new to Perl: I
>> there a way to read and print() an entire file as opposed to line by
line?
>
>Why would you want to do this? Oh well,
>
>perl -0777pe 1 yourfile
>
>perldoc perlrun
>
>--
>Rick Delaney
>rick.delaney@home.com
------------------------------
Date: 14 Apr 1999 03:24:56 GMT
From: "Andrew Branson" <a_branson_1998@yahoo.com>
Subject: Re: Printing a file
Message-Id: <7f11q8$9rd$0@208.231.50.177>
Joshua Justice wrote in message ...
<snip>>
>@lines_from_file = <FH>;
>
>Not to be condescending, but you should probably find a book or reference
>site to review. Supah-cool as Perl is, you can't really learn it by just
>screwing around.
>
>- j -
>print "Just another (minimalist) Perl hacker."
You're absolutely right. I have been programming for 10 years in C, 4 in
C++, and a bunch of other languages. I used to laugh at people struggling
with learning a new language. Perl has certainly humbled me. I am begining
to really enjoy the language now.
I did buy a book - Using Perl 5 for Web Programming - published by Que. It
sucks as a reference. The index sucks even more. I have been told to pick up
a copy of the "camel" book. What books do you recommend?
Thanks.
Andy
------------------------------
Date: Wed, 14 Apr 1999 03:58:04 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Printing a file
Message-Id: <37141109.A4EA277C@home.com>
[posted & mailed]
Andrew Branson wrote:
>
> I was using a perl script to construct web pages and amongst other
> things insert a footer (a separate file) into each page served.
> Presently, I was reading and print()ing it line by line. I'll give
> your method a shot.
I think line by line should suffice. I doubt you will see any kind of
performance improvement by slurping the whole file into memory at once
(though it shouldn't really hurt either if the file is small).
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Tue, 13 Apr 1999 18:24:04 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Problem with my & local declarations
Message-Id: <46g0f7.016.ln@magna.metronet.com>
Mike Mckinney (mike@mike.local.net) wrote:
: Eric The Read <emschwar@rmi.net> wrote:
: >Either "my" or "local" restricts the definition of the variable to the
: >current block. Unless you're doing it on purpose, you nearly always will
: >want to avoid "local" in favor of "my".
: I see. From reading Learning Perl, it looked like it only restricted it to
: the function it was being used in for my, and the function it was used in and
: any functions called from the current function for local.
Do not think of the extent of scope in terms of functions.
Think instead in terms of blocks (or files if not in a block).
Subroutines do have a block, but so do lots of other
constructs such as while and if.
You can even have a bare block, which would also limit scope.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 13 Apr 1999 21:12:25 -0500
From: therzog@knotech.com (Tim Herzog)
Subject: Re: Q: Convert two newlines to \n<p>
Message-Id: <therzog-1304992112250001@therzog-host105.dsl.visi.com>
In article <3713f2cf.15977653@news.netway.com>, mike@w3z.com (Mike
Collins) wrote:
>Trying to match two newlines to produce one newline and a paragraph
>tag <p>.
>
>The code shown and many, many variations all fail.
>
>undef $/;
>while (<TXTFILE>){
> s/\n\n/\n<p>/sg; #Not even close!
> print;
>}
undef'ing the globals doesn't work very well. Try this instead:
$everything = join("", <TXTFILE>);
$everything =~ s/\n\n/\n<p>/sg;
--
Tim Herzog
------------------------------
Date: Tue, 13 Apr 1999 21:42:33 -0500
From: therzog@knotech.com (Tim Herzog)
Subject: Re: referring to form generated variables
Message-Id: <therzog-1304992142330001@therzog-host105.dsl.visi.com>
In article <3713F1EA.EFCE4FD8@1185design.com>, mikej
<mikej@1185design.com> wrote:
single-quoted strings aren't interpolated, so the hash is looking for the
literal "collateral_type", not the value of the $collateral_type variable.
Use $survey_form{"$collateral_type"} (in double quotes) or
$survey_form{$collateral_type} (with no quotes) instead.
>the problem is, the script doesnt return any value for the form input if
>I refer to it as
>
>$survey_form{'$collateral_type'}
>
>even though it WILL return a value for $collateral_type, and also
>
>$survey_form{'$use_now'} will return a value along with the other filed
>name when I refer to them directly.
>
>So I am stumped why it wont return any value. Any help is appreciated!
>Thanks...
>
>-mike
>
>
>
>
--
Tim Herzog
------------------------------
Date: Wed, 14 Apr 1999 00:00:15 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: referring to form generated variables
Message-Id: <1dq83sd.m2ierr1z03q6mN@p98.tc2.state.ma.tiac.com>
mikej <mikej@1185design.com> wrote:
> the problem is, the script doesnt return any value for the form input if
> I refer to it as
>
> $survey_form{'$collateral_type'}
>
> even though it WILL return a value for $collateral_type
Single quotes don't interpolate. Unless you have the literal string
'$collateral_type' as a hash key, you probably meant:
$survey_form{$collateral_type}
--
#!/usr/bin/sh -- chipmunk (aka Ronald J Kimball)
perl -s -e'print sort grep { /\s/ } keys %main::
' -- -is -' Just' -' another ' -'Perl ' -'hacker
' http://www.tiac.net/users/chipmunk/ [rjk@linguist.dartmouth.edu]
------------------------------
Date: Wed, 14 Apr 1999 00:00:17 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: regex - camel and llama cannot help
Message-Id: <1dq83vc.i4g2vrdb0qtcN@p98.tc2.state.ma.tiac.com>
Eric Smith <eric@fruitcom.com> wrote:
> I looked and could not find the answer to this seemingly straightforward
> problem (maybe I missed it?)
>
> I am looking for a regex that will match `ericno' but not `ericnot'
> But the `eric' can also be `sally', so the important thing is the phrase
> `not' following the name, must be present in full and _not_ a `no'.
>
> $ echo ericnot |perl -ne 'if (/(eric[^(no)])/){print "$1 \n"}'
> $ echo ericnot |perl -ne 'if (/(eric[^(not)])/){print "$1 \n"}'
> $ echo ericnot |perl -ne 'if (/(eric[^(ot)])/){print "$1 \n"}'
> ericn
> $ echo ericno |perl -ne 'if (/(eric[^(not)])/){print "$1 \n"}'
Character classes match a single character which is one of the specified
characters. You can't use them to match not a specific sequence of
characters. [^(not)] matches any character other than (, n, o, t, or ).
You can do what you want with a negative look ahead assertion:
/(ericno(?!t))/ # matches 'ericno' not followed by 't'
/(eric(?:no(?!t))?/ # matches 'eric', or 'ericno' not followed by 't'
Hope that helps... You can find out more about look ahead assertions in
the perlre documentation.
--
#!/usr/bin/sh -- chipmunk (aka Ronald J Kimball)
perl -se 'print sort grep {/^[\S]/} keys %main::
' -- -is -' Just' -' another ' -'Perl ' -'hacker
' http://www.tiac.net/users/chipmunk/ [rjk@linguist.dartmouth.edu]
------------------------------
Date: 14 Apr 1999 03:08:54 GMT
From: nina2@fling.seas.upenn.edu (Nina Hung)
Subject: simple perl variable assigning qu
Message-Id: <7f10s6$kfj$1@netnews.upenn.edu>
I would like to create an array and its name is an input from user.
e.g. user entered "TEST"... so in the program, $fields{'name'} variable
will store the "TEST".
@($fields{'name'})... however, this won't work...
what can i do when i have a variable storing a name, which i want to make
it as the array's name?
THANK YOU,
nina
------------------------------
Date: 13 Apr 1999 21:28:21 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: simple perl variable assigning qu
Message-Id: <37140b55@cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
nina2@fling.seas.upenn.edu (Nina Hung) writes:
:I would like to create an array and its name is an input from user.
:e.g. user entered "TEST"... so in the program, $fields{'name'} variable
:will store the "TEST".
:
:@($fields{'name'})... however, this won't work...
:
:what can i do when i have a variable storing a name, which i want to make
:it as the array's name?
You're wanting to do the wrong thing. The symbol table is not the
hash you want to play with.
--tom
=head2 How can I use a variable as a variable name?
Beginners often think they want to have a variable contain the name
of a variable.
$fred = 23;
$varname = "fred";
++$$varname; # $fred now 24
This works I<sometimes>, but it is a very bad idea for two reasons.
The first reason is that they I<only work on global variables>.
That means above that if $fred is a lexical variable created with my(),
that the code won't work at all: you'll accidentally access the global
and skip right over the private lexical altogether. Global variables
are bad because they can easily collide accidentally and in general make
for non-scalable and confusing code.
Symbolic references are forbidden under the C<use strict> pragma.
They are not true references and consequently are not reference counted
or garbage collected.
The other reason why using a variable to hold the name of another
variable a bad idea is that the question often stems from a lack of
understanding of Perl data structures, particularly hashes. By using
symbolic references, you are just using the package's symbol-table hash
(like C<%main::>) instead of a user-defined hash. The solution is to
use your own hash or a real reference instead.
$fred = 23;
$varname = "fred";
$USER_VARS{$varname}++; # not $$varname++
There we're using the %USER_VARS hash instead of symbolic references.
Sometimes this comes up in reading strings from the user with variable
references and wanting to expand them to the values of your perl
program's variables. This is also a bad idea because it conflates the
program-addressable namespace and the user-addressable one. Instead of
reading a string and expanding it to the actual contents of your program's
own variables:
$str = 'this has a $fred and $barney in it';
$str =~ s/(\$\w+)/$1/eeg; # need double eval
Instead, it would be better to keep a hash around like %USER_VARS and have
variable references actually refer to entries in that hash:
$str =~ s/\$(\w+)/$USER_VARS{$1}/g; # no /e here at all
That's faster, cleaner, and safer than the previous approach. Of course,
you don't need to use a dollar sign. You could use your own scheme to
make it less confusing, like bracketed percent symbols, etc.
$str = 'this has a %fred% and %barney% in it';
$str =~ s/%(\w+)%/$USER_VARS{$1}/g; # no /e here at all
Another reason that folks sometimes think they want a variable to contain
the name of a variable is because they don't know how to build proper
data structures using hashes. For example, let's say they wanted two
hashes in their program: %fred and %barney, and to use another scalar
variable to refer to those by name.
$name = "fred";
$$name{WIFE} = "wilma"; # set %fred
$name = "barney";
$$name{WIFE} = "betty"; # set %barney
This is still a symbolic reference, and is still saddled with the
problems enumerated above. It would be far better to write:
$folks{"fred"}{WIFE} = "wilma";
$folks{"barney"}{WIFE} = "betty";
And just use a multilevel hash to start with.
The only times that you absolutely I<must> use symbolic references are
when you really must refer to the symbol table. This may be because it's
something that can't take a real reference to, such as a format name.
Doing so may also be important for method calls, since these always go
through the symbol table for resolution.
In those cases, you would turn off C<strict 'refs'> temporarily so you
can play around with the symbol table. For example:
@colors = qw(red blue green yellow orange purple violet);
for my $name (@colors) {
no strict 'refs'; # renege for the block
*$name = sub { "<FONT COLOR='$name'>@_</FONT>" };
}
All those functions (red(), blue(), green(), etc.) appear to be separate,
but the real code in the closure actually was compiled only once.
So, sometimes you might want to use symbolic references to directly
manipulate the symbol table. This doesn't matter for formats, handles, and
subroutines, because they are always global -- you can't use my() on them.
But for scalars, arrays, and hashes -- and usually for subroutines --
you probably want to use hard references only.
--
Your csh still thinks true is false. Write to your vendor today and tell
them that next year Configure ought to "rm /bin/csh" unless they fix their
blasted shell. :-) --Larry Wall in Configure from the perl distribution
------------------------------
Date: Wed, 14 Apr 1999 00:00:20 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: String matching
Message-Id: <1dq845k.c4k7br1la6y1aN@p98.tc2.state.ma.tiac.com>
Jonathan Stowe <gellyfish@gellyfish.com> wrote:
> You can use substr():
>
> $char = substr($string,13,0);
>
> that will get the 14th character which you can then test as you will.
That will get the null string. Of course, you meant to specify a length
of one rather than zero.
$char = substr($string,13,1);
--
chipmunk (Ronald J Kimball) <rjk@linguist.dartmouth.edu>
perl -e 'print map chop, sort split shift, reverse shift
' 'j_' 'e._jP;_jr/_je=_jk{_jn*_j &_j :_j @_jr}_ja)_js$_j
~_jh]_jt,_jo+_jJ"_jr>_ju#_jt%_jl?_ja^_jc`_jh-_je|' -rjk-
------------------------------
Date: Wed, 14 Apr 1999 00:00:21 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: stumped on regex - onto array
Message-Id: <1dq84m2.1o2e0jo1mzcz99N@p98.tc2.state.ma.tiac.com>
Ronald J Kimball <rjk@linguist.dartmouth.edu> wrote:
> @array = split( m[
> ( # main grab
> \d{0,2} # 0-2 digits
> \. # required .
> \d\d # required 2 digits
> (?: # group the second part
> - # required - separator
> \d{0,2} # 0-2 digits
> \. # required .
> \d\d # required 2 digits
> )? # optional second price
> ) # main grab
> \b # boundary (not really needed)
> ]x, # extended
> $text);
P.S. I forgot to mention that this is the regex posted by Uri earlier
in this thread. As the original poster said, this regex was perfect for
his needs; no sense me trying to rewrite it! Thanks Uri!
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 13 Apr 1999 04:20:46 GMT
From: mbk@cbr.dit.csiro.au (Martin Kuchlmayr)
Subject: Re: Use of LWP Modules
Message-Id: <7eugmu$8ce@gutter.its.csiro.au>
Zenin <zenin@bawdycaste.org> writes:
>In comp.lang.perl.modules David Smith <david@bluewave.com> wrote:
>: Trying to use the LWP modules to get a webpage so that I can work on it
>: before outputting to a browser...
>: this works fine, but doesn't work when $url = "https://mysecureurl.com"
> ^^^^^
> You need the Net::SSLeay module to make SSL connections with LWP.
Teh readme file that came with my copy of LWP says you must use
Crypt-SSLeay, Net::SSLeay is no longer supported. (My copy of LWP is
quite recent).
Martin.
------------------------------
Date: Wed, 14 Apr 1999 00:00:23 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Weird behavior with connect() and IP numbers from @ARGV
Message-Id: <1dq84zg.1lg3nds12au2amN@p98.tc2.state.ma.tiac.com>
<dfry@frymulti.com> wrote:
> connect(SOCK,$paddr) ;
> -------------------
>
> Okay, here's the problem: the connect() call fails each time.
Perhaps you should do some error checking to find out *why* the
connect() fails?
connect(SOCK, $paddr) or die "Can't connect to $site: $!\n";
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 14 Apr 1999 00:00:24 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: What is the end of file character for Mac
Message-Id: <1dq851j.skzf961v5qyd8N@p98.tc2.state.ma.tiac.com>
[posted and mailed]
Chris Newman <newman@dynamite.com.au> wrote:
> I am progressing through the 'Learning Perl' book on my Apple. For the
> shorter exercises it is quickest to type data via the screen. I am now
> looking for a end of file character(s) to active the Perl script to
> accept the input. I understand that for Unix this is Ctrl D and often
> Ctrl Z elsewhere except Macintosh. Can someone please help
When running your script under MacPerl and entering input via the
keyboard, you should use Ctrl-D to terminate input.
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
perl -le 'print "Just another \u$^X hacker"'
------------------------------
Date: Wed, 14 Apr 1999 02:06:12 GMT
From: doug_allan@my-dejanews.com
Subject: win32 api UserDel problem
Message-Id: <7f0t6g$5d0$1@nnrp1.dejanews.com>
I'm new to perl(as you can probably tell) ...with a quick question: the code
below executes without error messages, but does not delete the user "joeuser"
on the PDC. How come? (I'm running the newest version of perl for win32 and
executing it on the PDC.) Thanks for your time!!! -----------code pasted here
-----------------
use Win32API::Net;
$server="ntbox1";
$user="joeuser";
Win32API::Net::UserDel($server, $user);
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5377
**************************************