[23196] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5417 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 24 06:05:40 2003

Date: Sun, 24 Aug 2003 03:05:06 -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           Sun, 24 Aug 2003     Volume: 10 Number: 5417

Today's topics:
    Re: a backreference problem? <geoff.cox@blueyonder.co.uk>
    Re: a backreference problem? <geoff.cox@blueyonder.co.uk>
    Re: a backreference problem? <geoff.cox@blueyonder.co.uk>
    Re: a backreference problem? <geoff.cox@blueyonder.co.uk>
    Re: Commonly used modules <matthew.garrish@sympatico.ca>
    Re: Commonly used modules <kevin@vaildc.net>
    Re: Commonly used modules (Andrew Savige)
        Descending numeric sort using Guttman-Rosler Transform (Andrew Savige)
    Re: Descending numeric sort using Guttman-Rosler Transf <tassilo.parseval@rwth-aachen.de>
    Re: embeding tags (Tad McClellan)
    Re: embeding tags (Tad McClellan)
    Re: operator in a variable? <bigj@kamelfreund.de>
        Passing a hash to a function (Mark Healey)
    Re: Passing a hash to a function <tassilo.parseval@rwth-aachen.de>
    Re: Proper way to export structures from a module <ben.goldberg@hotpop.com>
    Re: Small memory problem <tore@aursand.no>
        stable sort (Praveen Kallakuri)
    Re: stable sort <uri@stemsystems.com>
    Re: stable sort <ben.goldberg@hotpop.com>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 24 Aug 2003 09:29:20 +0100
From: Geoff Cox <geoff.cox@blueyonder.co.uk>
Subject: Re: a backreference problem?
Message-Id: <1ftgkvgkc715erkchr4jqqd90h2b9oa1rc@4ax.com>

On Sun, 24 Aug 2003 00:05:44 +0100, "Peter Cooper"
<newsfeed@boog.co.uk> wrote:

Peter

So far I am using

open(IN, "a2-left.htm");
open(OUT, ">>out");

if (open(IN, "a2-left.htm")) {

$line = <IN>;

while ($line ne "") {
if ($line =~ /^<a href/) {
if ($line =~ /="(.*)\.doc/) {
print OUT ("$1 \n");
}
}
$line = <IN>;

}
}

close (IN);
close (OUT);

This works in that it lists in the out file, all the path info such as
"docs/path/wordfilename"

In another file I have items which have the this path info and also a
piece of introductory text associated with each wordfilename....so I
want to extract that introductory text and place it just after the
path info in say the out file above...how do I use the $1 info to get
this? I mean I cannot have $1[$n] etc...

Cheers

Geoff



>You can match 'many' things into an array like so:
>
>my $data1 = q{
><a href="docs/path/word.doc">link to word doc</a>
><a href="docs/path/word2.doc">link to word doc</a>
><a href="docs/path/word3.doc">link to word doc</a>
>};
>
>(@names) = ($data1 =~ /="(.*?)\.doc"/gsi);
>print $_ . "\n" for @names;
>
>However, if you really want to parse HTML, and aren't just using HTML as an
>example here, you will want to look into modules which are dedicated to this
>purpose. Look at the HTML Parser set at
>http://search.cpan.org/author/GAAS/HTML-Parser-3.31/ . HTML::LinkExtor (a
>link extractor) may be of particular use to you.
>
>Regards,
>Peter Cooper
>



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

Date: Sun, 24 Aug 2003 09:41:55 +0100
From: Geoff Cox <geoff.cox@blueyonder.co.uk>
Subject: Re: a backreference problem?
Message-Id: <beugkvoagpkce4ihrp76qimdbsi6onpr61@4ax.com>

On Sun, 24 Aug 2003 00:05:44 +0100, "Peter Cooper"
<newsfeed@boog.co.uk> wrote:

Peter et al ...

Now trying this - you will perhaps see better what I am trying to
do...problem with the passing of $1 to the sub getintro - I get an
uninitialized value in pattern match error ...

Cheers

Geoff

open(IN, "a2-left.htm");
open(OUT, ">>out");
open(INN, "total");

if (open(IN, "a2-left.htm")) {

$line = <IN>;

while ($line ne "") {
if ($line =~ /^<a href/) {
if ($line =~ /="(.*)\.doc/) {
&getintro($1);
}
}
$line = <IN>;

}
}
sub getintro {

@intro = <INN>;
for ($n=0;$n<900;$n++) {
if ($into[$n] =~ /$1/) {
print OUT ("$into[$n]\n");
print OUT ("$line[$n-1]\n");
}
}
}

close (IN);
close (OUT);
close (INN);




>"Geoff Cox" <geoff.cox@blueyonder.co.uk> wrote:
>> which will get "docs/path/word"
>> from <a href="docs/path/word.doc">link to word doc</a> (A)
>>
>> But! What if I have a file with say 100 lines similar to A above? How
>> do I deal with multiple values of $1?
>
>You can match 'many' things into an array like so:
>
>my $data1 = q{
><a href="docs/path/word.doc">link to word doc</a>
><a href="docs/path/word2.doc">link to word doc</a>
><a href="docs/path/word3.doc">link to word doc</a>
>};
>
>(@names) = ($data1 =~ /="(.*?)\.doc"/gsi);
>print $_ . "\n" for @names;
>
>However, if you really want to parse HTML, and aren't just using HTML as an
>example here, you will want to look into modules which are dedicated to this
>purpose. Look at the HTML Parser set at
>http://search.cpan.org/author/GAAS/HTML-Parser-3.31/ . HTML::LinkExtor (a
>link extractor) may be of particular use to you.
>
>Regards,
>Peter Cooper
>



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

Date: Sun, 24 Aug 2003 09:46:06 +0100
From: Geoff Cox <geoff.cox@blueyonder.co.uk>
Subject: Re: a backreference problem?
Message-Id: <dougkvc66p4jv20929ot886qmgqc9j857l@4ax.com>

On Sun, 24 Aug 2003 09:41:55 +0100, Geoff Cox
<geoff.cox@blueyonder.co.uk> wrote:


I know there are 2 mistakes re $into where it should read $intro etc .
have corrected these but still get same error message....

Geoff

>On Sun, 24 Aug 2003 00:05:44 +0100, "Peter Cooper"
><newsfeed@boog.co.uk> wrote:
>
>Peter et al ...
>
>Now trying this - you will perhaps see better what I am trying to
>do...problem with the passing of $1 to the sub getintro - I get an
>uninitialized value in pattern match error ...
>
>Cheers
>
>Geoff
>
>open(IN, "a2-left.htm");
>open(OUT, ">>out");
>open(INN, "total");
>
>if (open(IN, "a2-left.htm")) {
>
>$line = <IN>;
>
>while ($line ne "") {
>if ($line =~ /^<a href/) {
>if ($line =~ /="(.*)\.doc/) {
>&getintro($1);
>}
>}
>$line = <IN>;
>
>}
>}
>sub getintro {
>
>@intro = <INN>;
>for ($n=0;$n<900;$n++) {
>if ($into[$n] =~ /$1/) {
>print OUT ("$into[$n]\n");
>print OUT ("$line[$n-1]\n");
>}
>}
>}
>
>close (IN);
>close (OUT);
>close (INN);
>
>
>
>
>>"Geoff Cox" <geoff.cox@blueyonder.co.uk> wrote:
>>> which will get "docs/path/word"
>>> from <a href="docs/path/word.doc">link to word doc</a> (A)
>>>
>>> But! What if I have a file with say 100 lines similar to A above? How
>>> do I deal with multiple values of $1?
>>
>>You can match 'many' things into an array like so:
>>
>>my $data1 = q{
>><a href="docs/path/word.doc">link to word doc</a>
>><a href="docs/path/word2.doc">link to word doc</a>
>><a href="docs/path/word3.doc">link to word doc</a>
>>};
>>
>>(@names) = ($data1 =~ /="(.*?)\.doc"/gsi);
>>print $_ . "\n" for @names;
>>
>>However, if you really want to parse HTML, and aren't just using HTML as an
>>example here, you will want to look into modules which are dedicated to this
>>purpose. Look at the HTML Parser set at
>>http://search.cpan.org/author/GAAS/HTML-Parser-3.31/ . HTML::LinkExtor (a
>>link extractor) may be of particular use to you.
>>
>>Regards,
>>Peter Cooper
>>



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

Date: Sun, 24 Aug 2003 10:42:09 +0100
From: Geoff Cox <geoff.cox@blueyonder.co.uk>
Subject: Re: a backreference problem?
Message-Id: <av1hkv4qiokqc55pvbj3lja4sdgg1uahiu@4ax.com>

On Sun, 24 Aug 2003 09:46:06 +0100, Geoff Cox
<geoff.cox@blueyonder.co.uk> wrote:

>On Sun, 24 Aug 2003 09:41:55 +0100, Geoff Cox
><geoff.cox@blueyonder.co.uk> wrote:
>
>
>I know there are 2 mistakes re $into where it should read $intro etc .
>have corrected these but still get same error message....

which is odd...the value for $1 does get into the sub getintro but get
the error message "uninitialized value in pattern match" for the line

if ($into[$n] =~ /$1/) {

?

Cheers

Geoff




>Geoff
>
>>On Sun, 24 Aug 2003 00:05:44 +0100, "Peter Cooper"
>><newsfeed@boog.co.uk> wrote:
>>
>>Peter et al ...
>>
>>Now trying this - you will perhaps see better what I am trying to
>>do...problem with the passing of $1 to the sub getintro - I get an
>>uninitialized value in pattern match error ...
>>
>>Cheers
>>
>>Geoff
>>
>>open(IN, "a2-left.htm");
>>open(OUT, ">>out");
>>open(INN, "total");
>>
>>if (open(IN, "a2-left.htm")) {
>>
>>$line = <IN>;
>>
>>while ($line ne "") {
>>if ($line =~ /^<a href/) {
>>if ($line =~ /="(.*)\.doc/) {
>>&getintro($1);
>>}
>>}
>>$line = <IN>;
>>
>>}
>>}
>>sub getintro {
>>
>>@intro = <INN>;
>>for ($n=0;$n<900;$n++) {
>>if ($into[$n] =~ /$1/) {
>>print OUT ("$into[$n]\n");
>>print OUT ("$line[$n-1]\n");
>>}
>>}
>>}
>>
>>close (IN);
>>close (OUT);
>>close (INN);
>>
>>
>>
>>
>>>"Geoff Cox" <geoff.cox@blueyonder.co.uk> wrote:
>>>> which will get "docs/path/word"
>>>> from <a href="docs/path/word.doc">link to word doc</a> (A)
>>>>
>>>> But! What if I have a file with say 100 lines similar to A above? How
>>>> do I deal with multiple values of $1?
>>>
>>>You can match 'many' things into an array like so:
>>>
>>>my $data1 = q{
>>><a href="docs/path/word.doc">link to word doc</a>
>>><a href="docs/path/word2.doc">link to word doc</a>
>>><a href="docs/path/word3.doc">link to word doc</a>
>>>};
>>>
>>>(@names) = ($data1 =~ /="(.*?)\.doc"/gsi);
>>>print $_ . "\n" for @names;
>>>
>>>However, if you really want to parse HTML, and aren't just using HTML as an
>>>example here, you will want to look into modules which are dedicated to this
>>>purpose. Look at the HTML Parser set at
>>>http://search.cpan.org/author/GAAS/HTML-Parser-3.31/ . HTML::LinkExtor (a
>>>link extractor) may be of particular use to you.
>>>
>>>Regards,
>>>Peter Cooper
>>>



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

Date: Sat, 23 Aug 2003 22:04:18 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Commonly used modules
Message-Id: <R2V1b.1991$W01.374092@news20.bellglobal.com>


"Jon" <jonov@iprimus.com.au> wrote in message
news:3f46d58a_1@news.iprimus.com.au...
>
> I'm curious to know what CPAN modules people use in their general
day-to-day
> perl scripting (or can't live without). For example I make lots of use of
> the Date::Manip module and would hate to have to ever implement something
> like that.
>

I guess you missed the recent discussion. The CPAN modules are for the
losers who like stable code... ; )

Matt




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

Date: Sun, 24 Aug 2003 01:25:55 -0400
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: Commonly used modules
Message-Id: <kevin-C97945.01255524082003@news101.his.com>

In article <3f46d58a_1@news.iprimus.com.au>, Jon <jonov@iprimus.com.au> 
wrote:

> I'm curious to know what CPAN modules people use in their general day-to-day 
> perl scripting (or can't live without). For example I make lots of use of 
> the Date::Manip module and would hate to have to ever implement something 
> like that.

The one I seem to use the most, for some reason, is Tie::IxHash.  I 
think it should be part of the core distribution.
-- 
Kevin Michael Vail | Dogbert: That's circular reasoning.
kevin@vaildc.net   | Dilbert: I prefer to think of it as no loose ends.
http://www.vaildc.net/kevin/


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

Date: 24 Aug 2003 01:25:57 -0700
From: ajsavige@yahoo.com.au (Andrew Savige)
Subject: Re: Commonly used modules
Message-Id: <f5d2f2e7.0308240025.19c92906@posting.google.com>

Jon <jonov@iprimus.com.au> wrote in message news:<3f46d58a_1@news.iprimus.com.au>...
> Hi,
> 
> I'm curious to know what CPAN modules people use in their general day-to-day 
> perl scripting (or can't live without). For example I make lots of use of 
> the Date::Manip module and would hate to have to ever implement something 
> like that.

You might like to take a look at the phalanx project list:

http://qa.perl.org/phalanx/distros.html

/-\


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

Date: 24 Aug 2003 01:18:21 -0700
From: ajsavige@yahoo.com.au (Andrew Savige)
Subject: Descending numeric sort using Guttman-Rosler Transform
Message-Id: <f5d2f2e7.0308240018.47e6fae1@posting.google.com>

The following program is a simple example of sorting positive integers
using the Guttman-Rosler transform:

print map { substr($_, 4) } sort map { pack('N', $_) . $_ } <DATA>;
__END__
2
256
255
32000
33000
12345678
12345679
1234567
1

It seems to me that pack('N', $_) is sound while pack('L', $_) is
unsound (because 'N' is guaranteed big-endian, while 'L' is not).
Is that right?

What is the recommended way to do a descending numeric sort?
Changing pack('N', $_) to pack('N', -$_) seems to work.
Is it sound?

If the data contains negative integers, the simple program above
does not work. What is the recommended technique in that case?
Changing pack('N', $_) to pack('N', $_ ^ (1 << 31)) seems to work.
Is it sound?

/-\


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

Date: 24 Aug 2003 09:13:46 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Descending numeric sort using Guttman-Rosler Transform
Message-Id: <bi9vka$pmb$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Andrew Savige:

> The following program is a simple example of sorting positive integers
> using the Guttman-Rosler transform:
> 
> print map { substr($_, 4) } sort map { pack('N', $_) . $_ } <DATA>;
> __END__
> 2
> 256
> 255
> 32000
> 33000
> 12345678
> 12345679
> 1234567
> 1
> 
> It seems to me that pack('N', $_) is sound while pack('L', $_) is
> unsound (because 'N' is guaranteed big-endian, while 'L' is not).
> Is that right?

Right. 'L' is the native byte-order so it will only yield correct
results on big-endian machines. Well, I mean you could also do a 

    map { (reverse pack "V", $_) . $_ } <DATA>

;-)

> What is the recommended way to do a descending numeric sort?
> Changing pack('N', $_) to pack('N', -$_) seems to work.
> Is it sound?

Yes.

> If the data contains negative integers, the simple program above
> does not work. What is the recommended technique in that case?
> Changing pack('N', $_) to pack('N', $_ ^ (1 << 31)) seems to work.
> Is it sound?

No:

    print -2147483646 ^ (1<<31);
    print "\n";
    print 2147483650 ^ (1<<31);
    __END__
    2
    2

And suddenly a negative and a positive number become equal. So you are
limited by the number of bits your perl was compiled for. It may work
for perls compiled with 'use64bitall=define'. But at some point you
always have the problem that the numbers will get too large.

However, for a simple numeric sort (either descending or default order),
the Guttman-Rosler transform is not the right tool since

    sort { $a <=> $b } @list;
    sort { $b <=> $a } @list;

are special cases that have been optimized in the perl core. So the
above two will give significantly better performance than any transform.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Sat, 23 Aug 2003 19:37:54 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: embeding tags
Message-Id: <slrnbkg272.49v.tadmc@magna.augustmail.com>

Jim Key <jimkey@tds.net> wrote:

> there is the SSI tag that was generated


So then, your Perl program must have done the Right Thing.


> print "Content-type: text/html\n\n";
> print '<!--#include virtual="search.pl?',$url,'" -->';


Those print statements look fine to me (other than $url not being
given a value), so you do not have a problem with your Perl.

Your problem must be somewhere else. (So you should be looking
for the solution somewhere else.)


> Any suggestions are greatly appreciated.


Ask Perl questions here in the Perl newsgroup.

Ask questions about the CGI in the CGI newsgroup:

      comp.infosystems.www.authoring.cgi

Ask server setup questions in a newsgroup about servers, such as:

      comp.infosystems.www.servers.mac
      comp.infosystems.www.servers.misc
      comp.infosystems.www.servers.ms-windows
      comp.infosystems.www.servers.unix

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


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

Date: Sat, 23 Aug 2003 20:29:37 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: embeding tags
Message-Id: <slrnbkg581.4c0.tadmc@magna.augustmail.com>

Jim Key <jimkey@tds.net> wrote:

> Is there a problem with the way code was written that may act differently on
> different versions (?) of Perl 


No.


> on a server? 


That would likely depend on what server and on how that
server was configured. Neither of which is about Perl.


> Or was a better way of writing
> the code that it will execute the same?


Your code looked fine.


> But don't bother. Diffenitley don't need any help from a JERK like you.


That is likely to cost you. So long.


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


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

Date: Sun, 24 Aug 2003 08:55:54 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: operator in a variable?
Message-Id: <pan.2003.08.24.06.55.52.633009@kamelfreund.de>

Michael Roper wrote at Fri, 22 Aug 2003 10:54:15 -0700:

> It seemed to me that the cleanest way to do this was to include the desired
> operator in the @aDelete entry itself:
> 
> my @aDelete =
> ({
>   Name => 'invalid recipient',
>   Marker=> '^Recipient: michaelr@encraft\.com)$',
>   Op    => "!~",
>   Count => "0",
> },{
>   Name => 'open relay',
>   Marker=> '^   Reason: (NJABL|OSIRUSOFT) \[Open Relay',
>   Op    => "=~",
>   Count => "0",
> },{
>   Name => 'china and korea',
>   Marker=> ' (china|korea) does not seem to care about spam$',
>   Op    => "=~",
>   Count => "0",
> });
> 
> But I have been unable to find a way to then write:
> 
>     if( $sLogRecord $aDelete[$i]->{Op} /$aDelete[$i]->{Marker}/m )
> 
> that will work in the intended fashion.  I have tried every permutation of
> eval I can think of.
> 
> I realize that I can solve this problem in other ways.  It's just that the
> only solutions I've come up with are pretty ugly.  Any thoughts much
> appreciated.

Here's another way to get it:

my @aDelete = (
   {Name       => 'invalid recipient',
    Marker     => qr/^Recipient: michaelr@encraft\.com$/,
    HasToMatch => 0
   },
   {Name       => 'open relay',
    Marker     => qr/^   Reason: (NJABL|OSIRUSOF) \[Open Relay/,
    HasToMatch => 1
   },
   {Name       => 'china and korea',
    Marker     => qr/ (china|korea) does not seem to care about spam$/,
    HasToMatch => 1
   }
);

if ($sLogRecord =~ /$aDelete[$i]->{Marker}/m == $aDelete[$i]->{HasToMatch})
{
   $aDelete[$i]->{Counter}++;
}

That works because the regexp returns the number of successfull matches in
your string what is in your case 0 or 1, so it must be equal to the
HasToMach entry.

(I also used the qr// operator for the regexep parts what might be a bit
better, please read perldoc perlop [Regexp Quote-Like Operators] about)


This way has some advantages over the eval-method.
First it generates more and more sensful errors if something goes wrong.
E.g. if you type in the Op part only a = instead of =~, there is nor a
runtime error and I believe neither a warning.
I would find it also a bit easier to work in other contexts as you don't
need to distinguish between to operators but between two different
selfexplaining boolean states.
It is also a bit shorter as you don't need four characters ('=~') but only
1 to achieve the same in every entry of @aDelete.

However the main advantage is the better logic. Whether a Marker has to
match or not is basically not a question of which operator has to be used,
it's primary a question of "yes" or "no". Thus a boolean variable is more
appropriate to the problem.

(That would it also make it easier to port your program to other
languages, e.g. Perl 6, sometimes)


Greetings,
Janek


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

Date: Sun, 24 Aug 2003 06:27:23 GMT
From: die@spammer.die (Mark Healey)
Subject: Passing a hash to a function
Message-Id: <VP2SpNyJrzMZ-pn2-W1qrf63yrZYW@adsl-63-207-135-60.dsl.sndg02.pacbell.net>

I can't seem to find in in my perl book.  I'd like to pass hashes to
functions

#!/usr/bin/perl -wT

my %someHash;

$someHash{'one'} = "1";
$someHash{'two'} = "2";
$someHash{'three'} = "3";


sub onsiestwosies
        {
        do stuff with %someHash
        }

I'd simply like to pass %someHash to onesiestwosies.

--
Mark Heaely
marknews(at)healeyonline(dot)com


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

Date: 24 Aug 2003 07:01:09 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Passing a hash to a function
Message-Id: <bi9nrl$kpe$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Mark Healey:

> I can't seem to find in in my perl book.  I'd like to pass hashes to
> functions
> 
> #!/usr/bin/perl -wT
> 
> my %someHash;
> 
> $someHash{'one'} = "1";
> $someHash{'two'} = "2";
> $someHash{'three'} = "3";
> 
> 
> sub onsiestwosies
>         {
>         do stuff with %someHash
>         }
> 
> I'd simply like to pass %someHash to onesiestwosies.

Under well defined circumstances, you can simply do it like this:

    sub func {
        my %hash = @_;
    }
    ...
    func(%someHash);
    
The problem with that is that it a) copies the hash (which may be
inefficient if it is large) and b) you can't pass more than one list-ish
variable to the subroutine (perl flattens all arguments passed into one
large list). So best is to use a reference:

    sub func {
        my ($hash1_ref, $hash2_ref) = @_;
        # do the dereferencing
        my %hash1 = %$hash1_ref;
        ...
    }
    ...
    func(\%someHash1, \%someHash2);
    
See perlreftut.pod and perlref.pod if you aren't acquainted with
references. All about subroutines (including how to pass arguments and
access them), can be found in perlsub.pod.

Not sure whether you are familiar with the perldocs. You only mention a
book. The documentation of Perl is often more suitable for looking up such
things. See 'perldoc perl' for a list of available manpages and 'perldoc
perldoc' on how to access the Perl documentation.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Sun, 24 Aug 2003 01:02:48 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: Proper way to export structures from a module
Message-Id: <3F4846F8.4FF60DBD@hotpop.com>



Steve D wrote:
> 
> Steven Kuo <skuo@mtwhitney.nsc.com> wrote in message news:<Pine.GSO.4.21.0308201226460.20626-100000@mtwhitney.nsc.com>...
> > You may want to consider using an object-oriented approach.  It
> > really depends on how complex your data structure is.   For example:
> 
> Steve K,
> 
> Thanks for the suggestion.
> 
> I had considered an OO approach. However, the complexity of the
> structures and the number of transformations I wanted to be able to do
> precluded me from finding an appropriate abstraction. The
> combinatorics are a killer.  It seems to be easiest to just expose the
> structures to the appropriate objects.

Hmm.  Show us your data structures, and maybe we can help.

Also, one can generate one's OO methods for accessing a private data
structure through an AUTOLOAD sub.

> I just wanted to know if the methods I used were appropriate, or
> whether there might be a better (safer, simpler, clearer) way to
> express the code.

OO is certainly safer, and might possibly be clearer and simpler to use.

Whether it'll be clearer and simpler to implement, I don't know.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Sun, 24 Aug 2003 03:47:33 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Small memory problem
Message-Id: <pan.2003.08.24.01.47.30.773656@aursand.no>

On Sat, 23 Aug 2003 13:26:17 -0700, David Morel wrote:
> # now I want to return to low memory usage,
> # but the above undef statement doesn't get the job done!

That's right, and that's the way it is; When a program exits, it doesn't
necessarily free up its memory and return it to the OS.  Check the perldoc
for information about this.

A comment on your code, however.  Seems a bit C'ish to me, as you could
have written the same thing like this;

  my @paths = ();
  sleep 5;
  for ( 1 .. 500_000 ) {
      push( @paths, [$_, $_] );
  }
  sleep 5;


-- 
Tore Aursand <tore@aursand.no>


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

Date: 23 Aug 2003 19:33:53 -0700
From: praveen@unlserve.unl.edu (Praveen Kallakuri)
Subject: stable sort
Message-Id: <65bdd4b2.0308231833.5de7fc87@posting.google.com>

hello,

i am having a problem with stable sort.

************************************************************
use strict;
use sort 'stable';

 ....
 ...

   foreach my $key (sort { $a <=> $b && $sums{$b} <=> $sums{$a} } keys 
%sums) {
        printf TMPFILE "%d\n",$key;
    }
    print OUT "\n";
 ...
 ...
************************************************************
sums is a hash with the following key-value pairs:


2 3
3 4
4 2
5 4
6 3

i want the hash sorted by the values, but the sequence of keys to be 
preserved when possible. so, what i am expecting is something like 3 5 2 6 
4. but what i get is below:

3
5
6
2
4

why can't i get the 6 after 2 even though i am using stable sort? thanks 
for any suggestions. btw i am using perl 5.8 on a debian-woody.

thanks

praveen


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

Date: Sun, 24 Aug 2003 02:53:46 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: stable sort
Message-Id: <x7ptivn4uh.fsf@mail.sysarch.com>

>>>>> "PK" == Praveen Kallakuri <praveen@unlserve.unl.edu> writes:

  PK> use sort 'stable';

  PK>    foreach my $key (sort { $a <=> $b && $sums{$b} <=> $sums{$a} } keys 
  PK> %sums) {

why are doing a 2 level sort when you are only sorting the hash by value?

the stable sort will keep the same relative order of equal sort values
after the sort. so a simple sort by value should be fine.

  PK> 2 3
  PK> 3 4
  PK> 4 2
  PK> 5 4
  PK> 6 3

  PK> i want the hash sorted by the values, but the sequence of keys to
  PK> be preserved when possible. so, what i am expecting is something
  PK> like 3 5 2 6 4. but what i get is below:

now you seem to want the key to be compared if the values are the
same. fine, but your example code has it backwards.you need to compare
the values first and then if they are equal, compare the keys. the idiom
is to sort by the first level key and OR (||) it with the second level
sort.

  PK> 3
  PK> 5
  PK> 6
  PK> 2
  PK> 4

	foreach my $key (sort {
			$sums{$b} <=> $sums{$a}
				  ||
			       $a <=> $b } keys %sums) {

i note that you had the value comparison ($sums{$a}) in reverse order to
get a descending sort but the key sort comparison is in normal order
which will do a ascending subsort of the entries with equal values.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Sun, 24 Aug 2003 01:14:00 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: stable sort
Message-Id: <3F484998.83552801@hotpop.com>


[snip]
>    foreach my $key (sort { $a <=> $b && $sums{$b} <=> $sums{$a} } keys
> %sums) {

Why are you using && between these clauses, instead of || ?

Try writing your code as:

   foreach my $key (sort {
             $a <=> $b or
      $sums{$a} <=> $sums{$b}
   } keys %sums) {

The "use sort 'stable'" only means that if you have a sort comparator
which considers two keys of your original list as being equal to each
other, they will appear in the same relative order in the output as they
appeared in the input.  For example, consider:

   my @a = qw(foo bar quux};
   my @b = sort {0} @a;

If you've done "use sort 'stable';" then you're guaranteed that @b will
be in the same order as @al; otherwise, the order might be arbitrary or
random.

Here's a slightly more real-life-ish

   my @a = qw(3foo 2bar 2baz 1quux);
   my @b = sort { no warnings 'numeric'; $a <=> $b } @a;

With "use sort 'stable';" then 2bar will definitely come before 2baz,
since they're numerically equal and 2bar came before 2baz in the
original array.  Without it, their relative order might be arbitrary or
random.

For another real-life-ish example of "arbitrary" -- I remember an old
qsort, which, if you gave it data and a the comparator which considered
everything to be all equal, the output would be the reversed order of
the input.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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