[12831] in Perl-Users-Digest
Perl-Users Digest, Issue: 241 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 24 02:07:15 1999
Date: Fri, 23 Jul 1999 23:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 23 Jul 1999 Volume: 9 Number: 241
Today's topics:
ARGV validation of command line options (Anno Siegel)
Re: ARGV validation of command line options (Anno Siegel)
Re: ARGV validation of command line options (Steve .)
Re: ARGV validation of command line options (Steve .)
Re: Can anyone explain concepts of Perl Objects? (Abigail)
Re: Can anyone explain concepts of Perl Objects? (Anno Siegel)
Re: concatenate <laurens@bsquare.com>
Re: frames (Anno Siegel)
Re: Geekspeak Programming Contest (Ronald J Kimball)
Re: Help me ..; databases ... <loprestim@toad.net>
Re: mail::pop3client problems (Ronald J Kimball)
Re: My newbie solution - is this the best? (Abigail)
MySQL or Access? <pleasenomail@privacy.org>
Re: no such file when executing perl script (Ronald J Kimball)
Re: output of print map ( { unless (/^#/) {} } ("#") ); (Michael Wang)
Re: output of print map ( { unless (/^#/) {} } ("#") ); (Michael Wang)
Re: output of print map ( { unless (/^#/) {} } ("#") ); (Abigail)
Re: output of print map ( { unless (/^#/) {} } ("#") ); (Abigail)
Re: output of print map ( { unless (/^#/) {} } ("#") ); (Anno Siegel)
Re: output of print map ( { unless (/^#/) {} } ("#") ); <laurens@bsquare.com>
Re: output of print map ( { unless (/^#/) {} } ("#") ); (Anno Siegel)
Re: Perl CGI vs VB ASP (Ronald J Kimball)
Re: Positioning in file? (Anno Siegel)
Re: Possible to pass Hash's? Please Help. (Anno Siegel)
Re: Problem dereferencing hash (Ronald J Kimball)
Re: Problem dereferencing hash (Abigail)
Re: regex mathcing <aqumsieh@matrox.com>
Re: Regex-ing <aqumsieh@matrox.com>
Re: Retrieving NT Services <carvdawg@patriot.net>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 24 Jul 1999 02:28:43 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: ARGV validation of command line options
Message-Id: <7nb8cr$2of$1@lublin.zrz.tu-berlin.de>
Steve . <syarbrou@nospam.enteract.com> wrote in comp.lang.perl.misc:
[Getopt::Std]
>Thanks, I'll take a look. I'd also appreciate an example of how to do
>this without modules. Think I'm close, but in case I don't figure it
>out, it would be much appreciated. Thanks.
It's more involved than it looks at first sight. Simple yes/now
options are relatively easy (untested):
my $arg;
while ( @ARGV ) {
$arg = $_;
if ( /^-/ ) {
# process switch
} else {
last;
}
}
unshift @ARGV $arg;
But when it comes to switches that take values I'll use Getopt::Std
anytime, especially as it's part of the standard distribution.
Anno
------------------------------
Date: 24 Jul 1999 02:08:20 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: ARGV validation of command line options
Message-Id: <7nb76k$2l7$1@lublin.zrz.tu-berlin.de>
Steve . <syarbrou@nospam.enteract.com> wrote in comp.lang.perl.misc:
>say I have multiple options for a command lines. They can be used or
>not. How do I validate if they are there or not?
>
>For example:
>
>can use: progname -r -h -x infile outfile
>
>or can use progname or infile outfile
>
>or can ue progname infile outfile
>
>How do I do checking on what the user types in with these variations?
>Thanks.
use Getopt::Std and perldoc Getopt::Std.
Anno
------------------------------
Date: Sat, 24 Jul 1999 02:13:07 GMT
From: syarbrou@nospam.enteract.com (Steve .)
Subject: Re: ARGV validation of command line options
Message-Id: <37992101.43595971@news.enteract.com>
Thanks, I'll take a look. I'd also appreciate an example of how to do
this without modules. Think I'm close, but in case I don't figure it
out, it would be much appreciated. Thanks.
Steve
On 24 Jul 1999 02:08:20 -0000, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:
>Steve . <syarbrou@nospam.enteract.com> wrote in comp.lang.perl.misc:
>>say I have multiple options for a command lines. They can be used or
>>not. How do I validate if they are there or not?
>>
>>For example:
>>
>>can use: progname -r -h -x infile outfile
>>
>>or can use progname or infile outfile
>>
>>or can ue progname infile outfile
>>
>>How do I do checking on what the user types in with these variations?
>>Thanks.
>
>use Getopt::Std and perldoc Getopt::Std.
>
>Anno
------------------------------
Date: Sat, 24 Jul 1999 02:17:49 GMT
From: syarbrou@nospam.enteract.com (Steve .)
Subject: Re: ARGV validation of command line options
Message-Id: <379a2239.43908107@news.enteract.com>
My bad. Noticed it's included in perl.
Steve
On Sat, 24 Jul 1999 02:13:07 GMT, syarbrou@nospam.enteract.com (Steve
.) wrote:
>Thanks, I'll take a look. I'd also appreciate an example of how to do
>this without modules. Think I'm close, but in case I don't figure it
>out, it would be much appreciated. Thanks.
>
>Steve
>
>On 24 Jul 1999 02:08:20 -0000, anno4000@lublin.zrz.tu-berlin.de (Anno
>Siegel) wrote:
>
>>Steve . <syarbrou@nospam.enteract.com> wrote in comp.lang.perl.misc:
>>>say I have multiple options for a command lines. They can be used or
>>>not. How do I validate if they are there or not?
>>>
>>>For example:
>>>
>>>can use: progname -r -h -x infile outfile
>>>
>>>or can use progname or infile outfile
>>>
>>>or can ue progname infile outfile
>>>
>>>How do I do checking on what the user types in with these variations?
>>>Thanks.
>>
>>use Getopt::Std and perldoc Getopt::Std.
>>
>>Anno
------------------------------
Date: 24 Jul 1999 00:13:20 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Can anyone explain concepts of Perl Objects?
Message-Id: <slrn7piiq9.2rn.abigail@alexandra.delanet.com>
Ramanika (ramanika@flashmail.com) wrote on MMCLIII September MCMXCIII in
<URL:news:37990522.2EE12D5A@flashmail.com>:
Why are you xposting this to a defunct group, and an off-topic group?
Newsgroups header fixed.
## What does bless do? (yes I have read all about it and still do not
## understand)
It makes the reference to the datastructure aware to which class
it belongs.
## Under what circumstances do you need it (bless)?
When creating class instances (objects).
## Under what circumstances do you leave it out (bless)?
When you are not creating class instances.
## What is the equivalent of bless in regards to C++ objects?
I doubt there is any, but my knowledge of C++ is minimal.
## What is the best way to represent member data in an object? Hash?
Define "best way". Maybe there isn't a "best way"... IMO, Perl objects
suck, its main reason being how member data is dealt with.
## What is the equilavent of "a pointer to an object" in Perl?
Depending on one's view, it's either the reference to the datastructure
(the thing you are blessing), or a reference to that.
## How do you create and manipulate one (pointer to an object)?
my $pointer_to_obj = bless {}, "Hello";
or
my $pointer_to_obj = \ bless {}, "Hello";
Abigail
--
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y/+{#}$=^*&[0-9]i@:;`"',./ /d)&&$llama."\n");
-----------== 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: 24 Jul 1999 05:57:32 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Can anyone explain concepts of Perl Objects?
Message-Id: <7nbkkc$34i$1@lublin.zrz.tu-berlin.de>
Abigail <abigail@delanet.com> wrote in comp.lang.perl.misc:
>Ramanika (ramanika@flashmail.com) wrote on MMCLIII September MCMXCIII in
><URL:news:37990522.2EE12D5A@flashmail.com>:
>
>Why are you xposting this to a defunct group, and an off-topic group?
>Newsgroups header fixed.
>
>## What does bless do? (yes I have read all about it and still do not
>## understand)
>
>It makes the reference to the datastructure aware to which class
>it belongs.
Oh dear. Did I see the godess stumble?
Anno
------------------------------
Date: Fri, 23 Jul 1999 21:09:12 -0700
From: "Lauren Smith" <laurens@bsquare.com>
Subject: Re: concatenate
Message-Id: <7nbe98$cqu$1@brokaw.wa.com>
Larry Rosler wrote in message ...
>In article <37977868.C92BF625@aur.alcatel.com> on Thu, 22 Jul 1999
>14:00:40 -0500, Bruno Pagis <pagib@aur.alcatel.com> says...
>> $ string3 = $string1 . $string2;
>
>or
>
> $string3 = "$string1$string2";
>
>or
>
> $string3 = join "", $string1, $string2;
>
>or...
>
yet another way...
($string3 = $string1) .= $string2;
Lauren
------------------------------
Date: 24 Jul 1999 02:43:45 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: frames
Message-Id: <7nb991$2rc$1@lublin.zrz.tu-berlin.de>
JJcoParks4 <jjcoparks4@aol.com> wrote in comp.lang.perl.misc:
>Hello I am trying to make a perl cgi script and I wan't part of it to be in a
>frame. Is this posibble? And if so how the heck do I do it?
I don't know if it's posibble. No-one here does, since this group
is only concerned with perl and golf. Find a newsgroup with cgi
or html in its name.
Anno
------------------------------
Date: Fri, 23 Jul 1999 23:12:36 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Geekspeak Programming Contest
Message-Id: <1dvf3ab.jdcfhk1tpjwyiN@p20.tc15.metro.ma.tiac.com>
Tom Christiansen <tchrist@mox.perl.com> wrote:
> * Microsoft's mistakes = virii
Tsk tsk... I know you know better than that, Tom. ;)
--
_ / ' _ / - 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: Sat, 24 Jul 1999 00:28:03 -0400
From: matt <loprestim@toad.net>
Subject: Re: Help me ..; databases ...
Message-Id: <379940D2.AA23E626@toad.net>
What are you saying???
Richard H wrote:
> matt wrote:
> >
> > Here is an example of a connection and select statement:
> >
> > #open connection with DB
> > $DSN ="your_domain_name";
> > if (!($db = new Win32::ODBC("DSN=your_domain_name;"))) {
> > print STDOUT "Error connecting to $DSN\n";
> > print STDOUT "Error: " . Win32::ODBC::Error() . "\n";
> > exit;
> > }
> >
> > $SqlStatement = "SELECT table_name.field_name
> > FROM table_name;";
> >
>
> Er, am i making a fool of myself, or have you done a typo in the next
> bit??
>
> > if ($db->Sql($SqlStatement)) {
> > print "SQL failed- Cannot execute\n";
> > print "Error: ". $db->Error(). "\n";
> > $db->Close();
> > exit;
> > }
> > $db->Close();
> >
> > There are other ways of doing this, this is just how I like doing it :-)
>
> You like doing the SQL and if it returns something, pretending its
> failed??? :-),
>
> Richard H (i hope im right or im going to look v gormless)
------------------------------
Date: Fri, 23 Jul 1999 23:12:40 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: mail::pop3client problems
Message-Id: <1dvf3je.1ksv3hy5qss6yN@p20.tc15.metro.ma.tiac.com>
James Gerard Coleman <jgc5a@j2.mail.virginia.edu> wrote:
> Missing $ on loop variable at blah/blah/blah/pop3client.pm line 96
> BEGIN failed -- compilation aborted at dir/dir/dir/file.plx at line...
>
> i looked through the code, and couldn't find any errors... i might be
> wrong about that, but i'm pretty sure it's okay.. anyone here more
> familiar with this particular module? any workarounds, changes to the
> code i can use, or anything?
I would guess that line 96 looks something like this:
foreach my $loop_variable (@array) {
and you get the error because you are using an old version of Perl that
does not allow 'my' on the loop variable in a foreach expression.
You should upgrade to a more recent version of Perl. For Win32 Perl, go
to http://www.activestate.com/activeperl/
--
_ / ' _ / - 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: 24 Jul 1999 00:38:30 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: My newbie solution - is this the best?
Message-Id: <slrn7pik9e.2rn.abigail@alexandra.delanet.com>
Larry Rosler (lr@hpl.hp.com) wrote on MMCLII September MCMXCIII in
<URL:news:MPG.120292daaccbc659989d2d@nntp.hpl.hp.com>:
"" [Posted and a courtesy copy mailed.]
""
"" In article <7nanm6$vr7$1@nnrp1.deja.com> on Fri, 23 Jul 1999 21:43:36
"" GMT, breslow_marty@tandem.com <breslow_marty@tandem.com> says...
"" > I found that after the strip of STDIN the field had a beginning and
"" > trailing quote so I used substr to remove them. Then I used
"" > substitution with the g modifier to substitute "" for " and that
"" > worked. I then concatenated the result to get the final product
"" > i.e., '"' . $newstring . '",'
"" > Is this best way? I guess I was hoping for the opposite of tr's
"" > duplicate removal but that's not automated in the language.
""
"" Well, I can do it all in a 'one-liner', though that may not matter to
"" you. :-)
""
"" s/"(.+)"/"${\do{(my$x=$1)=~s|"|""|g;$x}}",/;
""
"" Golf, anyone?
Yours doesn't work for strings containing newlines, (or the string '""'
for that matter); fixing that, and beating your score:
s;(?<=.)"(?=.);"";gs;s;$;,;;
Just in case you complain it's actually 2 statements, and not a oneliner:
s+(?<=.)"(?=.)+""+gs+s+$+,+;
Or, for pre-perl5.005, still beating your score:
substr($_,1,-1)=~s;";"";g;s;$;,;;
Abigail
--
Look, the first time I used one of those new Ilya thingies.
-----------== 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: Fri, 23 Jul 1999 23:47:02 -0500
From: "Dan" <pleasenomail@privacy.org>
Subject: MySQL or Access?
Message-Id: <9zbm3.53796$AU3.1278529@news2.giganews.com>
I have got a question..... I would like to choose a db and I have a dilemma
between MySQL and Microsnot Access. They have both very nice features and
the decision is not obvious. What do you all think about that?
Also, if I put an Access db file on a unix box can I use ODBC (or something
else)
transparently to work with the DB?
Thanks for your suggestions.
Daniel
http://thewebcowboy.com
------------------------------
Date: Fri, 23 Jul 1999 23:12:51 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: no such file when executing perl script
Message-Id: <1dvf3q8.qtcjrgjjra5vN@p20.tc15.metro.ma.tiac.com>
Chris L <fncll@uaf.edu> wrote:
> Why would adding -w to the shebang line cause it to execute properly?
Check for a carriage return at the end of the shebang line.
--
_ / ' _ / - 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: 24 Jul 1999 03:49:08 GMT
From: mwang@tech.cicg.ml.com (Michael Wang)
Subject: Re: output of print map ( { unless (/^#/) {} } ("#") );
Message-Id: <7nbd3k$58m$1@news.ml.com>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>>>Michael Wang (mwang@tech.cicg.ml.com) wrote on MMCLI September MCMXCIII
>>>== What should be the output of the following?
>>>==
>>>== (1) map ( { unless (/^#/) {} } ("#") );
>>>== (2) print map ( { if (/^#/) {} } ("#") );
>>>== (3) print map ( { if ( !/^#/) {} } ("#") );
>>>==
>>>== And why? Thanks.
>>>==
>>>== It is my opinion that neither of the 3 above should produce ANYTHING.
>>>== but (1) produce "1" which I do not know why. How can I prevent it
>>>== from produce this unwanted "1". Thanks again.
>>>
>
>How would this ever "produce" anything in your sense of the word?
>Nothing in this code will ever output anything to the screen.
That is what I thought, but the fact it does output something makes
me to post the question which did not answer.
>As for weird, the bit of code does nothing if a match occurs.
>It does another nothing and then the same nothing as before if
>a match doesn't occur. Qualifies as weird in my book.
>
>None of these "produce" anything. I am still unclear what your
>question is.
If you are so concentrate on the picking up in English usage, and
"weirdness" of code, then I am not surprised that you miss the question
which is clearly spelled out. To make this question more clear, I
will show you the output of the code below, which obviously you did not
run. And since both you and I agree that it should not output anything,
I tend to think this is a Perl bug. Can someone with higher version of
Perl please tell me what is the output or lack of output with Perl
greater than version 5.004_04? Thanks a lot.
[julie:/opt/home/mwang]perl --version
This is perl, version 5.004_04 built for i86pc-solaris
Copyright 1987-1997, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.
[julie:/opt/home/mwang]perl -e 'print map { unless (/^#/) {} } ("#")'
1
What is the difference between Shell programmers and Perl programmers?
SHELL users dont talk much about their work. They just do it.
PERL users talk much more about their work. Talking and praising
reassures them of being worthy.
--
Michael Wang
http://www.mindspring.com/~mwang
------------------------------
Date: 24 Jul 1999 03:53:44 GMT
From: mwang@tech.cicg.ml.com (Michael Wang)
Subject: Re: output of print map ( { unless (/^#/) {} } ("#") );
Message-Id: <7nbdc8$58p$1@news.ml.com>
Tad McClellan <tadmc@metronet.com> wrote:
>Michael Wang (mwang@tech.cicg.ml.com) wrote:
>: >Michael Wang (mwang@tech.cicg.ml.com) wrote on MMCLI September MCMXCIII
>: >in <URL:news:7n7ag7$5re$1@news.ml.com>:
>: >== What should be the output of the following?
>: >==
>: >== (1) map ( { unless (/^#/) {} } ("#") );
>
>: >== It is my opinion that neither of the 3 above should produce ANYTHING.
>: >== but (1) produce "1" which I do not know why. How can I prevent it
>: >== from produce this unwanted "1". Thanks again.
>: >
>: >What do you mean by "producing"? As given, the map is in void context,
>: >anything "produced" will be thrown away. And it doesn't have side effects,
>: >so what exactly is the problem?
>:
>: "producing" means when you run it, what goes to the screen.
>
> Programmers call that "output".
>
> Precise terminology is important when discussing technical topics.
>
> (1) does not send anything ("produce") to the screen, because
> it does not have any output statements.
>
> If you have some code where (1) makes output, then we could
> comment on it if you would show it to us.
OK, please comment on the following, thanks.
[julie:/opt/home/mwang]perl --version
This is perl, version 5.004_04 built for i86pc-solaris
Copyright 1987-1997, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.
[julie:/opt/home/mwang]perl -e 'print map { unless (/^#/) {} } ("#")'
1 <= Please note the "1" there
--
Michael Wang
http://www.mindspring.com/~mwang
------------------------------
Date: 24 Jul 1999 00:04:04 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: output of print map ( { unless (/^#/) {} } ("#") );
Message-Id: <slrn7pii8t.2rn.abigail@alexandra.delanet.com>
Michael Wang (mwang@tech.cicg.ml.com) wrote on MMCLIII September MCMXCIII
in <URL:news:7nbdc8$58p$1@news.ml.com>:
%%
%% OK, please comment on the following, thanks.
I already did. What's your problem?
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
-----------== 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: 24 Jul 1999 00:05:53 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: output of print map ( { unless (/^#/) {} } ("#") );
Message-Id: <slrn7piic9.2rn.abigail@alexandra.delanet.com>
Michael Wang (mwang@tech.cicg.ml.com) wrote on MMCLIII September MCMXCIII
in <URL:news:7nbd3k$58m$1@news.ml.com>:
??
?? [Asking the same question for the zillionth time]
??
?? What is the difference between Shell programmers and Perl programmers?
??
?? SHELL users dont talk much about their work. They just do it.
?? PERL users talk much more about their work. Talking and praising
?? reassures them of being worthy.
What's the difference between programmers and Wangs?
Wangs don't listen.
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
-----------== 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: 24 Jul 1999 05:28:20 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: output of print map ( { unless (/^#/) {} } ("#") );
Message-Id: <7nbitk$32a$1@lublin.zrz.tu-berlin.de>
[posted and mailed]
Michael Wang <mwang@tech.cicg.ml.com> wrote in comp.lang.perl.misc:
>Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>>>>Michael Wang (mwang@tech.cicg.ml.com) wrote on MMCLI September MCMXCIII
>>>>== What should be the output of the following?
>>>>==
>>>>== (1) map ( { unless (/^#/) {} } ("#") );
>>>>== (2) print map ( { if (/^#/) {} } ("#") );
>>>>== (3) print map ( { if ( !/^#/) {} } ("#") );
>>>>==
>>>>== And why? Thanks.
>>>>==
>>>>== It is my opinion that neither of the 3 above should produce ANYTHING.
>>>>== but (1) produce "1" which I do not know why. How can I prevent it
>>>>== from produce this unwanted "1". Thanks again.
>>>>
>>
>>How would this ever "produce" anything in your sense of the word?
>>Nothing in this code will ever output anything to the screen.
>
>That is what I thought, but the fact it does output something makes
>me to post the question which did not answer.
Note that your statement (1) doesn't contain a print (or other
output-) statement. There is no way this can output anything
to the screen. (No, I didn't test this.)
>>As for weird, the bit of code does nothing if a match occurs.
>>It does another nothing and then the same nothing as before if
>>a match doesn't occur. Qualifies as weird in my book.
>>
>>None of these "produce" anything. I am still unclear what your
>>question is.
>
>If you are so concentrate on the picking up in English usage, and
>"weirdness" of code, then I am not surprised that you miss the question
>which is clearly spelled out.
The fact that two of your statements contain a print operation
whereas one doesn't makes it less than clear. I'm not gratuitously
nitpicking, I am honestly trying to find out what you want to know.
> To make this question more clear, I
>will show you the output of the code below, which obviously you did not
>run. And since both you and I agree that it should not output anything,
>I tend to think this is a Perl bug. Can someone with higher version of
>Perl please tell me what is the output or lack of output with Perl
>greater than version 5.004_04? Thanks a lot.
>
>[julie:/opt/home/mwang]perl --version
>
>This is perl, version 5.004_04 built for i86pc-solaris
>
>Copyright 1987-1997, Larry Wall
>
>Perl may be copied only under the terms of either the Artistic License or the
>GNU General Public License, which may be found in the Perl 5.0 source kit.
>
>[julie:/opt/home/mwang]perl -e 'print map { unless (/^#/) {} } ("#")'
>1
Well, here you *have* a print operation and the question makes sense.
Now let's see...
You're using a map with a block and a one-element list. This would
return a one-element list whose element is the value of your block.
The value of a block is the value of the last statement in the block,
which is an if statement. Well, it's an unless statement, same
difference. Here is where the trouble begins.
The Perl documentation doesn't say what the value of an if statement
is (I'd be amazed if it did). In fact, something like
$x = if ( ... ) { ... }
is a syntax error. Even if you put the if inside a block, like
$x = { if ( ... ) { ... } }
you get a syntax error. Now, putting that block inside a map is a
cute trick to make Perl confess what it thinks the value of an
if statement is, because any block is allowed there. But, and this
is a big BUT, Perl is under no obligation to make sense, because
it has never promised to return something useful from an if statement.
The result is undefined, and you will have to be content with whatever
Perl decides to return. Except a segfault, that is, and it doesn't
do that. If you were to say it would be more consistent if it
returned an undef, I'd have to agree. But there's nothing in the
contract that could lead you to expect that.
So, to come back to your original question "What can I do to prevent
that unwanted 1", I'm afraid there's nothing you can do.
>What is the difference between Shell programmers and Perl programmers?
>
>SHELL users dont talk much about their work. They just do it.
>PERL users talk much more about their work. Talking and praising
>reassures them of being worthy.
This group is meant to be a place to talk about Perl issues. If
you don't like it, don't go there. Your generalization is as
unwarranted as your exasperation.
Oh, and when you mail a Cc of your posting, please indicate in
the text that you have also posted it. The reason should be
obvious.
Anno
------------------------------
Date: Fri, 23 Jul 1999 22:22:08 -0700
From: "Lauren Smith" <laurens@bsquare.com>
Subject: Re: output of print map ( { unless (/^#/) {} } ("#") );
Message-Id: <7nbii0$ids$1@brokaw.wa.com>
Michael Wang wrote in message <7nbd3k$58m$1@news.ml.com>...
>Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>>>>Michael Wang (mwang@tech.cicg.ml.com) wrote on MMCLI September MCMXCIII
What we've got here is a failure to communicate.
>>>>== What should be the output of the following?
>>>>==
>>>>== (1) map ( { unless (/^#/) {} } ("#") );
The output of the that is nothing. There is no command to output/print to
screen/display/make visible anything. It does, however, produce a return
value that you are unsure of and concerned about. Your use of the word
'produce' can be taken to mean many different things and in this case it has
caused a lot of confusion and ill will.
>>>>== but (1) produce "1" which I do not know why. How can I prevent it
>>>>== from produce this unwanted "1". Thanks again.
(1) returns "1"
>>How would this ever "produce" anything in your sense of the word?
>>Nothing in this code will ever output anything to the screen.
>
>That is what I thought, but the fact it does output something makes
>me to post the question which did not answer.
I don't think you and Anno are thinking the same thing. He's obviously
talking about outputting to the screen and you are talking about returning a
value.
>[julie:/opt/home/mwang]perl -e 'print map { unless (/^#/) {} } ("#")'
>1
Oh ho! This is not the same code that we've seen in (1).
Well, I certainly don't have the definitive answer, but it looks like the
'map' function is returning an array with 1 element. My guess is that
'unless' is actually returning 'true' values and 'map' is storing them into
the array that you're asking for (which is just a re-statement of perlfunc
"map"'s output).
Whether 'unless' should be returning values is questionable, though,
especially seeing how 'if (!0)' doesn't pass a value to 'map'. Does anyone
know why this happens?
Lauren
------------------------------
Date: 24 Jul 1999 05:54:47 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: output of print map ( { unless (/^#/) {} } ("#") );
Message-Id: <7nbkf7$33q$1@lublin.zrz.tu-berlin.de>
Lauren Smith <laurens@bsquare.com> wrote in comp.lang.perl.misc:
[much snipped]
>Whether 'unless' should be returning values is questionable, though,
>especially seeing how 'if (!0)' doesn't pass a value to 'map'. Does anyone
>know why this happens?
I don't. Experimentation shows that if/unless ( ... ) in list context
behave erratic. I have seen them return ( 0 ), ( 1 ), ( '' ) and ().
but not ( undef ), if I'm reading my results right. () makes most
sense, in my opinion, but I have argued that the result is undefined
and we can't expect anything specific.
I tend to believe it's just some random sv that happens to lie around.
Maybe someone knowledgeable in perlguts cares to comment.
Anno
------------------------------
Date: Fri, 23 Jul 1999 23:12:52 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Perl CGI vs VB ASP
Message-Id: <1dvf3tb.sixnc613z7yt4N@p20.tc15.metro.ma.tiac.com>
elephant <e-lephant@b-igpond.com> wrote:
> [ item posted to comp.lang.perl.misc and CCed to Eisen Chao ]
>
> Eisen Chao writes ..
> >I'm familiar with using Perl within CGI,
> >but not with VB & ASP.
> >
> >What are the advantages of the Perl/CGI
> >combination over using the Micro$oft
> >product ?
>
> I'm fairly shocked at the lack of depth of the responses that you've
> received so far .. although maybe people can't be bothered because it's
> such a simple question to answer
Maybe people can't be bothered because this is a Perl newsgroup, so it's
pretty much a given that people will recommend Perl over Microsoft
products.
Even more so, the original poster is familiar with Perl, but not with VB
or ASP. Are we suppose to explain VB or ASP to the poster? This is not
the correct newsgroup for that.
Language advocacy is pointless in a newsgroup that is dedicated to a
single language.
--
_ / ' _ / - 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: 24 Jul 1999 02:37:04 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Positioning in file?
Message-Id: <7nb8sg$2q3$1@lublin.zrz.tu-berlin.de>
Lab User <bogus@razorback.uark.edu> wrote in comp.lang.perl.misc:
> Ok, I'm trying to write a perl script that'll make log entries in
>a text file in FILO order. That is, the first entry in the text file
>should be the last entry submitted by the script. My first thought was
>to use the "seek FILEHANDLE, 0, 0;" function and then write the entry.
>It doesn't work, though. The last entry made is always last in the log
>file, and I need this to be reversed. What do I do?
You read the faq. In particular, you read
perldoc -q 'append to the beginning'
Or, if you want some fancy overkill, get DB_File and check out
the file type DB_RECNO.
Anno
------------------------------
Date: 24 Jul 1999 02:18:51 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Possible to pass Hash's? Please Help.
Message-Id: <7nb7qb$2mf$1@lublin.zrz.tu-berlin.de>
japhy <japhy@pobox.com> wrote in comp.lang.perl.misc:
[...]
>As for your next post, what is bless? Bless "labels" a reference as
>belonging to a certain package (or "class").
Careful there. It's whatever the reference *points to* that becomes
an object in the package. The reference is unaffected.
> Variables may be DEFINED in
>a package, but that doesn't make them BLESSED into it. And the actual
>variable isn't blessed, it's the contents it REFERS to that get blessed.
You got it there, though the wording is slightly confusing.
Anno
------------------------------
Date: Fri, 23 Jul 1999 23:12:53 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Problem dereferencing hash
Message-Id: <1dvf402.144hdyq1jebx27N@p20.tc15.metro.ma.tiac.com>
Larry Rosler <lr@hpl.hp.com> wrote:
> > you mean: @keys = keys %$hash;
> >
> > for the same reason you say:
> > my %hash2;
> > @a = keys %hash2;
> > and not
> > @a = keys $hash2;
>
> No. Not for the same reason at all. %hash2 and $hash2 are different
> symbols, with no relaionship to each other. %hash2 is a hash; $hash2 is
> a scalar that may contain any scalar value, including a reference to a
> hash.
Exactly. %hash2 is a hash. %$hash2 is a hash.
$hash2 is not a hash. $$hash2 is not a hash.
That's why you say keys %$hash2 and keys %hash2, rather than keys
$$hash2 and $hash2.
I would argue that it is, as Lisa said, the same reason.
--
_ / ' _ / - 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: 24 Jul 1999 00:41:29 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Problem dereferencing hash
Message-Id: <slrn7pikf2.2rn.abigail@alexandra.delanet.com>
Michael O'Connor (moconnor@publiconline.co.uk) wrote on MMCLII September
MCMXCIII in <URL:news:3798CB00.490F@publiconline.co.uk>:
%% Hi,
%%
%% I'm hoping someone can tell me how to scan a hash which has been passed
%% to a subroutine as a reference e.g.
%%
%% sub1(\%hash1);
%%
%% ...
%%
%% sub sub1
%% {
%% my $hash = $_[0];
%% my @keys = keys $$hash;
%%
%% ...
%% }
%%
%% The last line of code above gives the error "Type of arg 1 to keys must
%% be hash (not scalar deref)" yet something like the following works fine
%% in its place:
%%
%% $$hash{'key'} = value;
Of course it does. "$$hash{key}" isn't a hash, it's a scalar. The leading
$ should give you the hint.
Now, keys want a hash. What's the secret symbol for a hash? Right, it's %.
So, lets try: my @keys = keys %$hash; And what do you know? It works....
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
-----------== 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: Fri, 23 Jul 1999 22:25:45 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: regex mathcing
Message-Id: <x3yvhba3hsm.fsf@tigre.matrox.com>
pozman@my-deja.com writes:
> If I have a string and want to know how many occurance there are of
> another particular string within the first one, is there a regular
> expression to do that.
$string = 'this is his cat';
$search = 'is';
$count = () = $string =~ /$search/g;
If this looks cryptic, then you should have a good look at perlre for
more information of Perl's regexps.
HTH,
Ala
------------------------------
Date: Fri, 23 Jul 1999 22:20:50 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Regex-ing
Message-Id: <x3ywvvq3i0t.fsf@tigre.matrox.com>
miker3@ix.netcom.com (Michael Rubenstein) writes:
> Which will translate two of the possible "carriage returns" you
> list into two delimiters. Something a little more like
>
> $news =~ s/(?:\r\n?)|(?:\n\r?)/delimiter/g;
>
> might work better.
Yeah but you are typing way too many characters:
$news =~ s/\r\n?|\n\r?/delimiter/g;
The OR ("|") binds very weekly for a good reason. Use it.
> However, it might be that Ben really does mean "carriage return",
> not "whatever represents a new line in the input." If so, his
> mistake is simply in using the wrong character. \r is the escape
> for carriage return, so it should be
>
> $news =~ s/\r/delimiter/g;
Let me suggest here that if the delimiter is a single (or empty)
character, then tr/// would be a faster approach than s///g.
HTH,
Ala
------------------------------
Date: Fri, 23 Jul 1999 22:56:46 -0400
From: HC <carvdawg@patriot.net>
Subject: Re: Retrieving NT Services
Message-Id: <37992B6E.7EEB459D@patriot.net>
> Where did you find lanman? ppm doesn't find it.
>
perl ppm.pl install http://jenda.krynicky.cz/perl/win32-lanman.ppd
>
> At least I'm not going crazy, Service really is
> empty. I figured there's a dll missing or
> something.
What? What do you mean by that?
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
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 V9 Issue 241
*************************************