[31479] in Perl-Users-Digest
Perl-Users Digest, Issue: 2731 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 19 00:09:40 2009
Date: Fri, 18 Dec 2009 21:09:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 18 Dec 2009 Volume: 11 Number: 2731
Today's topics:
Re: Creating an alias to an existing hash (from a hash <jl_post@hotmail.com>
Re: Creating an alias to an existing hash (from a hash <jl_post@hotmail.com>
Re: Creating an alias to an existing hash (from a hash <derykus@gmail.com>
Re: Curious benchmark results with Inline::C sln@netherlands.com
Re: Difference between "$var" and $var? <usenet@davidfilmer.com>
Re: Difference between "$var" and $var? <john@castleamber.com>
Re: Getting strange double-error messages on a "use <mo <uri@StemSystems.com>
Re: Getting strange double-error messages on a "use <mo <usenet@davidfilmer.com>
Re: Getting strange double-error messages on a "use <mo <usenet@davidfilmer.com>
Re: Getting strange double-error messages on a "use <mo <uri@StemSystems.com>
Getting strange double-error messages on a "use <module <usenet@davidfilmer.com>
Sorting an array <gamo@telecable.es>
Re: Sorting an array <jurgenex@hotmail.com>
Re: Sorting an array <gamo@telecable.es>
Re: Sorting an array <jurgenex@hotmail.com>
Re: Sorting an array <jimsgibson@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 18 Dec 2009 14:31:22 -0800 (PST)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Creating an alias to an existing hash (from a hash reference)
Message-Id: <b03c9a4d-0832-447a-b45f-7e7d3a33765c@s21g2000prm.googlegroups.com>
> jl_p...@hotmail.com wrote:
> > =A0 =A0If I find myself in such a situation in the future (which I'm su=
re
> > will happen), I'll probably just resort to search-and-replacing
> > instances of "$hash{" to "$hashRef->{".
On Dec 18, 1:09 pm, Xho Jingleheimerschmidt <xhos...@gmail.com>
replied:
> Don't forget about replacing "@hash{" with "@{$hashRef}{", and "keys
> %hash" with "keys %$hashRef", etc.
Very true. Yet another reason Data::Alias is so nice.
-- Jean-Luc
------------------------------
Date: Fri, 18 Dec 2009 14:46:19 -0800 (PST)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Creating an alias to an existing hash (from a hash reference)
Message-Id: <e0faafc8-e597-4bdd-834b-d8ef6b22575c@y32g2000prd.googlegroups.com>
On Dec 18, 12:55=A0pm, "C.DeRykus" <dery...@gmail.com> wrote:
> No, ordinary package variables and those declared with
> 'our' are scoped differently. And 'our' can be clobbered
> in a multi-package global way that ordinary package
> variables won't be:
>
> =A0 perl -Mstrict -wle "package main; our $x=3D1;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 package Foo; =A0our $x=3D2;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 package main; print $x"
> =A0 2
>
> vs.
>
> =A0 perl -Mstrict -wle "package main; use vars '$x';$x=3D1;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 package Foo; =A0use vars '$x'=
;$x=3D2;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 package main; print $x"
> =A0 1
Interesting. I did not know that.
"perldoc -f our" helped me understand a little more.
Of course, if your scopes don't cross package boundaries, then this
isn't an issue to worry about. But if they do, then this is good to
know.
-- Jean-Luc
------------------------------
Date: Fri, 18 Dec 2009 15:59:01 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: Creating an alias to an existing hash (from a hash reference)
Message-Id: <c6892ff0-945f-4323-87f9-64ecb6aa091b@j9g2000prh.googlegroups.com>
On Dec 18, 12:57=A0pm, "jl_p...@hotmail.com" <jl_p...@hotmail.com>
wrote:
> On Dec 18, 12:55=A0pm, "C.DeRykus" <dery...@gmail.com> wrote:
>
> > the first print below
> > works =A0as expected and the final print outside the
> > {no strict;...} draws an uninitialized warning:
>
> > perl -Mstrict -wle "use vars '%blah';
> > =A0 =A0 =A0 {no strict; local *blah =3D \%ENV; print $blah{PATH};}
> > =A0 =A0 =A0 print $blah{PATH}"
>
> =A0 =A0True, but the uninitialized warning happened because you used the
> "local" keyword. =A0If you remove that, then the second print() line
> will have access to %ENV via %blah.
True but it can be a good idea in general to
insulate a variable with 'local' to avoid
avoid clobbering any potential existing values.
I thought you had control of that part of the
code...
>
> =A0 =A0So you might think that using "local" prevents code in outside
> scopes from accessing %ENV through %blah. =A0But that's not true. =A0The
> "local" keyword temporarily changes the value of %blah, but it changes
> it everywhere in the package, not just in its scope.
>
> =A0 =A0Consider this code:
>
> =A0 =A0perl -Mstrict -wle "{no strict; local *blah =3D \%ENV; f() }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0sub f { our %blah; print $=
blah{PATH} }
>
> Even though the code inside f() is in a completely different scope
> that the code that calls f(), the code inside f() still has access to
> %blah as the calling code sees it (and therefore has access to modify
> %ENV through it).
>
> =A0 =A0Sure, declaring *blah as "local" in f() would prevent that from
> happening, but since you can't always guarantee that all code will
> "local"ize all its typeglobs, declaring one typeglob as "local" won't
> necessarily stop all code (outside the intended scope) from accessing
> what %blah references. =A0(It'll stop some code, but not all code.)
>
That's expected because 'local's dynamic scoping
propagates the localized variable into any called
subroutine in the localized scope. For instance:
{ local $foo=3D'bar'; f(); }
"The f() or any sub called within f() all the way
down the call stack will see $foo with its local
value 'bar'.
So, used correctly, 'local' does limit what's seen.
There's quite a bit of confusion about the gory
details of 'local' however. And details in perlsub
and perlfaq7 are skimpy..
--
Charles DeRykus
------------------------------
Date: Fri, 18 Dec 2009 17:19:17 -0800
From: sln@netherlands.com
Subject: Re: Curious benchmark results with Inline::C
Message-Id: <qt4oi5lk1v3dqolj015f1qv84a42rrsk2e@4ax.com>
On Tue, 15 Dec 2009 16:35:43 -0800 (PST), "jl_post@hotmail.com" <jl_post@hotmail.com> wrote:
> I theorized that the "unrolled" code would be the fastest, followed
>by the code that called the inlined function, followed by the code
>that called the non-inlined function.
>
Actually you are correct. This in theory is what happens.
However, no compiler will cooperate if left on its own accord.
Rarely is inline used, given all the other optimizations the compiler
does on your behalf. The only way to get the results you think is to
disable optimizations and force inlining, if you can even do that.
Inlining won't be done for a number of reasons (ie:recursion,...),
it is only a *suggestion* (as docs will tell you) to the compiler.
Usually, given specific code (and compiler), getting the compiler
to do with it what you want is time consuming, often trial and error.
Linking is a bigger hassle.
Here's some benchmarks ...
-sln
c:\temp\_INLTEST>cl -?
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
C/C++ COMPILER OPTIONS
-OPTIMIZATION-
/O1 minimize space /Op[-] improve floating-pt consistency
/O2 maximize speed /Os favor code space
/Oa assume no aliasing /Ot favor code speed
/Ob<n> inline expansion (default n=0) /Ow assume cross-function aliasing
/Od disable optimizations (default) /Ox maximum opts. (/Ogityb1 /Gs)
/Og enable global optimization /Oy[-] enable frame pointer omission
/Oi enable intrinsic functions
-CODE GENERATION-
..., etc ...
Benchmarks
==================================
Optimization /Od - disable (none)
use Inline (C => Config =>
BUILD_NOISY => 1,
FORCE_BUILD => 1,
OPTIMIZE => "-Od",
);
use Inline 'C' => <<'END_OF_C_CODE';
...
cl -c -IC:/temp/_INLTEST -nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_I
NC -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFI
X -Od -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\" "-IC:\Perl\lib\CORE" inlin
e_test_pl_95db.c
Command line warning D4025 : overriding '/O1' with '/Od'
inline_test_pl_95db.c
Rate C with inline C with function C unrolled
C with inline 4129/s -- -0% -23%
C with function 4131/s 0% -- -23%
C unrolled 5333/s 29% 29% --
** With optimizations disabled, with inline/function are the same
unrolled is best performance
==================================
Optimization /O1 - favor code size over speed (config.pm defaults?)
use Inline (C => Config =>
BUILD_NOISY => 1,
FORCE_BUILD => 1,
OPTIMIZE => "",
);
use Inline 'C' => <<'END_OF_C_CODE';
...
cl -c -IC:/temp/_INLTEST -nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_I
NC -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFI
X -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\" "-IC:\Perl\lib\CORE" inline_t
est_pl_95db.c
inline_test_pl_95db.c
Rate C with function C with inline C unrolled
C with function 4572/s -- -25% -25%
C with inline 6094/s 33% -- -0%
C unrolled 6098/s 33% 0% --
** With code size favored, function is slowest
inline/unrolled is best performance, about the same
==================================
Optimization's /Od /Ob1 - disable optimization, force inline (__inline/__forceinline same)
use Inline (C => Config =>
BUILD_NOISY => 1,
FORCE_BUILD => 1,
OPTIMIZE => "-Od -Ob1",
);
use Inline 'C' => <<'END_OF_C_CODE';
...
cl -c -IC:/temp/_INLTEST -nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_I
NC -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFI
X -Od -Ob1 -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\" "-IC:\Perl\lib\CORE"
inline_test_pl_95db.c
Command line warning D4025 : overriding '/O1' with '/Od'
inline_test_pl_95db.c
Rate C with function C with inline C unrolled
C with function 4129/s -- -22% -23%
C with inline 5288/s 28% -- -1%
C unrolled 5333/s 29% 1% --
** Optimizations disabled, inline is forced. * Pure results *
function is slowest
inline is alot faster
unrolled is a little faster than inline.
These results make sense!
==================================
Optimization /O2 - favor code speed over size
use Inline (C => Config =>
BUILD_NOISY => 1,
FORCE_BUILD => 1,
OPTIMIZE => "-O2",
);
use Inline 'C' => <<'END_OF_C_CODE';
...
cl -c -IC:/temp/_INLTEST -nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_I
NC -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFI
X -O2 -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\" "-IC:\Perl\lib\CORE" inlin
e_test_pl_95db.c
Command line warning D4025 : overriding '/O1' with '/O2'
inline_test_pl_95db.c
Rate C with inline C with function C unrolled
C with inline 9699/s -- -0% -0%
C with function 9699/s 0% -- 0%
C unrolled 9699/s 0% 0% --
** Code speed favored, inline is irrelavent in this case.
Inlineing has no affect here.
Apparently, where speed is concerned,
return sqrt(x*x + y*y);
is too generic and easily optimized to the point that function
wrapper is stripped off entirely.
------------------------------
Date: Fri, 18 Dec 2009 14:17:24 -0800 (PST)
From: David Filmer <usenet@davidfilmer.com>
Subject: Re: Difference between "$var" and $var?
Message-Id: <b53ffb77-5fdd-4313-8ab3-965835398c42@f18g2000prf.googlegroups.com>
On Dec 18, 10:42=A0am, sharma...@hotmail.com wrote:
>>> Difference between "$var" and $var?
Sometimes you will want to "stringify" an object. For example,
consider the following snippet, which uses the IO::All module to find
all the .txt files in a particular directory, which are added to a
zipfile.
my $zip =3D Archive::Zip -> new();
foreach my $file (io('/tmp/test/')
-> filter(sub {$_->name =3D~/.*\.txt/})
-> all_files(1) ) {
print "Adding file $file\n";
$zip -> addFile($file);
}
$zip->writeToFileNamed( 'baz.zip' );
If you run that as-is, the zipfile will be empty, even though you see
multiple print statements.
The problem is that $file is not an ordinary scalar variable - it's an
IO::All blessed something-or-another (Dumper says: $file =3D bless
( \*Symbol::GEN2, 'IO::All::File' ); ). In order to make that code
work, you need to double-quote $file (which causes it to "strinigy" to
it's name):
$zip -> addFile("$file");
--
David Filmer (http://DavidFilmer.com)
------------------------------
Date: Fri, 18 Dec 2009 16:19:08 -0600
From: John Bokma <john@castleamber.com>
Subject: Re: Difference between "$var" and $var?
Message-Id: <87fx78udr7.fsf@castleamber.com>
"Uri Guttman" <uri@StemSystems.com> writes:
>>>>>> "JB" == John Bokma <john@castleamber.com> writes:
>
> JB> "Uri Guttman" <uri@StemSystems.com> writes:
> >> did you compare the results? did you see any differences? make up your
> >> own mind about that.
>
> JB> I think that's a bit unfair. I mean, you *don't* have to post a reply.
>
> no, i wanted to really know if he actually compared the output. he was
> asking almost as if he didn't know.
I am not a fan of trial and error coding and certainly wouldn't
stimulate it.
I've been back to usenet recently and read both this group and
comp.lang.python and (again) sadly have to notice that this group is far
more hostile. Just don't reply to a message if it annoys you. I hit
Ctrl+C k (kill reply) a lot nowadays after I pressed F (follow-up).
--
John Bokma
Read my blog: http://johnbokma.com/
Hire me (Perl/Python): http://castleamber.com/
------------------------------
Date: Fri, 18 Dec 2009 19:32:57 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Getting strange double-error messages on a "use <module>" - does not seem to be @INC problem
Message-Id: <87y6kzvm4m.fsf@quad.sysarch.com>
>>>>> "DF" == David Filmer <usenet@davidfilmer.com> writes:
DF> On Dec 18, 2:32 pm, David Filmer <use...@davidfilmer.com> wrote:
>> Before, I felt like I was going in circles. Now I feel like I've hit
>> a brick wall.
DF> Sheez - never mind. The module CPM.pm had a cloaked "die" in it.
did you steal the romulan cloaking device? that is needed to debug many
modules.
DF> sloppy, sloppy.
wipe that spittle off your chin! :)
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Fri, 18 Dec 2009 14:32:06 -0800 (PST)
From: David Filmer <usenet@davidfilmer.com>
Subject: Re: Getting strange double-error messages on a "use <module>" - does not seem to be @INC problem
Message-Id: <01f2c4c7-e736-425c-9a49-8ec81f1982f3@v7g2000pro.googlegroups.com>
On Dec 18, 2:13=A0pm, "Uri Guttman" <u...@StemSystems.com> wrote:
> hi dave!
Hi, Uri - long time. I'm messing with some code from the Mother Ship.
> well, that is because it DID find the module.
Ah.
> compilation of CPM::MainProc failed. so run a perl -c on that module
Hmmm. I get
Compilation failed in require at /path/to/scripts/perllib/CPM/
MainProc.pm line 214.
BEGIN failed--compilation aborted at /path/to/scripts/perllib/CPM/
MainProc.pm line 214.
OK, the module doesn't like itself. So I have a look at line 214:
use CPM;
Which I check:
perl -c /path/to/scripts/perllib/CPM.pm
/ProductMaker/scripts/perllib/CPM.pm syntax OK
FWIW, all the modules end in "1;"
Before, I felt like I was going in circles. Now I feel like I've hit
a brick wall.
--
David Filmer (http://DavidFilmer.com)
------------------------------
Date: Fri, 18 Dec 2009 14:47:58 -0800 (PST)
From: David Filmer <usenet@davidfilmer.com>
Subject: Re: Getting strange double-error messages on a "use <module>" - does not seem to be @INC problem
Message-Id: <e6b9e1e5-5072-4473-84a8-533799faa2ed@z10g2000prh.googlegroups.com>
On Dec 18, 2:32=A0pm, David Filmer <use...@davidfilmer.com> wrote:
> Before, I felt like I was going in circles. =A0Now I feel like I've hit
> a brick wall.
Sheez - never mind. The module CPM.pm had a cloaked "die" in it.
sloppy, sloppy.
--
David Filmer (http://DavidFilmer.com)
------------------------------
Date: Fri, 18 Dec 2009 17:13:44 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Getting strange double-error messages on a "use <module>" - does not seem to be @INC problem
Message-Id: <87bphwvskn.fsf@quad.sysarch.com>
>>>>> "DF" == David Filmer <usenet@davidfilmer.com> writes:
DF> I'm trying to run someone else's code. I'm getting pairs of error
DF> messages that look like this:
DF> Compilation failed in require at /path/to/scripts/fooator.pl line
DF> 86.
DF> BEGIN failed--compilation aborted at /path/to/scripts/fooator.pl
DF> line 86.
DF> Line 86 says:
DF> use CPM::MainProc;
DF> Well, I figure that I have a problem with that module not being found
DF> in @INC, even though I'm accustomed to a different pair of error
DF> messages ("Can't locate Foo.pm in @INC..." and the same "BEGIN failed"
DF> message).
DF> But, anyway, CPM::MainProc is at /path/to/scripts/perllib/CPM/
DF> MainProc.pm, so I added (before line 86):
DF> use lib( '/path/to/scripts/perllib' , '/path/to/scripts/perllib/
DF> CPM' );
DF> But it makes no difference.
hi dave!
well, that is because it DID find the module. the error says the
compilation of CPM::MainProc failed. so run a perl -c on that module and
see what perl says. likely that module has a syntax error or possibly it
is missing the trailing 1; needed for require to return a true value.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Fri, 18 Dec 2009 14:05:01 -0800 (PST)
From: David Filmer <usenet@davidfilmer.com>
Subject: Getting strange double-error messages on a "use <module>" - does not seem to be @INC problem
Message-Id: <dfdf91a7-1c47-464e-ab0e-14fdda20e745@d9g2000prh.googlegroups.com>
I'm trying to run someone else's code. I'm getting pairs of error
messages that look like this:
Compilation failed in require at /path/to/scripts/fooator.pl line
86.
BEGIN failed--compilation aborted at /path/to/scripts/fooator.pl
line 86.
Line 86 says:
use CPM::MainProc;
Well, I figure that I have a problem with that module not being found
in @INC, even though I'm accustomed to a different pair of error
messages ("Can't locate Foo.pm in @INC..." and the same "BEGIN failed"
message).
But, anyway, CPM::MainProc is at /path/to/scripts/perllib/CPM/
MainProc.pm, so I added (before line 86):
use lib( '/path/to/scripts/perllib' , '/path/to/scripts/perllib/
CPM' );
But it makes no difference.
FWIW, The first line of MainProc.pm is
package CPM::MainProc;
I'm thinking the problem has nothing to do with @INC. I don't know
what that "Compilation failed in require" message means.
Can anyone help?
Thanks!
------------------------------
Date: Fri, 18 Dec 2009 22:38:44 +0000
From: gamo <gamo@telecable.es>
Subject: Sorting an array
Message-Id: <alpine.LNX.2.00.0912182233460.4215@jvz.es>
This code
@sorted = sort {
field4($a) <=> field4($b) ||
field1($a) <=> field1($b)
} @oferta;
simply don't work.
The error message is
Undefined subroutine &main::field4 called at subasta.pl line 30.
Any help is appreciated.
--
http://www.telecable.es/personales/gamo/
Honesta turpitudo est pro causa bona --Publilius Syrus
"Was it a car or a cat I saw?"
perl -E 'say 111_111_111**2;'
------------------------------
Date: Fri, 18 Dec 2009 15:03:05 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Sorting an array
Message-Id: <6d2oi5po6ee62r4ri2v82v66oveh6ocef1@4ax.com>
gamo <gamo@telecable.es> wrote:
>This code
>
>@sorted = sort {
> field4($a) <=> field4($b) ||
> field1($a) <=> field1($b)
>} @oferta;
>
>simply don't work.
>
>The error message is
>Undefined subroutine &main::field4 called at subasta.pl line 30.
Well, yeah, sorry for asking the obvious, but did you define a function
field4() in your main program? You are using it in the comparision, but
perl can't find it.
jue
------------------------------
Date: Fri, 18 Dec 2009 23:19:31 +0000
From: gamo <gamo@telecable.es>
Subject: Re: Sorting an array
Message-Id: <alpine.LNX.2.00.0912182312490.4260@jvz.es>
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--8323328-958307296-1261178371=:4260
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
Content-Transfer-Encoding: QUOTED-PRINTABLE
On Fri, 18 Dec 2009, J=FCrgen Exner wrote:
> gamo <gamo@telecable.es> wrote:
> >This code
> >
> >@sorted =3D sort {
> > field4($a) <=3D> field4($b) ||
> > field1($a) <=3D> field1($b)
> >} @oferta;
> >
> >simply don't work.
> >
> >The error message is=20
> >Undefined subroutine &main::field4 called at subasta.pl line 30.
>=20
> Well, yeah, sorry for asking the obvious, but did you define a function
> field4() in your main program? You are using it in the comparision, but
> perl can't find it.
>=20
> jue
>=20
I'm afraid I take the FAQ suggestion too literally.
How can be that subs be writed?
The array @oferta has $oferta[0 to .5M][0 to 3]
TIA
--=20
http://www.telecable.es/personales/gamo/
Honesta turpitudo est pro causa bona --Publilius Syrus
"Was it a car or a cat I saw?"
perl -E 'say 111_111_111**2;'
--8323328-958307296-1261178371=:4260--
------------------------------
Date: Fri, 18 Dec 2009 16:54:08 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Sorting an array
Message-Id: <nq8oi5h0mpvh1mj1a6c9gc6i7sga64j15k@4ax.com>
gamo <gamo@telecable.es> wrote:
>On Fri, 18 Dec 2009, Jürgen Exner wrote:
>
>> gamo <gamo@telecable.es> wrote:
>> >This code
>> >
>> >@sorted = sort {
>> > field4($a) <=> field4($b) ||
>> > field1($a) <=> field1($b)
>> >} @oferta;
>> >
>> >simply don't work.
>> >
>> >The error message is
>> >Undefined subroutine &main::field4 called at subasta.pl line 30.
>>
>> Well, yeah, sorry for asking the obvious, but did you define a function
>> field4() in your main program? You are using it in the comparision, but
>> perl can't find it.
>
>I'm afraid I take the FAQ suggestion too literally.
>How can be that subs be writed?
>
>The array @oferta has $oferta[0 to .5M][0 to 3]
Insufficient information. Please post a minimal but complete program
that we can compile and run. In your case what we really really need is
an actual sample of your data structure (make sure your program creates
that) as well as a clear, precise description of your sort criteria.
jue
------------------------------
Date: Fri, 18 Dec 2009 18:12:41 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Sorting an array
Message-Id: <181220091812411857%jimsgibson@gmail.com>
In article <alpine.LNX.2.00.0912182312490.4260@jvz.es>, gamo
<gamo@telecable.es> wrote:
> On Fri, 18 Dec 2009, J¸rgen Exner wrote:
>
> > gamo <gamo@telecable.es> wrote:
> > >This code
> > >
> > >@sorted = sort {
> > > field4($a) <=> field4($b) ||
> > > field1($a) <=> field1($b)
> > >} @oferta;
> > >
> > >simply don't work.
> > >
> > >The error message is
> > >Undefined subroutine &main::field4 called at subasta.pl line 30.
> >
> > Well, yeah, sorry for asking the obvious, but did you define a function
> > field4() in your main program? You are using it in the comparision, but
> > perl can't find it.
>
> I'm afraid I take the FAQ suggestion too literally.
> How can be that subs be writed?
>
> The array @oferta has $oferta[0 to .5M][0 to 3]
If you mean that the @oferta array has 500_000 elements, each of which
is a reference to an array with 4 elements, and you want to sort the
@oferta array using the numerical value of the fourth element of the
referenced arrays as a primary key and the numerical value of the first
element as a secondary key, then what you want is (untested):
@sorted = sort {
$a->[3] <=> $b->[3] ||
$a->[0] <=> $b->[0]
} @oferta;
--
Jim Gibson
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 V11 Issue 2731
***************************************