[22325] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4546 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 11 00:05:53 2003

Date: Mon, 10 Feb 2003 21:05:10 -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           Mon, 10 Feb 2003     Volume: 10 Number: 4546

Today's topics:
        best Perl book for a newbi (samphdauto)
    Re: Can perl receive input from the CRON line ? <abigail@abigail.nl>
    Re: Controlling order of precedence <mgjv@tradingpost.com.au>
        Declaring an array member in a object. <dmanjunath@yahoo.com>
    Re: Declaring an array member in a object. <lockner@cse.psu.edu>
        decompress a tar.Z fine in perl <mail@mail.net>
        How to Iterate through a String (ibits)
    Re: I'm just not getting it... FAQ5 <jkeen@concentric.net>
    Re: I'm just not getting it... FAQ5 <jkeen@concentric.net>
    Re: I'm just not getting it... FAQ5 <jkeen@concentric.net>
    Re: I'm just not getting it... FAQ5 <jkeen@concentric.net>
        Impossible to do CRLF->LF on Windows/Activestate? <kirkspam@alienbill.com>
        Impossible to do CRLF->LF on Windows/Activestate? (Chas Friedman)
    Re: Impossible to do CRLF->LF on Windows/Activestate? <bwalton@rochester.rr.com>
    Re: Impossible to do CRLF->LF on Windows/Activestate? (Tad McClellan)
    Re: Impossible to do CRLF->LF on Windows/Activestate? <jeff@vpservices.com>
        iterator in for loop (Chas Friedman)
    Re: Modify array elements using foreach ? <truthxayer@yahoo.com>
        Out of Memory! error when hit 32GB <johnb@owl.hou.asp.ti.com>
    Re: Out of Memory! error when hit 32GB <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 10 Feb 2003 20:10:20 -0800
From: samj@eisa.net.au (samphdauto)
Subject: best Perl book for a newbi
Message-Id: <65050d4c.0302102010.5225f1e8@posting.google.com>

Hello
I come from a vb backgound and want to learn Perl.. what is the latest
book you recommned me to start with. the version of perl I have is
5.8.0 which is the latest 'I think'.

thanks 

Sam


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

Date: 11 Feb 2003 00:30:35 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Can perl receive input from the CRON line ?
Message-Id: <slrnb4gh1b.sp3.abigail@alexandra.abigail.nl>

pcg2001@sympatico.ca (pcg2001@sympatico.ca) wrote on MMMCDL September
MCMXCIII in <URL:news:e6le4vklj2ib4frobmg1jg3o2fk2pj1tee@4ax.com>:
::  I'm trying to pass a number like this but I can't see it in my perl
::  script or I just don't know how. 
::  
::  10 10 10 * * /home/web/lookup.cgi "86034"
::  
::  The idea would be to launch the perl script and have the 86034
::  available in a variable. Any help is appreciated


Read up about @ARGV in the perlvar manual page.



Abigail
-- 
perl  -e '$_ = q *4a75737420616e6f74686572205065726c204861636b65720a*;
          for ($*=******;$**=******;$**=******) {$**=*******s*..*qq}
          print chr 0x$& and q
          qq}*excess********}'


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

Date: Tue, 11 Feb 2003 00:19:57 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Controlling order of precedence
Message-Id: <slrnb4ggdd.se5.mgjv@verbruggen.comdyn.com.au>

On Mon, 10 Feb 2003 09:17:29 -0500,
	Robert Krueger <racsw@frontiernet.net> wrote:
> Martien Verbruggen wrote:
> 
>> On 6 Feb 2003 19:06:18 -0800,
>> Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> wrote:
>>> Robert Krueger (racsw@frontiernet.net) wrote:
>>>: Hi,
>>>:   In C++, you can control the order of evaluation in calculations by
>>>: enclosing particular calculations in ().  Everything is then calculated
>>>: from the innermost () to the outermost () so any question of the order
>>>: of precedence can be eliminated.
>>> 
>>> 
>>> $result = ($a+$b) + ($c+$d) ;

[snip]

>> What perl currently does is:
>> 
>> $ perl -MO=Terse,exec -e '$result = ($a+$b) + ($c+$d)'

[snip]

>> So, yes, $a + $b (add [1]) is calculated before $c + $d (add[2]).

>   The reason for my qustion in the first place was because I received an 
> error when I tried to do this.  Obviously, I typed something incorrectly, 

I'd say so :)

> as all of you are confirming that parens() work the same in perl as in C++.
> Your explanation, Martien, was interesting, even though I didn't understand 
> the assembly-type code you included.  I'm not sure whether the parens 

Those are perl's internal op-codes (at least, some partial textual
representation of them), which is what your Perl source gets compiled
into before execution. You don't really need to understand it all. The
main gist was that the output was in execution order, and that Perl
has a stack. Each operation in that list puts something on the stack
or pulls it off, or both (see below).

> controls the order somewhat or not, but out of technical nit-picking, would 
> this example force the execution of c&d before a&b?:
>      ((a+b) + ((c+d)))
> Actually, I think that's identical to:  a+b + (c+d)

Yes, it is identical, and it is also identical to a+b+c+d.
Parentheses do not force an order of evaluation (this is also true for
C and C++, although there may be languages where this is different,
LISP maybe?), they just force a "grouping", potentially overriding the
natural grouping that would occur because of operator precedence. The
output of B::Terse (bear with me, I'll explain) shows:

$ perl -MO=Terse,exec -e '$result =  (($a+$b) + (($c+$d)))'
OP (0x80fc088) enter
COP (0x8103000) nextstate
SVOP (0x80f9308) gvsv  GV (0x80ffeac) *a
SVOP (0x80f9328) gvsv  GV (0x80ffe94) *b
BINOP (0x8102d38) add [1]
SVOP (0x8102480) gvsv  GV (0x80fff00) *c
SVOP (0x8172bf8) gvsv  GV (0x80ffec4) *d
BINOP (0x8102ca0) add [2]
BINOP (0x80f9378) add [3]
SVOP (0x8102d60) gvsv  GV (0x80fff0c) *result
BINOP (0x80f92e0) sassign
LISTOP (0x80fc038) leave [1]
-e syntax OK

which is identical to the same expression without any brackets. This
output shows the internal operations perl goes through in execution
order. First it puts a on the stack, then b, then it adds them,
leaving the result on the stack. It then pushes c and d on the stack,
adds them, and then adds the result of that with what was already on
the stack (the result of a + b). It then assigns that to $result.

Where brackets come in handy is if you need to do add a and b, and
multiply that result with c. Without brackets, 

a + b * c

would be, because of * having a higher precedence than +, equivalent to

a + (b * c)

and you want

(a + b) * c

which is why you need the brackets.

Note that the order of evaluation is still from left to right in both
of the cases above, and in most other cases. Running some of these
through B::Terse can show you:

$ perl -MO=Terse,exec -e '$result = $a + $b * $c'
$ perl -MO=Terse,exec -e '$result = ($a + $b) * $c'
$ perl -MO=Terse,exec -e '$result = $a * $b + $c'
$ perl -MO=Terse,exec -e '$result = $a * ($b + $c)'

In all cases above is a evaluated before b, which is evaluated before
c. As said before, for normal variables that makes no difference, but
if you have side effects in the expressions a, b, c or d, then it can
make a difference (e.g. subroutine calls which manipulate globals or
one of the variables in the expression). In C (and I believe in C++ as
well, or tied variables or...) the order of this evaluation is not
defined (except for some operators), and you can only force it by
breaking up your expression in more than one (not by inserting
brackets, that only helps the parser). In Perl, even though I don't
think it is formally stated anywhere [1], evaluation seems to always
happen from left to right, and brackets don't change that.

In Perl you can "force" the evaluation of the (c+d) before (a+b) by
either ordering it in that way, or splitting up the statement.

$result = $c + $d + $a + $b;

or

$result = $c + $d;
$result = $result + $a + $b;

But this last one wastes CPU cycles in Perl (in C, for example, it
would be the only[2] way to guarantee the order of evaluation),
because of the extra stack manipulations and ops this introduces.

But as said, the order of evaluation only matters if you have side
effects.

Martien

[1] and I am not even entirely sure whether this is always true. Does
anyone have a more authoritative source for evaluation order in Perl
apart from a few tests with B::Terse?

[2] pedantry: Any way that inserts a sequency point would do, but
that's beside the point.
-- 
                        | 
Martien Verbruggen      | If at first you don't succeed, destroy all
Trading Post Australia  | evidence that you tried.
                        | 


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

Date: Mon, 10 Feb 2003 23:27:49 GMT
From: "manj dodda" <dmanjunath@yahoo.com>
Subject: Declaring an array member in a object.
Message-Id: <VzW1a.377$Q73.40153338@newssvr14.news.prodigy.com>

How do i set the array portlist to be an array in the
object below ?.

I want the portlist to be an array. Please take a look
and comment on what i have done.

Thanks in advance.

ma


package myModel
sub new {
        my ($class) = shift;
        bless {
                "modelname" => 0,
                "@portlist"  => undef
        }, $class ;
}

sub setPortlist {
   my($self)       = shift;
   my(@m_portlist) = @_ ;

   $self->{portlist} = @m_portlist ;
}


sub main {

@myarr = qw( tom henry jack peter) ;
$list[$i] = myModel->new() ;
$list[$i]->setPortList(@myArray) ;
## This is not working.
}




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

Date: Mon, 10 Feb 2003 22:51:32 -0500
From: Matthew Lockner <lockner@cse.psu.edu>
Subject: Re: Declaring an array member in a object.
Message-Id: <b29s05$176q$1@f04n12.cac.psu.edu>

manj dodda wrote:

> How do i set the array portlist to be an array in the
> object below ?.
> 
> I want the portlist to be an array. Please take a look
> and comment on what i have done.
> 
> Thanks in advance.
> 
> ma
> 
> 
> package myModel
> sub new {
>         my ($class) = shift;
>         bless {
>                 "modelname" => 0,
>                 "@portlist"  => undef
>         }, $class ;
> }
> 
> sub setPortlist {
>    my($self)       = shift;
>    my(@m_portlist) = @_ ;
> 
>    $self->{portlist} = @m_portlist ;

An array reference will likely serve you better:

$self->{portlist} = \@m_portlist;


Then keep in mind that when you want to access the portlist field as an
array, you should dereference it as an array ref, roo.



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

Date: Tue, 11 Feb 2003 04:49:57 GMT
From: Serial # 19781010 <mail@mail.net>
Subject: decompress a tar.Z fine in perl
Message-Id: <t00h4v8q92ahht8dsmb4csigj0jdemacje@4ax.com>

I am new to perl and need to extract files from a tar.Z file.

using the archive::tar module i am able to get files from a tar and
tar.gz but not tar.Z.  When I attempt to decompress the tar.Z the
binary contents of the file are dumpted to the screen.

any help on the issues is greatly apperciated.

I am using the following code to test.

#!/bin/perl

use Archive::Tar;

$engineFile = "vsapi6510rh.tar.Z";

$tarNewEngine = Archive::Tar->new($engineFile, 1);
@newFileList = $tarNewEngine->list_files();
		
foreach $file ( @newFileList ){
	print("$file\n");
}

thanks,

frank
spam@powerhouselinux.com


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

Date: 10 Feb 2003 20:57:09 -0800
From: one2katwo@yahoo.com (ibits)
Subject: How to Iterate through a String
Message-Id: <a317f43d.0302102057.78d93acb@posting.google.com>

Hi, this is newbee question

I was wondering if somebody could show me an example of how to iterate
through a string that someone has entered and print it out character
by character to each new line.
for eg She should print like
S
h
e


Thank you,
Shannon


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

Date: 10 Feb 2003 23:16:41 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: I'm just not getting it... FAQ5
Message-Id: <b29bsp$p2i@dispatch.concentric.net>


"rab" <richardbriggs@att.com> wrote in message
news:900b7105.0302070542.6c7c0040@posting.google.com...
> "James E Keenan" <jkeen@concentric.net> wrote in message
news:<b1urie$akk@dispatch.concentric.net>...> >
> > If I understand your objective, the solution was even simpler than I
> > thought:
> >
> > use Tie::File;
> >
> > my $file = 'grok.txt';
> >
> > my @arr = ();
> > tie @arr, 'Tie::File', $file or die "Could not tie $file: $!";
> > for (my $i=0; $i<=$#arr; $i++) {
> >         my $temp = $arr[$i];
> >         $arr[$i] = 'grok-3 NEW TEXT HERE' if ($temp =~ /^grok-3/);
> > }
> > untie @arr;
>
>
> James... thanks for your response...  I tried this block and it ran
> fine, but did not seem to modify the original file.  I guess I need to
> write $arr[$i] into the file some how?  Sorry for the density here,
> I've never used Tie::File.  Please be patient.
>
Are you *sure*?  I re-tested this now and it changed the original file just
as I intended it to.




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

Date: 10 Feb 2003 23:55:57 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: I'm just not getting it... FAQ5
Message-Id: <b29e6d$p2c@dispatch.concentric.net>


"James E Keenan" <jkeen@concentric.net> wrote in message
news:b29bsp$p2i@dispatch.concentric.net...
>
> "rab" <richardbriggs@att.com> wrote in message
> news:900b7105.0302070542.6c7c0040@posting.google.com...
> > "James E Keenan" <jkeen@concentric.net> wrote in message
> news:<b1urie$akk@dispatch.concentric.net>...> >
> > > If I understand your objective, the solution was even simpler than I
> > > thought:
> > >
> > > use Tie::File;
> > >
> > > my $file = 'grok.txt';
> > >
> > > my @arr = ();
> > > tie @arr, 'Tie::File', $file or die "Could not tie $file: $!";
> > > for (my $i=0; $i<=$#arr; $i++) {
> > >         my $temp = $arr[$i];
> > >         $arr[$i] = 'grok-3 NEW TEXT HERE' if ($temp =~ /^grok-3/);
> > > }
> > > untie @arr;
> >
> >
> > James... thanks for your response...  I tried this block and it ran
> > fine, but did not seem to modify the original file.  I guess I need to
> > write $arr[$i] into the file some how?  Sorry for the density here,
> > I've never used Tie::File.  Please be patient.
> >
> Are you *sure*?  I re-tested this now and it changed the original file
just
> as I intended it to.
>
>
An important caveat:  By looking at your response to other posters, I see
that what you want is to replace *only the first* instance where $temp =~
/^grok-3/.  My solution above replaces *all* such instances.  I've been
trying to figure out a solution using Tie::File, but haven't got it yet.
The reason is that if we're iterating over the array indexes (as, I've
found, is usually the case with Tie::File), but since the splice method
works *immediately* (cannot be deferred), the next line of text slips into
the index position we just spliced out.  So I'll have to think about this a
while longer.




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

Date: 11 Feb 2003 00:43:40 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: I'm just not getting it... FAQ5
Message-Id: <b29gvs$p2h@dispatch.concentric.net>


"James E Keenan" <jkeen@concentric.net> wrote in message
news:b29bsp$p2i@dispatch.concentric.net...
>
> "rab" <richardbriggs@att.com> wrote in message
> news:900b7105.0302070542.6c7c0040@posting.google.com...
> > "James E Keenan" <jkeen@concentric.net> wrote in message
> news:<b1urie$akk@dispatch.concentric.net>...> >
> > > If I understand your objective, the solution was even simpler than I
> > > thought:
> > >
> > > use Tie::File;
> > >
> > > my $file = 'grok.txt';
> > >
> > > my @arr = ();
> > > tie @arr, 'Tie::File', $file or die "Could not tie $file: $!";
> > > for (my $i=0; $i<=$#arr; $i++) {
> > >         my $temp = $arr[$i];
> > >         $arr[$i] = 'grok-3 NEW TEXT HERE' if ($temp =~ /^grok-3/);
> > > }
> > > untie @arr;
> >
> >
> > James... thanks for your response...  I tried this block and it ran
> > fine, but did not seem to modify the original file.  I guess I need to
> > write $arr[$i] into the file some how?  Sorry for the density here,
> > I've never used Tie::File.  Please be patient.
> >
> Are you *sure*?  I re-tested this now and it changed the original file
just
> as I intended it to.
>
>
Here is the solution I was groping towards.  It uses Tie::File and splice to
replace only the first instance and delete all subsequent ones ... but it
ain't pretty.

my $file = 'grok.txt';
my (@arr, @tbsplice);
my ($signal, $temp);
tie @arr, 'Tie::File', $file or die "Could not tie $file: $!";
for (my $i=0; $i<=$#arr; $i++) {
    my $temp = $arr[$i];
    if ($temp =~ /^grok-3/) {
        if (! $signal) {
            $arr[$i] = 'grok-3 NEW TEXT HERE';
            $signal++;
        } else {
            push @tbsplice, $i;
        }
    }
}
for (my $j=$#tbsplice; $j>=0; $j--) {
    splice @arr, $tbsplice[$j], 1;
}
untie @arr;
print "Rows in original which were spliced out:  @tbsplice\n";

HTH!




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

Date: 11 Feb 2003 04:22:49 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: I'm just not getting it... FAQ5
Message-Id: <b29tqp$p2g@dispatch.concentric.net>


"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3E486DC3.1994F06@earthlink.net...
> James E Keenan wrote:
> [snip]
> > An important caveat:  By looking at your response to other posters, I
> > see that what you want is to replace *only the first* instance where
> > $temp =~ /^grok-3/.  My solution above replaces *all* such instances.
> > I've been trying to figure out a solution using Tie::File, but haven't
> > got it yet.
>
> use Tie::File;
>
> tie my(@arr), "Tie::File", "grok.txt"
>    or die "Couldn't tie grok.txt: $!";
> for (@arr) {
>    if( /^grok-3/ ) {
>       $_ = 'grok-3 NEW TEXT HERE';
>       last;
>    }
> }
> untie @arr;
> __END__
> [untested]
>

I think you've misinterpreted the OP's intention in the same way I did.  See
my 2nd post of this evening.  I believe he wants to delete all subsequent
instances of /^grok-3/.  Yours, like my first attempt, makes a substitution
for the first instance but fails to delete the subsequent ones.




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

Date: Mon, 10 Feb 2003 23:24:07 GMT
From: Kirk Is <kirkspam@alienbill.com>
Subject: Impossible to do CRLF->LF on Windows/Activestate?
Message-Id: <rwW1a.454$Y2.16592@news.tufts.edu>

I'm having an odd problem, where it seems Perl is doing such a good job of 
handling DOS CRLF that I can't get it to not handle it nicely...

I made a two liner file in notepad called dos.txt:
line1
line2

14 bytes, 1 for each character, 2 for each CRLF

I thought a one liner like 

perl -e "while($line = <>) { $line =~ /\r$//; print $line; }" < dos.txt > 
unix.txt

would fix it, but unix.txt is still 14 bytes (and reads as a PC format 
file to textpad.

I thought "ok, so maybe it's hiding the CRLF inside the \n, so let me 
try:"

perl -e "while($line=<>){chomp $line;print $line.chr(10);}" < dos.txt > 
unix.txt

Still 14 bytes...it's like something at a low I/O level is intercepting
the chr(10) and expanding it to the full CRLF.

Am I doing something wrong? if I print chr(13) I can make text that 
textpad freely recognizes as Mac format... how can I tell Perl to stop 
being so nice about the CRLF thing and let me do what I need to? Is there 
a special flag or variable to override the default EOL character?




-- 
QUOTEBLOG: http://kisrael.com   SKEPTIC MORTALITY: http://kisrael.com/mortal
"I would have made a good pope" --Richard M. Nixon 


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

Date: Tue, 11 Feb 2003 04:02:05 +0000 (UTC)
From: friedman@math.utexas.edu (Chas Friedman)
Subject: Impossible to do CRLF->LF on Windows/Activestate?
Message-Id: <b29sjt$dvd$1@geraldo.cc.utexas.edu>



 Kirk wrote:
>I'm having an odd problem, where it seems Perl is doing such a good job of 
>handling DOS CRLF that I can't get it to not handle it nicely...
>
>I made a two liner file in notepad called dos.txt:
>line1
>line2
>
>14 bytes, 1 for each character, 2 for each CRLF
>
>I thought a one liner like 
>
>perl -e "while($line = <>) { $line =~ /\r$//; print $line; }" < dos.txt > 
>unix.txt
>
>would fix it, but unix.txt is still 14 bytes (and reads as a PC format 
>file to textpad.
 .....

 First, don't you mean $line =~ s/\r$//, rather than $line =~ /\r$//?

 Second, if I use
perl -e "binmode STDOUT;while($line = <>) { $line =~ s/\r$//; print $line; }"<dos.txt>unix.txt

 I seem to get the desired effect in DOS (removal of "\r").
                    chas



 


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

Date: Tue, 11 Feb 2003 01:37:45 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Impossible to do CRLF->LF on Windows/Activestate?
Message-Id: <3E485397.3020806@rochester.rr.com>

Kirk Is wrote:

> I'm having an odd problem, where it seems Perl is doing such a good job of 
> handling DOS CRLF that I can't get it to not handle it nicely...
 ...

Perl internally converts the CR-LF sequence to LF, and converts LF to 
CR-LF on output, in Windoze, by default.  You can make MAC files OK 
because Windoze Perl doesn't do anything to plain CR characters.  The 
solution to your problem is the function binmode.  See:

     perldoc -f binmode

There is another, deeper question, though:  Why do you want to make 
Unix-format or MAC-format text files on a PC?  Does not the software you 
are using to transport files between platforms solve this problem 
automatically for you?

-- 
Bob Walton



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

Date: Mon, 10 Feb 2003 19:51:46 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Impossible to do CRLF->LF on Windows/Activestate?
Message-Id: <slrnb4glpi.1pc.tadmc@magna.augustmail.com>

Kirk Is <kirkspam@alienbill.com> wrote:

> I'm having an odd problem, where it seems Perl is doing such a good job of 
> handling DOS CRLF that I can't get it to not handle it nicely...


> Am I doing something wrong?


Yes.


> how can I tell Perl to stop 
> being so nice about the CRLF thing and let me do what I need to?


   perldoc -f binmode


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


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

Date: Mon, 10 Feb 2003 20:09:45 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Impossible to do CRLF->LF on Windows/Activestate?
Message-Id: <3E487789.8040707@vpservices.com>

Chas Friedman wrote:

>  Kirk wrote:
> 
>>I'm having an odd problem, where it seems Perl is doing such a good job of 
>>handling DOS CRLF that I can't get it to not handle it nicely...

 >

> perl -e "binmode STDOUT;while($line = <>) { $line =~ s/\r$//; print $line; }"<dos.txt>unix.txt
> 


Or, more simply:

   perl -e "binmode STDOUT;while(<>){print}"<dos.txt>unix.txt

-- 
Jeff



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

Date: Tue, 11 Feb 2003 00:35:05 +0000 (UTC)
From: friedman@math.utexas.edu (Chas Friedman)
Subject: iterator in for loop
Message-Id: <b29gfo$6c3$1@geraldo.cc.utexas.edu>



__________
You wrote:
>hi
>
>how do i tell which iteration i'm on within a for loop?
>
>i can do
>
>for (my $i=0;$i<@array;$i++) {
>  print "iteration #: $i item: $array[$i]\n";
>}
>
>but i don't like that C-style idiom.  what i need is a system variable
>$X to tell me which item i'm on, like:
>
>print "iteration #: $X item: $_\n" for @array;
>
>please could someone hack into the perl source code and add this
>feature for me and email me the recompiled perl binary.
>
>TIA
 You could do something like:
{my $i=1;sub X {$i++};sub reset_X {$i=1}}  #Define your own iterator
reset_X;
print "Iteration @{[X]}: Item: $_\n" for @array;
 
 True, the @{[X]} takes a few more typing steps than $X, and this is likely
an unintelligent solution to a nonexistent problem, but it certainly isn't 
C-style and it is less trouble than recompiling perl.
                       chas




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

Date: Mon, 10 Feb 2003 17:46:43 -0800
From: TruthX <truthxayer@yahoo.com>
Subject: Re: Modify array elements using foreach ?
Message-Id: <3E485603.85365CF5@yahoo.com>

Stefan wrote:
> 

> 
> #!/usr/local/bin/perl -w
> 
> use strict;
> 
> my(%List) = ('one', 1,  'two', 2,  'three', 3,  'four', 4,  'five', 5);
> 
> my($element);
> foreach $element (keys %List) {
>    $element =~ s/^three$/third/;

### change the value as well 
	$List{$element} = 3 if ($element eq 'third');

> }
> 
> foreach $element (keys %List) {
>    print $element, " = ", $List{$element}, "\n";
> }

-- 
Developments ... occurred only because some thinkers either
decided
not to be bound by certain `obvious' methodological rules,
or
because they unwittingly broke them. 
					-Paul Feyerabend (philosopher)


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

Date: Mon, 10 Feb 2003 23:55:13 +0000 (UTC)
From: John M Bach <johnb@owl.hou.asp.ti.com>
Subject: Out of Memory! error when hit 32GB
Message-Id: <b29e51$nvc$1@expedia.hou.asp.ti.com>

i get an "Out of Memory!" error when building up datastructures
in memory and reach the 2GB limit.

i have heard that there is a 'large file compatibility mode'
which when enabled should get around this memory limit.
is anyone familiar with this?  for some reason it doesn't seem
to be working for us.

i guess the other option would be to migrate to a large data
model (64 bit) version.  would perl 5.8 do this, or would some
special switches be required when compiling it?

currently using perl (5.005_03).  thanks.
 


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

Date: Mon, 10 Feb 2003 22:50:30 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Out of Memory! error when hit 32GB
Message-Id: <3E487306.633359FA@earthlink.net>

John M Bach wrote:
> 
> i get an "Out of Memory!" error when building up datastructures
> in memory and reach the 2GB limit.
> 
> i have heard that there is a 'large file compatibility mode'
> which when enabled should get around this memory limit.

No, large files are large files.  This mode alters the meaning of the C
level typedef "off_t", which is used for offsets within a file, and for
file sizes.  To enable it, one would add -Duselargefiles on the
commandline when running Config.

Changing perl to use large *pointers* (that is, the C level sizeof
"void*", or other pointer types), is another option entirely.

I believe that the option to enable that that is "-Duse64bitall", though
I'm not entirely sure.

> is anyone familiar with this?  for some reason it doesn't seem
> to be working for us.
> 
> i guess the other option would be to migrate to a large data
> model (64 bit) version.  would perl 5.8 do this, or would some
> special switches be required when compiling it?
> 
> currently using perl (5.005_03).  thanks.

It should be doable with either of 5.6 or 5.8, and yes, you'll need some
special switches when running Config before compiling it.

It *might* (I'm not sure) be doable with 5.005_03, but you'll need to
reconfigure and recompile it.

-- 
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
 landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"


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

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


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