[19301] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1496 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 11 14:05:27 2001

Date: Sat, 11 Aug 2001 11:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <997553107-v10-i1496@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 11 Aug 2001     Volume: 10 Number: 1496

Today's topics:
    Re: Encrypted Email (Anno Siegel)
    Re: how to verify $dir is null <gnarinn@hotmail.com>
    Re: Is regex in grep() automatically precompiled? (Malcolm Dew-Jones)
        Modem::Vgetty (Newbie) (Mike)
        Need help with CGI.pm... <viper16336@mindspring.com>
    Re: Need help with CGI.pm... <ayamanita.nospam@bigfoot.com>
    Re: permuting extremely large string <andras@mortgagestats.com>
    Re: permuting extremely large string <andras@mortgagestats.com>
    Re: permuting extremely large string <godzilla@stomp.stomp.tokyo>
    Re: permuting extremely large string <godzilla@stomp.stomp.tokyo>
    Re: permuting extremely large string (Anno Siegel)
    Re: permuting extremely large string (Anno Siegel)
    Re: permuting extremely large string <andras@mortgagestats.com>
    Re: permuting extremely large string <andras@mortgagestats.com>
    Re: stat() in W98SE (Tad McClellan)
    Re: stat() in W98SE <pne-news-20010811@newton.digitalspace.net>
    Re: Sub that defaults to use $_ in callers context (Anno Siegel)
        Too stupid for a simple CORE::GLOBAL:: export <murat.uenalan@gmx.de>
    Re: tricky Question (Tad McClellan)
    Re: voodoo cookie hash problem (Mongo)
        What happened to the first element of my arrray? <Pcmann1@btinternet.com>
    Re: What happened to the first element of my arrray? <pne-news-20010811@newton.digitalspace.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 11 Aug 2001 17:56:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Encrypted Email
Message-Id: <9l3rk4$cm5$1@mamenchi.zrz.TU-Berlin.DE>

According to Jeff Snoxell <Jeff@aetherweb.co.uk>:
> Hi,
> 
> Thanks for everyone's help with my BigInt and other problems.
> 
> I'm still no closer to a solution however.
> 
> I need a way to send 128-bit (minimum) encrypted emails from my ISP's linux
> server to my Outlook Express inbox. I have CGI and FTP access to the server
> but I don't have telnet and hence cannot easily install modules (I never
> seem to have any luck with installing modules even when I do have telnet
> access). I'm willing to spend a small amount of money to register some
> shareware if necessary.

 ...which you would install how?

Get an environment where you can install the necessary encryption-
and mailing-modules.  Building your own encryption is futile, not
because it's inherently hard, but because it must be bug-free, and
that is always hard.

> Please help, I've been stuck on this problem for 48 hours now and my mind is
> melting.

Oh my!

Anno


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

Date: Sat, 11 Aug 2001 16:10:04 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: how to verify $dir is null
Message-Id: <997546204.773424624465406.gnarinn@hotmail.com>

In article <3B7448C2.7060605@bellatlantic.net>,
Hong Hsu  <honghsu@bellatlantic.net> wrote:
>
>This is a simple question.   how to verify the $dir is uninitialized?
>The following code just doesn't work.
>...
>my $dir = $ARGV[0];
>my $currentdir = `pwd`;
>print "current working directory: $currentdir\n";
>if($dir eq "")
>{
>   $dir = $currentdir;
>}
>else
>{
>   ...
>}
>

define "doesn't work"
(apart the '...' of course)

gnari



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

Date: 11 Aug 2001 10:48:36 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Is regex in grep() automatically precompiled?
Message-Id: <3b756ff4@news.victoria.tc.ca>

David Combs (dkcombs@panix.com) wrote:
: In article <t4dimt45ecgduqld8r6h04sm0dacdu09v4@4ax.com>,
: Bart Lateur  <bart.lateur@skynet.be> wrote:
:  ...
: >.... Even then, you can always fall back on
: >generating a sub on the fly, from a string:
: >
: >	my $grep = eval 'sub { grep /$pat/o, @_ }'

:                    ^^^^^^^^^^^^

: >	  or die "Cannot eval grep sub: $@";
: >	@result = $grep->(@array);
: >

: PLEASE explain that eval on what I guess is a ref
: to an anon sub.

What's being eval'd is NOT a ref to an anonymous sub.
What's being eval'd is a string.

When the string is eval'd then the code in the string is run.  In
this case the text is a perl snippet that creates an anonymous sub.

The sub includes a regex that is compiled *just once*.  Normally this
means that you cannot change the value of $pat, because the regex will not
see the changes.

However, when the eval is rerun then a whole new regex is created using
the new value of $pat.  This allows you to combine the /o feature of m//
with variables that may change their values from time to time. 

Having said that, I have questions about the single quotes.  The variable
is not being interpolated into the eval'd string, instead the value of
$pat must be resolved sometime later, and I wonder about what value $pat
will get and whether everything will be recompiled. (since the eval'd
string is a constant)

(It may be fine)

I have always used this like so

	my $p = quotemeta($pat);
	my $grep = eval "sub { grep /$p/o, @_ }"


: WHAT gets assigned into $grep?

a ref to a sub that can be run (something like) like &$grep(...) 

: >Note that the first time you call the $grep sub (*with* a parameter),
: >should be in the scope of $pat, perhaps like this:
: >
: >	$grep->("");
: >

(Ah, he's answering my own questions from above - I should have read this
more thoroughly first.)




--
Want to access the command line of your CGI account?  Need to debug your
installed CGI scripts?  Transfer and edit files right from your browser? 

What you need is "ispy.cgi" - visit http://nisoftware.com/ispy.cgi


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

Date: 11 Aug 2001 08:05:34 -0700
From: mikekh123@yahoo.com (Mike)
Subject: Modem::Vgetty (Newbie)
Message-Id: <cd3e8552.0108110705.1c96c0ef@posting.google.com>

hi,
I'm trying to use Modem::Vgetty and I can't even get the exampel code
that comes with the module to work!

I have this code
----------
#!/usr/bin/perl   -w
use Modem::Vgetty;
$v = new Modem::Vgetty();
$v->add_handler('BUSY_TONE', 'endh', sub { $v->stop; exit(0); });
local $SIG{ALRM} = sub { $v->stop; };
$v->enable_events;
$v->record('/tmp/hello.rmd');
alarm(20);
$v->waitfor('READY');
$v->shutdown;
-------------

And get this error

"can't call method "add_handler" on an undefined value at .test.pl
line 4"

Can anyone help ??

Thx
Mike


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

Date: Sat, 11 Aug 2001 10:08:07 +0100
From: "Stephen Edelblut" <viper16336@mindspring.com>
Subject: Need help with CGI.pm...
Message-Id: <9l3i05$iiu$1@slb5.atl.mindspring.net>

What is wrong with this:
print $q->start_html(-head=>meta({-http_equiv=>'refresh',
content=>'3;url=>../www/file.txt'})),

Thank you.




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

Date: Sat, 11 Aug 2001 15:35:01 GMT
From: Akira Yamanita <ayamanita.nospam@bigfoot.com>
Subject: Re: Need help with CGI.pm...
Message-Id: <3B75508E.273A85D0@bigfoot.com>

Stephen Edelblut wrote:
> 
> What is wrong with this:
> print $q->start_html(-head=>meta({-http_equiv=>'refresh',
> content=>'3;url=>../www/file.txt'})),

It won't compile? :) Anyway, this should help you out.

From perldoc CGI:

There is no support for the HTTP-EQUIV type of <META> tag.
This is because you can modify the HTTP header directly
with the header() method.  For example, if you want to
send the Refresh: header, do it in the header() method:

print $q->header(-Refresh=>'10; URL=http://www.capricorn.com');


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

Date: Sat, 11 Aug 2001 09:48:06 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: permuting extremely large string
Message-Id: <3B753796.70305B0F@mortgagestats.com>



"Godzilla!" wrote:

> John W. Krahn wrote:
>
>
>
> > I don't know if this is faster but it's shorter.
>
> > sub perm_string {
> >     my $str_ref = shift;
> >     my $len = length $$str_ref;
>
> You need to add  $$str_ref = \$str_ref  in an appropriate
> code line position. Doing this just might enable your code
> to work correctly rather than producing all zeroes and
> no references.

Most of us, unlike you, Godzilla, have grasped the implied fact that $str_ref is
meant to contain a string reference rather than a string itself. Once again, you
failed to ask yourself this simple question before posting: "Am I assuming that the
OP is an idiot?" Make sure the answer to that question is "no" before you embarrass
yourself again.


> Use of shift @_ would be helpful as well.

Why?



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

Date: Sat, 11 Aug 2001 10:18:38 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: permuting extremely large string
Message-Id: <3B753EBD.209D50BD@mortgagestats.com>



Les Ander wrote:

> Hi,
> i need to permute a string which is about 4 Mb!
> I experience  memory problems if i convert it to an array (the program
> crashes). So I need to permute the string inplace without converting
> it into an array.
> A simple strategy i am thinking of is follows...

[snip]

> it took about 45 seconds when i tried it on a string of length about
> 5,000,0000 characters.
> Is there a way to speed it up?
> also, can some one think of a better algorithm?
>

What difference can it possibly make?

A million-element set has easily more than 10^(10^6) permutations, so even
if you dramatically improve your algorithm and can generate a single
permutation in the time it takes light to traverse a hydrogen atom instead
of the current forty-five seconds, you are still looking at a computing
time way exceeding the age of the universe.

Why don't you tell us what original problem it is that you are trying to
solve: maybe you'll get some more helpful answers.





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

Date: Sat, 11 Aug 2001 07:20:53 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: permuting extremely large string
Message-Id: <3B753F45.79C5AF48@stomp.stomp.tokyo>

Andras Malatinszky wrote:
 
> Godzilla! wrote:
> > John W. Krahn wrote:

> > > I don't know if this is faster but it's shorter.

> > > sub perm_string {
> > >     my $str_ref = shift;
> > >     my $len = length $$str_ref;

> > You need to add  $$str_ref = \$str_ref  in an appropriate
> > code line position. Doing this just might enable your code
> > to work correctly rather than producing all zeroes and
> > no references.
 
> Most of us, unlike you, Godzilla, have grasped the implied fact that $str_ref is
> meant to contain a string reference rather than a string itself. Once again, you
> failed to ask yourself this simple question before posting: "Am I assuming that the
> OP is an idiot?" Make sure the answer to that question is "no" before you embarrass
> yourself again.
 

  "You need to add  $$str_ref = \$str_ref ...."


Are you the loving mouthpiece for the originating author?


  * amused *

How funny, The CLPM Troll being the loving mouthpiece for
himself under a fake name!


Godzilla!
--


#!perl

@_ = qw (Godzilla Rocks!);

my $str_ref = shift;
my ($len) = length $$str_ref;

if ($str_ref)
 { print "$str_ref\n"; }
else
 { print "Totally Duh!\n"; }

if ($$str_ref)
 { print "$$str_ref\n"; }
else
 { print "Totally Duh!\n"; }

if ($len)
 { print "$len\n"; }
else
 { print "Totally Duh!\n"; }


&Duh;

sub Duh
 {
  $str_ref = shift;
  my ($len) = length $$str_ref;

  if ($str_ref)
   { print "\n$str_ref  Whoa! There's Godzilla! She Rocks!\n\n"; }
  else
   { print "Totally Duh!\n"; }

  if ($$str_ref)
   { print "$$str_ref\n"; }
  else
   { print "Totally Duh!\n"; }

  if ($len)
   { print "$len\n"; }
  else
   { print "Totally Duh!\n"; }
 }

exit;


PRINTED RESULTS:
________________

Totally Duh!
Totally Duh!
Totally Duh!

Godzilla  Whoa! There's Godzilla! She Rocks!

Totally Duh!
Totally Duh!


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

Date: Sat, 11 Aug 2001 09:06:12 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: permuting extremely large string
Message-Id: <3B7557F4.4EED47E2@stomp.stomp.tokyo>

Godzilla! wrote:
 
> Andras Malatinszky wrote:
> > Godzilla! wrote:
> > > John W. Krahn wrote:

(snipped)
 
> > > > I don't know if this is faster but it's shorter.
 
> > > > sub perm_string {
> > > >     my $str_ref = shift;
> > > >     my $len = length $$str_ref;
 
> > > You need to add  $$str_ref = \$str_ref  in an appropriate
> > > code line position. Doing this just might enable your code
> > > to work correctly rather than producing all zeroes and
> > > no references.
 
> > Most of us, unlike you, Godzilla, have grasped the implied fact that $str_ref is
> > meant to contain a string reference rather than a string itself. Once again, you
> > failed to ask yourself this simple question before posting: "Am I assuming that the
> > OP is an idiot?" Make sure the answer to that question is "no" before you embarrass
> > yourself again.

> Are you the loving mouthpiece for the originating author?
 
>   * amused *

(snipped code sample)
 

What? No follow-up CLPM Troll article? My response have
you stumped? Are you incapable of understanding implied
deliberately vague parameters?

True problem here is you, as The CLPM Troll, are incapable
of posting clear, concise and coherent articles. At best,
you hold a tenuous grip on language usage. Your intellectual
skills are less than tenuous.

This is why I consider you to be a Mental Midget compared
to this Intellectual Giant I am.

There is zero need to create a string reference, there
is zero need to create @_ holding a string reference and,
there is zero need to use a sub-routine, as exemplified in
one of my articles posted in response to your original inane
troll article under one of your typical fake names.

As is customary for you as The CLPM Troll, you have created
both a problem and a solution, both of which are inanely
illogical, both of which are cumbersome, slow and inefficient.
As The CLPM Troll, you have further emphasized how poor are
your Perl skills and how poor is your thinking with this
most recent posted article as "Les Ander" and subsequent
fake name articles.

You play this vague implications game and yet are incapable
of deriving implied parameters of others, even well worded
and obvious implied parameters such as I posted.

Those of us whom are moderately intelligent, will quickly
realize all of what I have said is right on target after
a quick glance at my test code which directly implies
substantiating evidence.

Consider yourself to be once again made a moronic mark.

Godzilla!  Queen Of Con.
--

#!perl

$string = "Godzilla Rocks!";

$str_ref = \$string;

@_ = ($str_ref);

print "Totally Duh:\n\n";

&Totally_Duh;

sub Totally_Duh
 {
  $str_ref = shift;
  print "$str_ref\n";
  print $$str_ref;
 }


print "\n\n";


$string = "Godzilla Rocks!";
@_ = ($string);

print "Totally Logical:\n\n";

&Totally_Logical;

sub Totally_Logical
 { 
  print "$string\n";
  print "@_\n\n";
 }


print "Perfect Godzilla Logic:\n\n";

print $string;


exit;


PRINTED RESULTS:
________________


Totally Duh:

SCALAR(0x1a6527c)
Godzilla Rocks!

Totally Logical:

Godzilla Rocks!
Godzilla Rocks!

Perfect Godzilla Logic:

Godzilla Rocks!


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

Date: 11 Aug 2001 17:16:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: permuting extremely large string
Message-Id: <9l3p8l$ba9$1@mamenchi.zrz.TU-Berlin.DE>

According to Abigail <abigail@foad.org>:

[...]

> sub shuffle {
>     # No need to pass a reference - Perl passes by reference anyway.
>     local $_ = $_ [0];

But, but...  I'd be terribly mistaken if this didn't make a copy.
"local *_ = \ $_[0]" wouldn't.

Anno


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

Date: 11 Aug 2001 17:18:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: permuting extremely large string
Message-Id: <9l3pco$ba9$2@mamenchi.zrz.TU-Berlin.DE>

According to Andras Malatinszky  <andras@mortgagestats.com>:
> 
> 
> Les Ander wrote:
> 
> > Hi,
> > i need to permute a string which is about 4 Mb!
> > I experience  memory problems if i convert it to an array (the program
> > crashes). So I need to permute the string inplace without converting
> > it into an array.
> > A simple strategy i am thinking of is follows...
> 
> [snip]
> 
> > it took about 45 seconds when i tried it on a string of length about
> > 5,000,0000 characters.
> > Is there a way to speed it up?
> > also, can some one think of a better algorithm?
> >
> 
> What difference can it possibly make?
> 
> A million-element set has easily more than 10^(10^6) permutations, so even
> if you dramatically improve your algorithm and can generate a single
> permutation in the time it takes light to traverse a hydrogen atom instead
> of the current forty-five seconds, you are still looking at a computing
> time way exceeding the age of the universe.

He doesn't want all the permutations, just one (or a few) random ones.

Anno


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

Date: Sat, 11 Aug 2001 13:45:26 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: permuting extremely large string
Message-Id: <3B756F36.4A347F23@mortgagestats.com>



"Godzilla!" wrote:

[...]

> What? No follow-up CLPM Troll article? My response have
> you stumped? Are you incapable of understanding implied
> deliberately vague parameters?
>
> True problem here is you, as The CLPM Troll, are incapable
> of posting clear, concise and coherent articles. At best,
> you hold a tenuous grip on language usage. Your intellectual
> skills are less than tenuous.
>
> This is why I consider you to be a Mental Midget compared
> to this Intellectual Giant I am.

[...]

> As is customary for you as The CLPM Troll, you have created
> both a problem and a solution, both of which are inanely
> illogical, both of which are cumbersome, slow and inefficient.
> As The CLPM Troll, you have further emphasized how poor are
> your Perl skills and how poor is your thinking with this
> most recent posted article as "Les Ander" and subsequent
> fake name articles.

[...]

Yes, yes, I confess. There are only two people posting on this board: you,  Intellectual
Giant, and me, the CPLM Troll. All these hundreds of posts that you see here have been
singlehandedly posted by me, under fake names. And the purpose of this grand scheme? To
provide you with entertainment as you watch the Universe revolve around you.



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

Date: Sat, 11 Aug 2001 13:48:12 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: permuting extremely large string
Message-Id: <3B756FDC.4C5299E0@mortgagestats.com>



Anno Siegel wrote:

> According to Andras Malatinszky  <andras@mortgagestats.com>:
> >
> >
> > Les Ander wrote:
> >
> > > Hi,
> > > i need to permute a string which is about 4 Mb!
> > > I experience  memory problems if i convert it to an array (the program
> > > crashes). So I need to permute the string inplace without converting
> > > it into an array.
> > > A simple strategy i am thinking of is follows...
> >
> > [snip]
> >
> > > it took about 45 seconds when i tried it on a string of length about
> > > 5,000,0000 characters.
> > > Is there a way to speed it up?
> > > also, can some one think of a better algorithm?
> > >
> >
> > What difference can it possibly make?
> >
> > A million-element set has easily more than 10^(10^6) permutations, so even
> > if you dramatically improve your algorithm and can generate a single
> > permutation in the time it takes light to traverse a hydrogen atom instead
> > of the current forty-five seconds, you are still looking at a computing
> > time way exceeding the age of the universe.
>
> He doesn't want all the permutations, just one (or a few) random ones.
>
> Anno

Oh, yes, I realize that. That's why I'd like to see where this permuting is
going. Maybe there is a less computing-intensive way of achieving the few
specific shufflings that the OP requires.



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

Date: Sat, 11 Aug 2001 08:36:24 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: stat() in W98SE
Message-Id: <slrn9na9m8.40h.tadmc@tadmc26.august.net>

A. Rodriguez <stuff@mail.chiriqui.com> wrote:
>
>Does stat() return anything in Windows 98 SE.


I wouldn't know, sorry.

Looks fine to me. Works on my system (no Windows here).


>The line below prints nothing
>
> print join('|', stat($files));
                            ^
                            ^

Why the plural variable name? stat() takes only one argument.

Maybe it is failing because $files does not contain what you
think it contains.

Maybe it is failing because $files is a relative path, and your
current directory isn't what you think it is.

Maybe several other things.

Best to check the return value from stat():

   my @stats = stat($files) or die "could not stat '$files'  $!";


Include the $! variable, and stat() will tell you why it failed.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 11 Aug 2001 18:25:35 +0200
From: Philip Newton <pne-news-20010811@newton.digitalspace.net>
Subject: Re: stat() in W98SE
Message-Id: <7ls9ntsf1hrc401i790c9qq47th145a13h@4ax.com>

On 10 Aug 2001 20:33:25 -0700, stuff@mail.chiriqui.com (A. Rodriguez)
wrote:

> Does stat() return anything in Windows 98 SE.

Yes.

> The line below prints nothing
> 
>  print join('|', stat($files));

What is the value of the variable $files?

Try this:

    perl -e "print join '|', stat 'c:/msdos.sys'"

And if you still come up with nothing, then you have a problem (I'm
assuming that file exists on every Windows 98 system).

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: 11 Aug 2001 16:48:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Sub that defaults to use $_ in callers context
Message-Id: <9l3nlr$9ql$1@mamenchi.zrz.TU-Berlin.DE>

According to Michael Carman  <mjcarman@home.com>:
> Anno Siegel wrote:

> > Indeed.  "exists $_[0]" doesn't recognize an undef that is passed
> > in.

[...]
 
> Seems to be something different about @_. I'll file a bug report.

FWIW, the behavior is the same with perl 5.7.2, probably still the
bleedperl.

Anno


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

Date: Sat, 11 Aug 2001 18:18:56 +0200
From: "Murat Uenalan" <murat.uenalan@gmx.de>
Subject: Too stupid for a simple CORE::GLOBAL:: export
Message-Id: <9l3lnr$6hb4u$1@ID-71895.news.dfncis.de>

After reading in the perlsub that i can simply replace a builtin perl
function or just create one which behaves like a builtin i tried:

__PERL__

package Class;

use Exporter;

our %EXPORT_TAGS = ( 'all' => [ qw(reflect schema) ] );

our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );

our @EXPORT = qw(class);

our @ISA = qw( Exporter );

 BEGIN
 {
  no strict 'refs';

  *{ 'CORE::GLOBAL::class' } = \&class;
 }

use subs qw(class);

sub class
{
      class_import( scalar caller, @_ );
}

# other insignificant subs: class_import, reflect, schema

1;

__END__

I just want to use the EXPORT variables, so i don't think i can write my own
import() subroutine and use ->export. Is this wrong ?

So when called from a script:

use Class;

package FOO;

    # Still need ::class instead of class

::class 'ANYTHING';

i still have to do need an package identifier for the "class" sub.

TYIA,
Murat






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

Date: Sat, 11 Aug 2001 09:22:37 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: tricky Question
Message-Id: <slrn9naccs.40h.tadmc@tadmc26.august.net>

Trull <trullock@yahoo.com> wrote:
>i have 14 lists, each with various bits of data in them.
>
>@one
>@two
>@three
>etc..
>
>and
>@aaa
>@bbb
>@ccc
>etc.
>
>
>now, i need to take the data from the @one @ two @three lists, and enter it
                                                                    ^^^^^
>into the @aaa @bbb @ccc lists.


Do you want a _copy_ of the elements put into @aaa and friends?

Or do you only need to know the "order" of the arrays?


>however, they need to be in a certain order. whichever list (one two three
>type) that has the highest number in the 1st entry needs to go into @aaa.
>the 2nd biggest needs to go into @bbb

>does that make sense?


Yes. But your choice of data structure seems to leave room 
for improvement  :-)


>any ideas how i can do this?

-----------------------------------
#!/usr/bin/perl -w
use strict;

my @one = (1, 2, 3);
my @two = (100, 200, 300);
my @three = (10, 20, 30);

my($aaa, $bbb, $ccc) = sort { $b->[0] <=> $a->[0]} \(@one, @two, @three);

my @aaa = @{$aaa};
my @bbb = @{$bbb};
my @ccc = @{$ccc};

print "@aaa\n@bbb\n@ccc\n";
-----------------------------------


Expanding to all 14 names will be a pain though.

I suspect there is an XY problem here, but since we don't know
what X is, we aren't going to be able to offer very good advice...

What is it that you are really trying to accomplish?


Seems to me you should be using an LoL (perldoc perllol) instead
of individually named @aaa, @bbb:

----------------------------
#!/usr/bin/perl -w
use strict;

my @one = (1, 2, 3);
my @two = (100, 200, 300);
my @three = (10, 20, 30);

my @sorted;  # LoL   

foreach ( sort { $b->[0] <=> $a->[0]} \(@one, @two, @three)) {
   push @sorted, [ @$_ ];   # make a copy
}

# let's see what we ended up with
foreach ( @sorted ) {
   print "@$_\n";
}
----------------------------

At least now we only have to list 14 things one place.

If you also used an LoL for @one, @two, then the identical code would
work regardless of the number of elements (arrays):


----------------------------
#!/usr/bin/perl -w
use strict;

my @orig = (
   [1, 2, 3],             # aka @one
   [100, 200, 300],       # aka @two
   [10, 20, 30],
);

my @sorted;  # LoL

foreach ( sort { $b->[0] <=> $a->[0]} @orig) {
   push @sorted, [ @$_ ];   # make a copy
}

# of if we don't need copies, just need to know what order:
#my @sorted = sort { $b->[0] <=> $a->[0]} @orig;

# let's see what we ended up with
foreach ( @sorted ) {
   print "@$_\n";
}
----------------------------

Now we don't have to list the 14 arrays at all, and it works with
15 arrays, or 13 arrays...

Carefully choosing an appropriate data structure can make your
programming life much easier.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 11 Aug 2001 10:40:53 -0700
From: mongo@firewallx.com (Mongo)
Subject: Re: voodoo cookie hash problem
Message-Id: <dc31dfbf.0108110940.7a9a871f@posting.google.com>

I think it's got somthing to do with sendmail being on a different
server so it doesn't see the cookie.


> >
> >$email = $cookies{email};
> >print "$cookies{email}\n";
> >
> >but as soon as I try to use the same value in a mail message it
> >reslults in a blank space.??
> 
> no, there is no special code in the perl interpreter that detects that
> a string is going to be used in a email message.
> 
> you simply have a bug in your code. show us the part where you use
> the value in your mail message.
> 
> gnari


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

Date: Sat, 11 Aug 2001 16:13:39 +0100
From: "Peter Mann" <Pcmann1@btinternet.com>
Subject: What happened to the first element of my arrray?
Message-Id: <9l3i2m$aoj$1@neptunium.btinternet.com>

Dear All,
     I am new to Perl and this problem has me puzzled. When I call 'output
users' from 'getUsers' the first element of the array is missing and not
displayed in the combo box!
     Before i split it up into 2 subs, all the elements were displayed in
the combo box, so I suspect the problem has something to do with passing the
array? But what is it?
     Does anyone know why this is?

Thanks in advance
  - Pete



sub getUsers
{
  $dbh = DBI->connect('dbi:ODBC:developers');
  $sqlstatement = "SELECT * FROM developers";

  $sth = $dbh->prepare($sqlstatement);
  $sth->execute ||
    die "Could not execute SQL statement, maybe invalid?";

  @users=$sth->fetchrow_array;
  outputUsers (@users);

  $sth->finish();
  $dbh->disconnect();
}


sub outputUsers
{
  my @temp = shift;

  #Output database results
  while ($temp=$sth->fetchrow_array)
  {
    $combo1->insert("end", $temp);
  }
}





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

Date: Sat, 11 Aug 2001 18:45:21 +0200
From: Philip Newton <pne-news-20010811@newton.digitalspace.net>
Subject: Re: What happened to the first element of my arrray?
Message-Id: <sdnantc22753f6dvojju0el67dqvtp3db6@4ax.com>

On Sat, 11 Aug 2001 16:13:39 +0100, "Peter Mann"
<Pcmann1@btinternet.com> wrote:

> Dear All,
>      I am new to Perl and this problem has me puzzled. When I call 'output
> users' from 'getUsers' the first element of the array is missing and not
> displayed in the combo box!

I think you're confused about what the contents of the array are and how
you are using them.

> sub getUsers
> {
>   $dbh = DBI->connect('dbi:ODBC:developers');
>   $sqlstatement = "SELECT * FROM developers";

OK, so you're going to select all columns from the table developers.
(NB: IMO one should not use select * but rather enumerate the columns
explicitly, but that's another matter.)

>   $sth = $dbh->prepare($sqlstatement);
>   $sth->execute ||
>     die "Could not execute SQL statement, maybe invalid?";
> 
>   @users=$sth->fetchrow_array;

This fetches one SQL row of data into @users. The various elements of
@users will be the columns of the database; for example, @users might be
('Doe', 'John', 'Senior Developer', '$50.000'), or whatever, depending
on your data structure.

>   outputUsers (@users);

Here, you're passing this first row of data that you just fetched to the
subroutine outputUsers, where it'll show up in @_.

>   $sth->finish();
>   $dbh->disconnect();
> }
> 
> 
> sub outputUsers
> {

OK, here we are in outputUsers. @_ now contains ('Doe', 'John', 'Senior
Developer', '$50.000') or whatever.

>   my @temp = shift;

This removes *one* element from @_ and puts it into @temp. @temp would
now contain 'Doe', and @_ would be ('John', 'Senior Developer',
'$50.000').

You then proceed to completely ignore @temp, and indeed the first row of
data your read above, for the rest of the subroutine.

>   #Output database results
>   while ($temp=$sth->fetchrow_array)

Here, you call fetchrow_array but stick the value into a scalar, $temp
(which has nothing to do with the array @temp you filled with a single
element above). 'use strict' would have warned you about the use of this
variable if you hadn't declared $temp outside the subroutine somewhere
but within the same lexical scope (earlier on in the same file, for
example). (You did 'use strict', didn't you? You should still have
declared $temp in this subroutine if its value is to be local to the
subroutine -- similarly with $dbh, $sqlstatement, and @users in
getUsers. [$sth is used in both subroutines.])

I don't know what $temp contains since the DBI documentation says
fetchrow_array returns "an array holding the field values". Putting
aside the fact that AIUI subroutines can't return arrays but only lists,
the example in the DBI documentation uses list context for
fetchrow_array since the result is assigned to the array @ary. And since
in Perl, one cannot deduce the behaviour of a subroutine when called in
scalar context from its behaviour in list context (or vice versa),
there's no telling what undefined behaviour will result from the above
call.

Possible results could be: assigning the first column to $temp;
assigning the last column to $temp; assigning the number of columns to
$temp; assigning an array reference containing the columns to $temp;
assigning the current temperature (in Kelvin) in Boulder, Colorado to
$temp; croak()ing; or pretty much anything else.

>   {
>     $combo1->insert("end", $temp);
>   }

Well, whatever ended up in $temp gets passed to $combo1->insert. So you
take an variable with an unknown value and add it to the combobox, I
presume. But whatever the value of $temp is, you won't add the first row
of SQL results to the combobox since you read that in getUsers already
but did nothing with the result. So all the calls of fetchrow_array in
the while loop will return rows 2 to the end of the SQL result set.

> }

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 1496
***************************************


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