[15714] in Perl-Users-Digest
Perl-Users Digest, Issue: 3127 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 22 18:15:57 2000
Date: Mon, 22 May 2000 15:15:26 -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: <959033726-v9-i3127@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 22 May 2000 Volume: 9 Number: 3127
Today's topics:
Re: simple array question <dave@dave.org.uk>
Re: simple array question <godzilla@stomp.stomp.tokyo>
Re: simple array question (Gordon Clemmons)
Re: sorting a list of mixed numbers and text as in perl <andrew.mcguire@walgreens.com>
Re: SQL newbie question <makarand_kulkarni@My-Deja.com>
Re: SQL newbie question <news@theedgeofpanic.freeserve.co.uk>
Re: SQL newbie question newsposter@cthulhu.demon.nl
Re: the use of $_ (Mark-Jason Dominus)
Re: the use of $_ <godzilla@stomp.stomp.tokyo>
Re: the use of $_ (Mark Badolato)
Re: the use of $_ <godzilla@stomp.stomp.tokyo>
Re: the use of $_ (Gordon Clemmons)
Re: updated : Re: regexes *sigh* damn I hate these thin <lr@hpl.hp.com>
Re: updated : Re: regexes *sigh* damn I hate these thin (Abigail)
Re: valid email address <thepoet1@arcormail.de>
Visibility of package lexicals in debugger msouth@fulcrum.org
Re: Windows/Linux Incompatibility <apage.net[remove]@usa.net>
Re: Windows/Linux Incompatibility <ab@cd.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 22 May 2000 19:06:15 +0100
From: Dave Cross <dave@dave.org.uk>
Subject: Re: simple array question
Message-Id: <egtiis44ufe643i4b37vi53ol2lgo7dhlg@4ax.com>
On Mon, 22 May 2000 10:03:44 -0700, "Godzilla!"
<godzilla@stomp.stomp.tokyo> wrote:
>"red [2]" wrote:
>
>> can i get the number of values in an array
>> without going through a foreach loop?
>> eg if i opened a file and
>> @myarray=<FILELINES>;
>> how do i get the amount of "lines" in @myarray?
>
>
>This format, one of a few, might help you
>quickly and easily:
>
>$#myarray+1
This is only true as long as $[ has not been changed, as $#array gives
the index of the lst element in @array.
The more often used
$count = @array;
or (more explicitly)
$count = scalar @array;
will always give the right answer.
Perhaps this test script will demonstrate:
my @a = qw(one two three);
print $#a + 1, "\n";
print scalar @a, "\n";
$[ = 1;
print $#a + 1, "\n";
print scalar @a, "\n";
$[ = 100;
print $#a + 1, "\n";
print scalar @a, "\n";
hth,
Dave...
--
<http://www.dave.org.uk> SMS: sms@dave.org.uk
yapc::Europe - London, 22 - 24 Sep <http://www.yapc.org/Europe/>
"There ain't half been some clever bastards" - Ian Dury [RIP]
------------------------------
Date: Mon, 22 May 2000 11:32:09 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: simple array question
Message-Id: <39297D29.AFB8E51D@stomp.stomp.tokyo>
Dave Cross wrote:
> "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
> >"red [2]" wrote:
> >> can i get the number of values in an array
> >> without going through a foreach loop?
> >> eg if i opened a file and
> >> @myarray=<FILELINES>;
> >> how do i get the amount of "lines" in @myarray?
> >This format, one of a few, might help you
> >quickly and easily:
> >$#myarray+1
> This is only true as long as $[ has not been changed, as $#array gives
> the index of the lst element in @array.
> The more often used
> $count = @array;
Thank you Mr. Cross for enhancing what
I have posted. This is a good point.
Godzilla!
------------------------------
Date: 22 May 2000 20:33:13 GMT
From: perl_phreak@yahoo.com (Gordon Clemmons)
Subject: Re: simple array question
Message-Id: <8F3C805D4nospamblahcom@206.165.3.70>
godzilla@stomp.stomp.tokyo (Godzilla!) wrote in
<39296870.A675303A@stomp.stomp.tokyo>:
>"red [2]" wrote:
>
>> can i get the number of values in an array
>> without going through a foreach loop?
>> eg if i opened a file and
>> @myarray=<FILELINES>;
>> how do i get the amount of "lines" in @myarray?
>
>
>This format, one of a few, might help you
>quickly and easily:
>
>$#myarray+1
>
>
>This is a simple example of how
>this format works:
>
>
>Test Script:
>________________
>
>#!/usr/local/bin/perl
>
>print "Content-Type: text/plain\n\n";
>
>@Test_Array = ("one", "two", "three");
>
>$count = ($#Test_Array+1);
>
>print "Number of elements is $count";
>
>exit;
>
>
>
>Printed Results:
>________________
>
>Number of elements is 3
>
Or you could use a more practical approach:
#!/usr/bin/perl -w
use strict;
my @Test = ("one", "two", "three");
print 'The number of elements is ', scalar(@Test);
-- Gordon
------------------------------
Date: Mon, 22 May 2000 15:29:04 -0500
From: "Andrew N. McGuire" <andrew.mcguire@walgreens.com>
Subject: Re: sorting a list of mixed numbers and text as in perldoc
Message-Id: <Pine.GSO.4.21.0005221524180.5490-100000@sputnik.corp.walgreens.com>
On Mon, 22 May 2000, Larry Rosler wrote:
+ In article <Pine.GSO.4.21.0005221149250.1017-
+ 100000@sputnik.corp.walgreens.com> on Mon, 22 May 2000 11:52:32 -0500,
+ Andrew N. McGuire <andrew.mcguire@walgreens.com> says...
[ snip ]
+ #!/usr/local/bin/perl -w
+ use strict;
+
+ my @unsorted = qw[hi low 1 2 3 yo what's up dawg?];
+
+ my @sorted = map substr($_, 1 + rindex $_, "\0") => sort
+ map { (/(\d+)/ ? 0 . pack N => $1 : 1 . uc) . "\0$_" } @unsorted;
+
+ print "@unsorted\n@sorted\n";
Thank you, I knew there was a better way, I have not yet read your
paper on sorting in its entirety. I suppose if I had I would have
known that, unfortunately, I can only read so much at one time.
Regards,
anm
--
/*-------------------------------------------------------.
| Andrew N. McGuire |
| andrew.mcguire@walgreens.com |
`-------------------------------------------------------*/
------------------------------
Date: Mon, 22 May 2000 11:30:10 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: SQL newbie question
Message-Id: <39297CB2.4ED56728@My-Deja.com>
> SELECT * FROM exampletable
> WHERE * = $foo[1] AND $foo[2] etc..?
You cannot use '*'. You have to mention the column names
explicitly.
> If I want to return the rows where all the
> elements of @foo match at least one column
How will this ever be possible ? If @foo contained
values in a particular order then the select SQL statement
also should be able to obtain these columnar values
in that particular order. Or else the meaning of equality
would be ill defined.
---
------------------------------
Date: Mon, 22 May 2000 19:49:46 +0100
From: "Bagsy" <news@theedgeofpanic.freeserve.co.uk>
Subject: Re: SQL newbie question
Message-Id: <8gc0be$e30$1@news8.svr.pol.co.uk>
Makarand Kulkarni <makarand_kulkarni@My-Deja.com> wrote in message
news:39297CB2.4ED56728@My-Deja.com...
> > SELECT * FROM exampletable
> > WHERE * = $foo[1] AND $foo[2] etc..?
>
> You cannot use '*'. You have to mention the column names
> explicitly.
Really? Can I use "*" in the SELECT statement though? Or not at all?
> > If I want to return the rows where all the
> > elements of @foo match at least one column
>
> How will this ever be possible ? If @foo contained
> values in a particular order then the select SQL statement
> also should be able to obtain these columnar values
> in that particular order. Or else the meaning of equality
> would be ill defined.
I'm not sure I follow you here. Excuse me if this is a stupid question
but I'll try to explain it better. I have an array which I am using to build
a statement so I can pass the "WHERE" clause as a variable like this;
SELECT * (if possible) FROM example
WHERE $argumentspecifics
...but I don't know exactly how to construct the conditions of the WHERE
clause. Basically I want check a number of words against each column in a
table (so that the first word is checked against every column, then the next
word is checked against every column etc.) and want the database to return
any row where all the words are found *somewhere* within a row, regardless
of which column they are found in. Is this impossible? I imagine it would be
something like this..
WHERE col1 OR col2 OR col3 = word1 AND col1 OR col2 OR col3 = word2
Is this the correct way to do it or am I barking up the wrong tree?
------------------------------
Date: 22 May 2000 19:22:55 GMT
From: newsposter@cthulhu.demon.nl
Subject: Re: SQL newbie question
Message-Id: <8gc1ef$4e0$1@internal-news.uu.net>
Bagsy <news@theedgeofpanic.freeserve.co.uk> wrote:
> Really? Can I use "*" in the SELECT statement though? Or not at all?
You can't use it in the WHERE clause.
> ...but I don't know exactly how to construct the conditions of the WHERE
> clause. Basically I want check a number of words against each column in a
> table
You're trying to do something like:
WHERE col1 IN ('a','b','c') OR
col2 IN ('a','b','c') OR
...
coln IN ('a','b','c');
?
But you'd be better of asking these kinds of questions in a newsgroup
discussing SQL, this doesn't seem to have any relevance to Perl ...
Erik
------------------------------
Date: Mon, 22 May 2000 19:46:21 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: the use of $_
Message-Id: <39298e8c.60bd$128@news.op.net>
In article <39281AD2.8B439E31@stomp.stomp.tokyo>,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>> Reason 7 is if you're stuck with perl 4. ''I am stuck with perl 4''
>> is never *good* reason to do *anything*, except maybe to cut your
>> wrists or something.
>
>Perl 4 is still currently shipped with some
>operating system packages and, Perl 4 concerns
>are posted here at times. Perl 4 is still quite
>viable and of concern to many. To shun posters
>here for use of Perl 4 or to shun those who are
>stuck with Perl 4, is most illogical, unrealistic
>and perhaps, an act of technological bigotry.
I didn't shun anybody; I didn't even go so far as to call anyone a
nasty name, like 'illogical unrealistic bigot'. I just said that
perl4 was a bad reason to do something.
>Perl 4 is the foundation of Perl 5, yes?
Whatever the heck that means.
------------------------------
Date: Mon, 22 May 2000 12:58:17 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: the use of $_
Message-Id: <39299159.FE4AEEA@stomp.stomp.tokyo>
Mark-Jason Dominus wrote:
> In article <39281AD2.8B439E31@stomp.stomp.tokyo>,
> Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
> I didn't shun anybody; I didn't even go so far
> as to call anyone a nasty name, like
> 'illogical unrealistic bigot'....
(snipped here and there, context retained)
I did not say this. You did. Deliberate
misquotation of a person is to tell a
lie. In that you have elected to lie,
your credibility is reduced to zero.
I am insulted by this type of lying.
This is personally offensive and
malice intent abuse on your part.
Godzilla!
------------------------------
Date: 22 May 2000 20:04:45 GMT
From: mbadolato@quepasa.com (Mark Badolato)
Subject: Re: the use of $_
Message-Id: <8F3C83B55mbadolatoquepasacom@206.165.3.80>
godzilla@stomp.stomp.tokyo (Godzilla!) wrote in
<39299159.FE4AEEA@stomp.stomp.tokyo>:
>Mark-Jason Dominus wrote:
>
>> In article <39281AD2.8B439E31@stomp.stomp.tokyo>,
>> Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>
>> I didn't shun anybody; I didn't even go so far
>> as to call anyone a nasty name, like
>> 'illogical unrealistic bigot'....
>I did not say this.
You most certainly did:
:: stuck with Perl 4, is most illogical, unrealistic
:: and perhaps, an act of technological bigotry.
The least you could do is instruct the voices in your head to send
memo's to each other detailing the various ramblings that they spew
forth.
--mark
------------------------------
Date: Mon, 22 May 2000 13:09:01 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: the use of $_
Message-Id: <392993DD.AD58950C@stomp.stomp.tokyo>
Mark Badolato wrote:
>
> godzilla@stomp.stomp.tokyo (Godzilla!) wrote in
> <39299159.FE4AEEA@stomp.stomp.tokyo>:
> >Mark-Jason Dominus wrote:
> >
> >> Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
> >> I didn't shun anybody; I didn't even go so far
> >> as to call anyone a nasty name, like
> >> 'illogical unrealistic bigot'....
> >I did not say this.
> You most certainly did:
> :: stuck with Perl 4, is most illogical, unrealistic
> :: and perhaps, an act of technological bigotry.
> The least you could do is instruct the voices in your head to send
> memo's to each other detailing the various ramblings that they spew
> forth.
I do not read where I said,
"illogical unrealistic bigot"
as I was quoted to have said.
Lies will get you nowhere with me.
Godzilla!
------------------------------
Date: 22 May 2000 20:20:37 GMT
From: perl_phreak@yahoo.com (Gordon Clemmons)
Subject: Re: the use of $_
Message-Id: <8F3C8ACD6nospamblahcom@206.165.3.70>
>godzilla@stomp.stomp.tokyo (Godzilla!) wrote:
>> You most certainly did:
>
>> :: stuck with Perl 4, is most illogical, unrealistic
>> :: and perhaps, an act of technological bigotry.
>
>> The least you could do is instruct the voices in your head to send
>> memo's to each other detailing the various ramblings that they spew
>> forth.
>
>
>I do not read where I said,
>
>"illogical unrealistic bigot"
>
>as I was quoted to have said.
>
>Lies will get you nowhere with me.
Wasn't that what Dr. Evil said? Or was that Darth Vader?
You must have an elaborate estate in the land of denial.
You are insinuating that Mark wants to get somewhere
with you, which is libelous and a defamation of his
character, both morally and intellectually (not to mention
sexually judging by the pictures I've seen). If you
continue this blatant assault on him as a person
and as a coder, blah blah blah.
:)
-- Gordon
------------------------------
Date: Mon, 22 May 2000 12:34:48 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: updated : Re: regexes *sigh* damn I hate these things
Message-Id: <MPG.13932baf62cd1b3a98aaae@nntp.hpl.hp.com>
In article <3928fc88.4177870@news.skynet.be> on Mon, 22 May 2000
09:56:13 GMT, Bart Lateur <bart.lateur@skynet.be> says...
> The WebDragon wrote:
...
> >I don't quite understand how to tell the regex that - is a valid 'word'
> >character, so that it will find the utother/fire-logo-map.zip as well as
> >utdm/DM-Halls_of_redemption.zip
>
> You can't, AFAIK. It's a pity. "locale" seems to be doing it, but you
> can't do it as a common user. Currently the best solution (5.6 may
> provide features, but I consider it not Ready For The World just yet) is
> to use a character class; possibly, for readability, you can put it in a
> variable and use that variable in the regex -- don't forget the //o
> switch.
>
> $w = "[a-zA-Z0-9_\\-\\.]";
Why not let 'locale' do it, then? Note the single-quotes and no
escaping in the character class:
$w = '[\w.-]';
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 22 May 2000 20:06:33 GMT
From: abigail@foad.org (Abigail)
Subject: Re: updated : Re: regexes *sigh* damn I hate these things
Message-Id: <slrn8ij4q9.1bm.abigail@ucan.foad.org>
On 21 May 2000 08:05:03 GMT, The WebDragon <nospam@devnull.com> wrote:
++ the problem has become more complex than it was.
Perhaps it's a good idea to actually write down a specification
instead of using trial-and-error-and-start-over-again-on-each-next-example.
Abigail
------------------------------
Date: Mon, 22 May 2000 09:04:33 +0200
From: Christian Winter <thepoet1@arcormail.de>
Subject: Re: valid email address
Message-Id: <16mag8.83h.ln@usenet-autoren.de>
Christian Winter <thepoet1@arcormail.de> schrob:
> ... map{ ($addr =~ /$_$/i)?1:0) } @a) > 0) {
^^^
This should be @tld, I should look better what I name it
when cut'n'pasting. But at least it's tested ;-)
Regards
Christian
But at least it's tested ;-)
Regards
Christian
------------------------------
Date: 22 May 2000 20:39:59 GMT
From: msouth@fulcrum.org
Subject: Visibility of package lexicals in debugger
Message-Id: <8gc5uv$sme$1@inxs.ncren.net>
I found the behaviour below surprising. This may represent some
misunderstading of scopeing or the debugger or both--I would
appreciate if anyone can clarify for me.
The summary is like this. In Foo.pm (which happens to define a
class) I have a (I think the correct term is) package-scoped lexical
declared with my(). It's called $package_lexical--here is the whole
module:
##########
# Foo.pm #
##########
#!perl -w
use strict;
use lib qw/./;
package Foo;
my $package_lexical = 'foo';
sub new {
my $class = shift;
#return bless {pl=>\$package_lexical}, $class;
return bless {}, $class;
}
sub yelp {
my $self = shift;
#print "${$self->{pl}}\n";
print "$package_lexical\n";
}
1;
Now, everything works as I expect it to when I use this module
in a test script, uf.pl, which looks like this:
##########
# uf.pl #
##########
#!/usr/bin/perl -w
use strict;
use lib qw/./;
use Foo;
my $foo = new Foo;
$foo->yelp;
For example:
south 195% perl uf.pl
foo
This is what I expect--in Foo::yelp $package_lexical is visible.
However, when I run it through the debugger, $package_lexical seems
to be visible (to the debugger) only while stepping through subroutines
where it is explicitly referenced:
Start the debugger:
south 196% perl -d uf.pl
Loading DB routines from perl5db.pl version 1.0402
Emacs support available.
Enter h or `h h' for help.
Step into Foo::new:
main::(uf.pl:4): my $foo = new Foo;
DB<1> s
Foo::new(Foo.pm:10): my $class = shift;
Now we're in the function Foo::new. I would think that
$package_lexical would be visible from here, but
DB<1> x $package_lexical
0 undef
Why is that undef?
Go back to uf.pl:
DB<2> r
scalar context return from Foo::new: empty hash
Step into Foo::yelp:
main::(uf.pl:5): $foo->yelp;
DB<2> s
Foo::yelp(Foo.pm:16): my $self = shift;
And it does what I would have expected the other to
do:
DB<2> x $package_lexical
0 'foo'
In Foo.pm, there are two commented-out lines of code that
reverse the situation if you swap their comment-ness with
their neighbors. That is, if you change new() so that it
stores a reference to $package_local in the returned
object, then you will see 'foo' for "x $package_lexical"
when the debugger is in new(). And if you then also
comment out the explicit reference to $package_lexical
in Foo::yelp, (regardless of whether you put in
the code next to it that deref's the object's pointer
to it), you get "undef" for "x $package_lexical" when
the debugger is in yelp() (although uf.pl doesn't
perform any differently--yelp() still prints 'foo').
Just for the record, what I was expecting was that
any time the debugger is in a subroutine that is
in the package, the debugger would be able to see
any package-scoped lexicals regardless of whether
the subroutine referred to those lexicals
explicitly or not.
Thanks for any light you can shed on this for me.
mike
--
Michael South | http://fulcrum.org
Head Mathophile, | 101 Canyon Run
fulcrum.org | Cary NC 27513 USA
(msouth@fulcrum.org) | (919) 465-9074
------------------------------
Date: Mon, 22 May 2000 14:29:58 -0400
From: "Zowwie" <apage.net[remove]@usa.net>
Subject: Re: Windows/Linux Incompatibility
Message-Id: <siiv4v37o153@corp.supernews.com>
I have also seen this problem before....
If stripping or chomp doesn't cure your problem... Try this.
Rather than copy the files to a floppy, or copy via samba(SMB) to the Linux
machine.... Fire up the FTP server on the Linux box.
Then... from the windows machine go to the command prompt and follow these
steps:
ftp ftp.linux.org
Login
navigate to your directory
type ASCII
then type mput *.*
OR
If you have allot of directories... Use a good FTP program.
You may have to go into the options of said program and tell it that .txt,
.pl, .cgi and other extensions are ASCII files... And not to send them as
binary.
Try WSFTP
Good luck!
nobull@mail.com wrote in message ...
>"Blair Heuer" <ab@cd.com> writes:
>
>> I have only programmed perl for and on Windows machines, but today my
server
>> administrator switched the server to Linux. ( Hooray for Linux! )
>
>> I have narrowed the problem down to being that the script leaves a return
of
>> some sort after every variable which are taken from a file which
seperates
>> variables by line. The code is then chomped, so it should not have any
>> problems, right?
>
>Looks like you forget to transfer the files as text when you copied
>them from Windows to Unix.
>
>chomp() does the right thing for the platform it's running on. It
>does not cope with text files copied as binary from a different
>platform.
>
>--
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
------------------------------
Date: Mon, 22 May 2000 21:40:18 GMT
From: "Blair Heuer" <ab@cd.com>
Subject: Re: Windows/Linux Incompatibility
Message-Id: <6PhW4.17773$S31.433508@newsread2.prod.itd.earthlink.net>
> You might try stripping control-M characters as you read the prefs file.
> Windows files have different end-of-line markers than UNIX files. This
could
> be causing problems. I don't believe chomp() will strip both the control-M
> and the \n.
Thank you very much! That seems to be exactly what my problem was. The
script is now functioning wonderfully with the addition of that simple line
to remove the control-M characters.
- Blair Heuer
------------------------------
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 3127
**************************************