[16484] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3896 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 3 00:10:26 2000

Date: Wed, 2 Aug 2000 21:10:14 -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: <965275814-v9-i3896@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 2 Aug 2000     Volume: 9 Number: 3896

Today's topics:
        returning an array <ab@cd.com>
    Re: Same data accesed twice? (cleaned up code) <pking@idirect.com>
    Re: splitting on spaces <elephant@squirrelgroup.com>
    Re: splitting on spaces (NP)
    Re: splitting on spaces <elephant@squirrelgroup.com>
    Re: splitting on spaces (NP)
    Re: String to Integer (Gwyn Judd)
    Re: Subclassing an opaque class (Damian Conway)
    Re: Tie, invalid argument <bwalton@rochester.rr.com>
    Re: uuuuuuuAaron Kulkis is a Communist Buttfucker <Odious@home.com>
    Re: Value of undefined variable in activeperl (Keith Calvert Ivey)
    Re: very cool routine <newt@veko.ne.mediaone.net>
    Re: What happened to $fh->input_record_separator ? (Tom Christiansen)
    Re: What happened to $fh->input_record_separator ? (Andrew J. Perrin)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 03 Aug 2000 03:46:49 GMT
From: "Blair Heuer" <ab@cd.com>
Subject: returning an array
Message-Id: <JW5i5.4588$0W4.156550@newsread2.prod.itd.earthlink.net>

A script I am writing uses a database to handle all data and to simplify
coding, I decided to use a function for getting the data to save on space
and readability. The problem is, when I get the data it is returned in an
array of hashes, but I can't figure out how to return an array. Using:
<code> return @return; </code> only returns the number of elements in the
array. Using <code> return "@return"; </code> returns the value flat as a
string, not allowing for more than one data item to be loaded.

So the question: How do I return an array? Should I use references somehow?
Also, would returning a hash follow the same methods.

Here is the code used (it still needs to handle differentiating between
returning an array or hash, but it should only return an array of at least
one element):

<code>

# Get Data Routine
sub gd() {
    my ( $table, $select, $where ) = @_;
    my ( @return, $load );

    $load = $db->prepare( "SELECT $select FROM $table WHERE $where;" );
    $load->execute;

    if ( $select eq '*' or $select =~ /,/) {
        while ( $data = $load->fetchrow_hashref ) { push ( @return,
$data ); }
    } else { $return[0] = $load->fetchrow_array; }

    $load->finish;

    return @return; # Here is the trouble spot

}

# Sample Calls
  $t{'board_last'} = &gd( 'posts', 'max(post_date)',
"board_id=$t{'board_id'}" );
  @posts = &gd( 'posts', '*', "board_id=$t{'board_id'} AND
post_date='$t{'board_last'}';" );
  %post = &gd( 'posts', '*', "board_id=$t{'board_id'} AND
topic_id=$t{'topic_id'} AND post_id=$t{'post_id'};" );

</code>

Thanks a ton,
Blair




------------------------------

Date: Thu, 03 Aug 2000 03:23:15 GMT
From: Paul King <pking@idirect.com>
Subject: Re: Same data accesed twice? (cleaned up code)
Message-Id: <3988E5D2.7408F38D@idirect.com>

"Mike King @work" wrote:

> Debjit wrote:
> >
> > Did u try printing the sql and try it from sql prompt?
>
> or maybe using $dbh->errstr to find out if SQL is complaining about
> anything?
>
> -Mike

Yeah, I did both. SQL was quiet (no complaining), but a look  into the
database
itself revealed simply bad data. The problem has been fixed. Thanks.

Paul King



------------------------------

Date: Thu, 03 Aug 2000 01:11:31 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: splitting on spaces
Message-Id: <MPG.13f364285492f1db9896b5@news>

Logan Shaw writes ..
>In article <8m9arg$ifa$1@lublin.zrz.tu-berlin.de>,
>Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>>Hang around a bit.  The term "jeopardy posting" (and implicitly
>>"jeopardectomy") are explained about twice or three times a week.
>
>They are?  I've been on Usenet since 1990, and I can't recall
>ever having seen it before.  (Or are you saying they're explained on
>comp.lang.perl.misc every week?)

just because you don't recall seeing an explanation doesn't appear to 
mean much .. a quick search for "jeopardy style" on Deja will set you 
straight

being explained in c.l.p.misc every week (a tigher requirement than that 
of being explained every week in the whole usenet) would probably be a 
reach - certainly it's referred to at least once a week .. but I don't 
know about it being explained

-- 
  jason -- elephant@squirrelgroup.com --


------------------------------

Date: Thu, 03 Aug 2000 03:06:26 GMT
From: nvp@spamnothanks.speakeasy.org (NP)
Subject: Re: splitting on spaces
Message-Id: <Sk5i5.416006$MB.6455574@news6.giganews.com>

On Thu, 03 Aug 2000 01:11:31 GMT, jason <elephant@squirrelgroup.com> wrote:
: Logan Shaw writes ..
: >
: >They are?  I've been on Usenet since 1990, and I can't recall
: >ever having seen it before.  (Or are you saying they're explained on
: >comp.lang.perl.misc every week?)
: 
: just because you don't recall seeing an explanation doesn't appear to 
: mean much .. a quick search for "jeopardy style" on Deja will set you 
: straight

What the poster was pointing out is that he didn't see these rules
covered as part of *netiquette* (on the whole).  True, a newsgroup can
set its own definition of acceptable styles and it would be more than
helpful to post these guidelines to news.answers -- but I don't recall
seeing any such document there.  Don't forget that there are still
some people who refer to news.* before posting anything.  :-)

-- 
Nate II



------------------------------

Date: Thu, 03 Aug 2000 03:18:48 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: splitting on spaces
Message-Id: <MPG.13f381f58d444fe29896ba@news>

NP writes ..
>On Thu, 03 Aug 2000 01:11:31 GMT, jason <elephant@squirrelgroup.com> wrote:
>: Logan Shaw writes ..
>: >
>: >They are?  I've been on Usenet since 1990, and I can't recall
>: >ever having seen it before.  (Or are you saying they're explained on
>: >comp.lang.perl.misc every week?)
>: 
>: just because you don't recall seeing an explanation doesn't appear to 
>: mean much .. a quick search for "jeopardy style" on Deja will set you 
>: straight
>
>What the poster was pointing out is that he didn't see these rules
>covered as part of *netiquette* (on the whole).

then they should have said as much .. expanding their pronoun - they 
said that they couldn't recall ever having seen an explanation of 
"jeopardy" before

>True, a newsgroup can
>set its own definition of acceptable styles and it would be more than
>helpful to post these guidelines to news.answers -- but I don't recall
>seeing any such document there.  Don't forget that there are still
>some people who refer to news.* before posting anything.  :-)

I'm not commenting on that .. because I do think that it's a little 
rough to expect someone to be aware that interleaved posting or bottom-
posting is the accepted way to post on usenet .. because there is no 
clear mention in the FAQs that I've seen either

to this group's credit I rarely see jeopardy style treated with complete 
contempt .. usually it is remarked upon and often a small explanation 
accompanies that remark .. but rarely is it treated with the same 
despairing contempt as someone asking a Perl FAQ .. or an off-topic 
question

with that as my only evidence I would propose that this group does not 
judge the jeopardists harshly .. nor does it expect people to get it 
right first time .. people don't get plonked for jeopardising (I'm 
enjoying these jeopardy based words immensely) as they certainly do for 
asking FAQs and OT questions (has anyone coined OTQ yet ?)

anyway .. I was correctly pointing out that Logan's recollection should 
not carry much weight because the term is certainly explained at least 
weekly .. possibly weekly in this group alone

-- 
  jason -- elephant@squirrelgroup.com --


------------------------------

Date: Thu, 03 Aug 2000 03:45:31 GMT
From: nvp@spamnothanks.speakeasy.org (NP)
Subject: Re: splitting on spaces
Message-Id: <vV5i5.416075$MB.6457960@news6.giganews.com>

On Thu, 03 Aug 2000 03:18:48 GMT, jason <elephant@squirrelgroup.com> wrote:
: 
: then they should have said as much .. expanding their pronoun - they 
: said that they couldn't recall ever having seen an explanation of 
: "jeopardy" before

He said that he'd be on USENET since 1990, and that he'd never heard of
"jeopardy" before.  From that, I thought the inference (that he was
looking to the USENET FAQs for an explanation of "jeopardy" and didn't
find one) was clear.

: I'm not commenting on that .. because I do think that it's a little 
: rough to expect someone to be aware that interleaved posting or bottom-
: posting is the accepted way to post on usenet .. because there is no 
: clear mention in the FAQs that I've seen either

Exactly.  In fact, I do recall reading that a person can place new
materials before *or* after quoted materials as long as the content has
been trimmed down.  After re-reading the (USENET) FAQs tonight, it
seems that there really isn't One True Way to deal with quoted
materials as long as (a) the posting doesn't use overquoting and (b)
the posting doesn't become unreadable because of quoted characters or
word wrapping.

: to this group's credit I rarely see jeopardy style treated with complete 
: contempt .. usually it is remarked upon and often a small explanation 
: accompanies that remark .. but rarely is it treated with the same 

Actually, most people in this newsgroup seem to put quoted materials
before new comments -- which is good and clear to read.

-- 
Nate II



------------------------------

Date: Thu, 03 Aug 2000 01:30:28 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: String to Integer
Message-Id: <slrn8ohiph.fp5.tjla@thislove.dyndns.org>

I was shocked! How could Larry Rosler <lr@hpl.hp.com>
say such a terrible thing:
>In article <39887CB3.2A2028BB@netstorm.net> on Wed, 02 Aug 2000 19:57:50 
>GMT, Jim Mauldin <mauldin@netstorm.net> says...
>> Drew Simonis wrote:
>> > 
>> > Greg Bacon wrote:
>> > >
>> > > You want a decimal coding (dc).  Get that in Perl with
>
>> > >     $blah = "123456";
>> > >     $blah =~ tr/0123456789//dc;  # <- note the dc

>Jim and Drew,
>
>Did you really miss the implicit smiley in the nonsense highlighted 
>above?
>
>Greg was producing a Perl Bowling no-op.
>
>Consider yourselves to have been had!  :-)

It's not a no-op Larry :)

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
People will buy anything that's one to a customer.


------------------------------

Date: 3 Aug 2000 03:54:44 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Subclassing an opaque class
Message-Id: <8maqe3$lm0$1@towncrier.cc.monash.edu.au>

Bob Glickstein <bobg@moonbase.zanshin.com> writes:

>When I subclass someone else's class, how can I add my own instance
>variables?

>When I subclass my own class, I simply do this:
	[SNIP]
>because I know the composition of a MySuperclass object.  But when the
>superclass is someone else's, $self may not be a HASH reference at
>all; and if it is, `sub_instance_var' may collide with a member
>already in the HASH.

You are correct. Unfortunately there is no sure-fire way to do
inheritance of an arbitrary Perl class without knowing what's
going on inside it.

One way around the problem is to use aggregation rather than inheritance:

	package MySubclass;

	sub new {
		my ($class, @args) = @_;
		my $self = { base => new MySuperclass(@args) };
		$self->{sub_instance_var} = $whatever;
		bless $self, $class;
	}

	# Forward unknown methods to base class object...
	sub AUTOLOAD {
		my $self = shift;
		$AUTOLOAD =~ s/.*:://;
		$self->{base}->$AUTOLOAD(@_);
	}



Damian


------------------------------

Date: Thu, 03 Aug 2000 03:29:31 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Tie, invalid argument
Message-Id: <3988E753.446D0E30@rochester.rr.com>

Michiel Dethmers wrote:
 ...
> I'm trying to read a file but I get "invalid argument". The docs say
> that this can be anything, which is not very helpful.
> 
> I have a .db file which has been created by a dbmopen.
> 
> if I do
> use NDBM_File;
> tie %DB,"NDBM_File","filename",O_RDWR|_CREAT,0640 or die $!
> it dies with "Invalid argument"
> 
> does this mean my data is corrupt?
> (by the way, dbmopen dies with the same error)
> Any replied please by email, as I don't read this group too often.
 ...
> Michiel

Well, it might help if you spelled O_CREAT correctly.  You left out the
O.


------------------------------

Date: Thu, 03 Aug 2000 03:11:44 GMT
From: Odious <Odious@home.com>
Subject: Re: uuuuuuuAaron Kulkis is a Communist Buttfucker
Message-Id: <3988E346.2E6BF2C6@home.com>



No User wrote:
> 
> uuuuuuu  He is, man. What more can I say?
> 


Hey now, come on....aaron is not a communist.

-- 
The Spiffy Page: Home of the Ask Odious seduction advice column.
http://members.home.net/odious


------------------------------

Date: Thu, 03 Aug 2000 01:30:13 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Value of undefined variable in activeperl
Message-Id: <398fca3a.5025026@news.newsguy.com>

"Klaus Lyngsoe" <klaus@whitehat.dk> wrote:

>I have crypted my users password like this:
>$cryptpass = crypt ($password, $salt);
>
>The problem is that I did not give $salt any value before using it to
>encrypt the password. It works fine in active perl, but returns $cryptpass
>with no value on the linux-server. I believe it means that an undefined $var
>has a value in activeperl.
>
>Can anybody help me out and tell me what that value of an undefined $salt in
>activeperl is ?

C:\TEMP>perl -e"print crypt('foo', undef)"
AAWTPsRihC6Ok
C:\TEMP>perl -e"print crypt('barbaz', undef)"
AAlSlrltM/onw
C:\TEMP>perl -e"print crypt('barbaz', 'AA')"
AAlSlrltM/onw

Looks like it's "AA" -- the salt is the first two characters of
the encrypted string.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


------------------------------

Date: Thu, 03 Aug 2000 02:38:55 GMT
From: <newt@veko.ne.mediaone.net>
Subject: Re: very cool routine
Message-Id: <3X4i5.1391$pu4.133326@typhoon.ne.mediaone.net>

Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
> Robin Bank wrote:

>> C is fast.
>> PERL is comparably extremely slow.
>> Copiler VS Interpreter

> Ummm... Mr. Bank, I really must object. If you employ
> good logic, cite truisms, state facts and debate issues
> based on rational thinking, these people, well... their
> brains will explode. 

Hey, waitasec ... wasn't he just regurgitating what "these people" were
telling him all along?  How did "their" words become facts and rational
thoughts (not so sure about that truism stuff) by coming out of his,
er, mouth ...

Shoot.  Did I just get trolled? I just got trolled ...

Nevermind. I now return you back to your regularly scheduled newsgroup,
already in session.

>PLONK<


------------------------------

Date: 2 Aug 2000 20:36:00 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: What happened to $fh->input_record_separator ?
Message-Id: <3988da90$1@cs.colorado.edu>

In article <87snsn5mk6.fsf@achebe.perrins>,
Andrew J. Perrin <aperrin@demog.berkeley.edu> wrote:
>Greetings. I just loaded 5.6.0 (using linux/debian), and the following
>code snippet is now broken:
>
>...
>my $fh = new FileHandle($fn);
>$fh->input_record_separator('#---#---#---#');
>...
>
>The error msg is:
>
>input_record_separator is not supported on a per-handle basis 
>
>I can't find mention of this in perldiag or perldoc FileHandle.  What
>happened? How can I have similar functionality?

Camel 3 reads, in the documentation on FileHandle in the stdlibs chapter:

    Currently, three methods (C<output_field_separator>,
    C<output_record_separator>, and C<input_record_separator>) only
    pretend to be per-handle methods: setting them on one handle
    actually affects all filehandles. They are therefore only
    supported as class methods, not as per-filehandle methods.  This
    restriction may be lifted someday.

--tom


------------------------------

Date: 02 Aug 2000 23:23:03 -0500
From: aperrin@demog.berkeley.edu (Andrew J. Perrin)
Subject: Re: What happened to $fh->input_record_separator ?
Message-Id: <87u2d3km6w.fsf@achebe.perrins>

tchrist@perl.com (Tom Christiansen) writes:

> Camel 3 reads, in the documentation on FileHandle in the stdlibs chapter:
> 
>     Currently, three methods (C<output_field_separator>,
>     C<output_record_separator>, and C<input_record_separator>) only
>     pretend to be per-handle methods: setting them on one handle
>     actually affects all filehandles. They are therefore only
>     supported as class methods, not as per-filehandle methods.  This
>     restriction may be lifted someday.
> 
> --tom

Okay... did I miss this in perldoc, or is it only in the dead-tree edition?

Also, I tried what perldoc suggests (e.g., calling the method on a
FileHandle object) as well as:

input_record_separator $fh "..."
and
FileHandle::input_record_separator "..."

both of which failed completely.  The only thing I could make work was
the old-fashioned:

local($/) = "...";

I find it rather hard to believe that this is really a bug - can
someone post code that successfully uses the input_record_separator
method of the FileHandle package in 5.6.0?

Thanks.
Andy Perrin


------------------------------

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 3896
**************************************


home help back first fref pref prev next nref lref last post