[29489] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 733 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 9 14:09:58 2007

Date: Thu, 9 Aug 2007 11:09:08 -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           Thu, 9 Aug 2007     Volume: 11 Number: 733

Today's topics:
    Re: (Re)announcing APL 2007 <steve@shrogers.com>
    Re: Certfication in AWK or SHell programming <suregeonde@yahoo.de>
    Re: How i convert a excel file to csv file xhoster@gmail.com
    Re: How to parse directory structure from FTP LIST <spamtrap@dot-app.org>
    Re: How to parse directory structure from FTP LIST <tadmc@seesig.invalid>
    Re: how to tranpose a huge text file <bugbear@trim_papermule.co.uk_trim>
    Re: how to tranpose a huge text file <nospam-abuse@ilyaz.org>
    Re: how to tranpose a huge text file <jgibson@mail.arc.nasa.gov>
    Re: how to tranpose a huge text file <pgovern@u.washington.edu>
    Re: how to tranpose a huge text file <nospam-abuse@ilyaz.org>
    Re: if kill 9, $pid fails, is the error caught anywhere anno4000@radom.zrz.tu-berlin.de
        more elegant way to say ($1, $2, $3, $4, ...)? <larry.grant.dc@gmail.com>
        multidimensional Array <tristan@vvv.xls>
    Re: multidimensional Array <1usa@llenroc.ude.invalid>
    Re: multidimensional Array (Jens Thoms Toerring)
    Re: multidimensional Array <yankeeinexile@gmail.com>
        Need help in writing PCRE <vikrant.kansal@gmail.com>
    Re: Need help in writing PCRE <invalid@invalid.org>
    Re: Need help in writing PCRE <vikrant.kansal@gmail.com>
        pass by reference <larry.grant.dc@gmail.com>
    Re: pass by reference <peter@makholm.net>
    Re: pass by reference <larry.grant.dc@gmail.com>
        perl 5.8.8 make test hangs on ext/Sys/Syslog/t/syslog.. <bdbaddog@gmail.com>
    Re: perl to parse out iostat information on solaris 9 <josef.moellers@fujitsu-siemens.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 09 Aug 2007 05:25:52 -0700
From:  Steve <steve@shrogers.com>
Subject: Re: (Re)announcing APL 2007
Message-Id: <1186662352.731056.47190@q3g2000prf.googlegroups.com>

On Aug 6, 7:20 am, Paul Mansour <p...@carlislegroup.com> wrote:
> On Aug 5, 11:54 pm, Mike Kent <mk...@acm.org> wrote:
>
> > APL 2007 conference on Array Programming
>
> >      co-located with OOPSLA 2007
>
> > Sponsor:              ACM SIGAPL
>
> > Where:                Montreal
>
> > When:                 October 21 (tutorials)
> >                        October 22/23  (main conference program)
>
> APL2007 Roll Call: Is anyone going to this?
>
> I'm thinking about going, but I don't want to the only one to show up,
> as in San Diego.

I'm going.



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

Date: Thu, 09 Aug 2007 13:24:47 +0200
From: "news.t-online.de" <suregeonde@yahoo.de>
Subject: Re: Certfication in AWK or SHell programming
Message-Id: <f9eth3$fn5$02$1@news.t-online.com>

ehabaziz2001@gmail.com wrote:
> Hello,
> can I have any kind of certfifcation in Awk and SED and if the answer
> is NO What is the nearest certfication to SED,AWK and even any
> certfifcation to shell programming?
> Thanks
> 

simply give AWK a call, or SED
http://www.awk.com/
http://www.sed.com/


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

Date: 09 Aug 2007 15:52:05 GMT
From: xhoster@gmail.com
Subject: Re: How i convert a excel file to csv file
Message-Id: <20070809115207.261$fp@newsreader.com>

Santana <paulito.santana@gmail.com> wrote:
> Hei friends,
> i'am new in newbie in Perl, and i try i convert a excel file in csv
> file  in Suse 10.0 linux.
>
> I install the Spreadsheet-ParseExcel-0.32.tar.gz module in my linux
> but when i try run this script :
>
> use strict;
> use Spreadsheet::ParseExcel;
>
>    my $excel =3D Spreadsheet::ParseExcel::Workbook->Parse($file);

$file has not been declared.


>     foreach my $sheet (@{$excel->{Worksheet}}) {
>         printf("Sheet: %s\n", $sheet->{Name});
>         $sheet->{MaxRow} ||=3D $sheet->{MinRow};
>         foreach my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) {
>             $sheet->{MaxCol} ||=3D $sheet->{MinCol};
>             foreach my $col ($sheet->{MinCol} ..  $sheet->{MaxCol}) {
>                 my $cell =3D $sheet->{Cells}[$row][$col];
>                 if ($cell) {
>                     printf("( %s , %s ) =3D> %s\n", $row, $col, $cell-
> >{Val});
>                 }
>             }
>         }
>     }
>
> I have a error something like this :
>
> "Can=B4t locate Spreadsheet.pm in @INC(@INC constains : ............"
>
> Can you help me, please ??

If you want actual help, you should post actual code and actual error, not
"something like" them.

Perhaps you a have an unnecessary line "use Spreadsheet;" somewhere in your
code that you are not showing us.  If so, take it out.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 09 Aug 2007 06:54:09 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How to parse directory structure from FTP LIST
Message-Id: <m2vebp2d2m.fsf@dot-app.org>

lg <lgt@invalid.com> writes:

> usenet@DavidFilmer.com wrote:
>
>>On Aug 8, 11:08 am, lg <l...@invalid.com> wrote:
>>
>>> First of all is the directory list standard? Does file/directory name start at
>>> column 56 etc?
>>
>>> If not how do FTP programs parse info if it's not standardised?
>>
>>FTP output (and even commands) differ widely between systems.

 ...

> If system is only limited to those who understand LIST command is the
> list-file structure standardised/documented somewhere?

No, RFC 959 and its sequels don't specify that - that's why it varies
from server to server, because it's *not* standardized.

Why are you reinventing the wheel instead of using Net::FTP, anyway?

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Thu, 9 Aug 2007 06:23:18 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: How to parse directory structure from FTP LIST
Message-Id: <slrnfblu96.bcl.tadmc@tadmc30.sbcglobal.net>

lg <lgt@invalid.com> wrote:
> usenet@DavidFilmer.com wrote:
>
>>On Aug 8, 11:08 am, lg <l...@invalid.com> wrote:
>>
>>> First of all is the directory list standard? Does file/directory name start at
>>> column 56 etc?
>>
>>> If not how do FTP programs parse info if it's not standardised?


The FTP protocol is standardised. FTP programs are not standardised.


>>But if you want to really assure that the system is as bullet-proof as
>>possible then you should use an FTP module such as Net::FTP

> If system is only limited to those who understand LIST command is the list-file
> structure standardised/documented somewhere?


Maybe. The commands your FTP program have might be documented in the
docs for your FTP program.

But you have already been given the correct solution to your problem,
namely, rely on the FTP protocol (via a module) rather than on a
particular FTP program.

Do you have some reason for not adopting the suggested correct solution?


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Thu, 09 Aug 2007 11:39:20 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: how to tranpose a huge text file
Message-Id: <13blrmphmlsta9@corp.supernews.com>

Jie wrote:
> I have a huge text file with 1000 columns and about 1 million rows,
> and I need to transpose this text file so that row become column and
> column become row. (in case you are curious, this is a genotype file).
> 
> Can someone recommend me an easy and efficient way to transpose such a
> large dataset, hopefully with Perl ?

This is very analagous to the problems
of rotating a (much larger than memory) photograph.

    BugBear


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

Date: Thu, 9 Aug 2007 10:53:45 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: how to tranpose a huge text file
Message-Id: <f9ernp$2ljr$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Mumia W.
<paduille.4061.mumia.w+nospam@earthlink.net>], who wrote in article <13bl688igm6eb03@corp.supernews.com>:
> On 08/08/2007 09:00 PM, Ilya Zakharevich wrote:
> > [A complimentary Cc of this posting was sent to
> > Jie 
> > <jiehuang001@gmail.com>], who wrote in article <1186606584.143555.119720@k79g2000hse.googlegroups.com>:
> >> [...]
> >> Can someone recommend me an easy and efficient way to transpose such a 
> >> large dataset, hopefully with Perl ?
> > 
> > If your CRTL allows opening a 1000 output files, read a line, and 
> > append the entries into corresponding files.  Then cat the files 
> > together.
> > 
> > If your CRTL allows opening only 32 output files, you need 3 passes, 
> > not 2.  [...]
> 
> FileCache might also be useful here.

Do not think so.  What gave you this idea?  You want to open files 1e9
times?

Puzzled,
Ilya


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

Date: Thu, 09 Aug 2007 09:01:09 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: how to tranpose a huge text file
Message-Id: <090820070901097436%jgibson@mail.arc.nasa.gov>

In article <f9e1t8$2g6h$1@ns.felk.cvut.cz>, Petr Vileta
<stoupa@practisoft.cz> wrote:

> Jie wrote:
> > I have a huge text file with 1000 columns and about 1 million rows,
> > and I need to transpose this text file so that row become column and
> > column become row. (in case you are curious, this is a genotype file).
> >
> > Can someone recommend me an easy and efficient way to transpose such a
> > large dataset, hopefully with Perl ?
> >
> > Thank you very much!
> >
> > Jie
> Maybe you will regard my solution as bizzare, but ...
> 
> 1) open your file for read
> 2) open 1000 files for write
> 3) read row of your file
> 4) parse columns
> 5) write 1st column to 1st file, 2nd column to 2nd file etc. but without end 
> of line "\n"
> 6) goto 3 until end of file
> 7) close readed file
> 8) write "\n" to each of 1000 files and close all
> 9) simply join all files to one using system command (cp 0.txt + 1.txt .... 
>  > final.txt)
> 
> This solution not consumpt much memory and should be relatively quick.

Open files do consume a bit of memory: file control blocks,
input/output buffers, etc.

> 
> BTW: I'm curious to reactions of this programmer community :-)

That is a fine approach, except for the practical matter that most
operating systems will not allow a normal user to have 1000 files open
at one time. The limit is 256 for my current system (Mac OS 10.4):

jgibson 34% ulimit -n
256

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: Thu, 09 Aug 2007 09:17:04 -0700
From:  patrick <pgovern@u.washington.edu>
Subject: Re: how to tranpose a huge text file
Message-Id: <1186676224.705635.161690@x40g2000prg.googlegroups.com>

On Aug 8, 1:56 pm, Jie <jiehuang...@gmail.com> wrote:
> I have a huge text file with 1000 columns and about 1 million rows,
> and I need to transpose this text file so that row become column and
> column become row. (in case you are curious, this is a genotype file).
>
> Can someone recommend me an easy and efficient way to transpose such a
> large dataset, hopefully with Perl ?
>
> Thank you very much!
>
> Jie

If you're on UNIX and the columns are fixed length or delimited
you may want to consider using the cut command inside a loop.

Loop from 1 to 1000 to process each column
  cut -f<loop counter> <input file> | perl -e 'while (<>)
{chomp;print;print "|";}print "\n"' >> <output file>

Patrick



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

Date: Thu, 9 Aug 2007 16:38:14 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: how to tranpose a huge text file
Message-Id: <f9fftm$2qko$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Jim Gibson 
<jgibson@mail.arc.nasa.gov>], who wrote in article <090820070901097436%jgibson@mail.arc.nasa.gov>:
> > This solution not consumpt much memory and should be relatively quick.
> 
> Open files do consume a bit of memory: file control blocks,
> input/output buffers, etc.

Peanuts of you do not open a million of files.

> > BTW: I'm curious to reactions of this programmer community :-)
> 
> That is a fine approach, except for the practical matter that most
> operating systems will not allow a normal user to have 1000 files open
> at one time. The limit is 256 for my current system (Mac OS 10.4):
> 
> jgibson 34% ulimit -n
> 256

This is not the limit imposed by your operating system.  Just the
limit suggested by one of the ancessors of your program.  Try raising
ulimit -n; when if fails, it would indicate the limit given by the OS.

Hope this helps,
Ilya


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

Date: 9 Aug 2007 16:51:58 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: if kill 9, $pid fails, is the error caught anywhere?
Message-Id: <5i0v1eF3kqkppU1@mid.dfncis.de>

Ilya Zakharevich  <nospam-abuse@ilyaz.org> wrote in comp.lang.perl.misc:
> [A complimentary Cc of this posting was sent to
> it_says_BALLS_on_your forehead 
> <simon.chao@fmr.com>], who wrote in article
> <1186081732.328530.231760@i13g2000prf.googlegroups.com>:
> > > What OS?  On most OSes, there may be unkillable processes (not even by
> > > root).  [I rememeber getting ones on Solaris 2.6, when the floppy disk
> > > started to misfunction....]
> 
> > This is SunOS 5.8.
> 
> I think it should not matter.  It is hard to imagine an OS
> architecture which would not allow a device driver to define "Do not
> interrupt programs which entered this chunk of my code" flag.
> 
> Anyone with more detailed knowledge?

No knowledge, just anecdotes.

No OS seems to be immune against stuck io calls, but there used to
be huge differences as to how often it happened.  I remember one
particular version of HPUX (I don't remember which, it was about
10 years ago) that had to be rebooted regularly (2-3 times/week)
to get rid of unkillable processes blocking resources.

Other systems were much better in that respect, though none were immune.
I've always assumed that the better ones had a more useful timeout
mechanism.

Whatever the reason, these days I don't see large differences between
systems concerning stuck io calls.  They're generally rare with
standard devices, but since the behavior depends at least in part
on the device driver, one might see more of them with exotic devices.

Anno


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

Date: Thu, 09 Aug 2007 18:04:38 -0000
From:  Larry <larry.grant.dc@gmail.com>
Subject: more elegant way to say ($1, $2, $3, $4, ...)?
Message-Id: <1186682678.852047.101920@k79g2000hse.googlegroups.com>

I'm using a /g regex in a while loop to capture parenthesized matches
to meaningful variable names like this:

while (/ (...) ... (...) ... (...)/g) {
    my ($foo, $bar, $baz) = ($1, $2, $3);
    ...
}

The ($1, $2, $3) part seems inelegant ... is there a more elegant way?

BTW, don't suggest:

while (my ($foo, $bar, $baz) = / (...) ... (...) ... (...)/g) {
    ...
}

That will cause the regex to evaluate in a list context, which changes
the behavior of /g to parse all of $_ at once, only returning the
first match and throwing away the rest.



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

Date: Thu, 9 Aug 2007 17:51:07 +0200
From: "Tristan" <tristan@vvv.xls>
Subject: multidimensional Array
Message-Id: <f9fd5a$ltv$1@ss408.t-com.hr>

how to put more arrays in one?

@array1 = qw(Quarter Dime Nickel Penny);
@array2 = qw(test1 test2 test3 test4);
@array3 = (1,2,3,4,5,6,7,8,9,10);
@array4 = (11,22,33,44,55);


I want to have only one multidimensional array. How to do it?

Thanks.



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

Date: Thu, 09 Aug 2007 16:10:04 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: multidimensional Array
Message-Id: <Xns99877BC67FE5asu1cornelledu@127.0.0.1>

"Tristan" <tristan@vvv.xls> wrote in news:f9fd5a$ltv$1@ss408.t-com.hr:

> how to put more arrays in one?
> 
> @array1 = qw(Quarter Dime Nickel Penny);
> @array2 = qw(test1 test2 test3 test4);
> @array3 = (1,2,3,4,5,6,7,8,9,10);
> @array4 = (11,22,33,44,55);
> 
> 
> I want to have only one multidimensional array. How to do it?

Here is your fish:

my @array = (
   [ qw(Quarter Dime Nickel Penny) ],
   [ qw(test1 test2 test3 test4)   ],
   [ 1 .. 10 ],
   [ 11, 22, 33, 44, 55 ],
);

Here is where you learn how to fish:

perldoc perldsc

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>



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

Date: 9 Aug 2007 16:13:51 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: multidimensional Array
Message-Id: <5i0spvF3mhm0cU1@mid.uni-berlin.de>

Tristan <tristan@vvv.xls> wrote:
> how to put more arrays in one?

> @array1 = qw(Quarter Dime Nickel Penny);
> @array2 = qw(test1 test2 test3 test4);
> @array3 = (1,2,3,4,5,6,7,8,9,10);
> @array4 = (11,22,33,44,55);

> I want to have only one multidimensional array. How to do it?

There are no true multidimensional arrays in Perl. But what you
can use instead is an arrary of array references, e.g.

my @array = ( [ qw( Quarter Dime Nickel Penny ) ],
              [ qw( test1 test2 test3 test4 )   ],
              [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)  ],
		      [ 11, 22, 33, 44, 55              ]  );

Now e.g. $array[1][3] (or $array[1]->[3], if you prefer the
slightly longer version) is the string 'test4'.

                            Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de


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

Date: 09 Aug 2007 11:20:40 -0500
From: Lawrence Statton <yankeeinexile@gmail.com>
Subject: Re: multidimensional Array
Message-Id: <87odhg8ysn.fsf@hummer.cluon.com>

"Tristan" <tristan@vvv.xls> writes:

#!/usr/bin/perl
use strict;
use warnings;

my @array1 = qw(Quarter Dime Nickel Penny);
my @array2 = qw(test1 test2 test3 test4);
my @array3 = (1,2,3,4,5,6,7,8,9,10);
my @array4 = (11,22,33,44,55);

my @blob = ( \@array1, \@array2, \@array3, \@array4 );

print "\$blob[0][3] = $blob[0][3]\n";
print "\$blob[0][3] = $blob[3][4]\n";


% perl ex-1 
$blob[0][3] = Penny
$blob[0][3] = 55

-- 
	Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
place them into the correct order.


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

Date: Thu, 09 Aug 2007 09:44:05 -0700
From:  vikrant <vikrant.kansal@gmail.com>
Subject: Need help in writing PCRE
Message-Id: <1186677845.478430.32450@z24g2000prh.googlegroups.com>

Hi everyone,

I know this not the right place to ask this question but i did not
found any group specific for discussion problem related to PCRE. But,
i believe members of  this forum are having good in writing PCRE thats
why i am posting my question here.

I need ur help in writing the pcre for the following string

string :-   ftp:\\abnssjs%20jfdhjdh.htc%00.mnd

Now, what i need to match is "ftp:" "anything in between except i.e
^(%00)" followed by "%00" then Dot

What i have tried so far is

1.   /ftp:.*%00./i   but .* match any thing including %00 (except
newline)
2.  /ftp:(^\%00)*./i  It's not working.
3. /ftp:^(%00)*./i  It's not working.

The problem is ignore any character till particular string i.e "%00"
not come.

So,please help me out.

Regards,
Vikrant



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

Date: Thu, 09 Aug 2007 19:26:15 +0200
From: David Sudlow <invalid@invalid.org>
Subject: Re: Need help in writing PCRE
Message-Id: <46bb4e40$0$27395$ba4acef3@news.orange.fr>

vikrant wrote:
> Hi everyone,
> 
> I know this not the right place to ask this question but i did not
> found any group specific for discussion problem related to PCRE. But,
> i believe members of  this forum are having good in writing PCRE thats
> why i am posting my question here.
> 
> I need ur help in writing the pcre for the following string
> 
> string :-   ftp:\\abnssjs%20jfdhjdh.htc%00.mnd
> 
> Now, what i need to match is "ftp:" "anything in between except i.e
> ^(%00)" followed by "%00" then Dot
> 
> What i have tried so far is
> 
> 1.   /ftp:.*%00./i   but .* match any thing including %00 (except
> newline)
> 2.  /ftp:(^\%00)*./i  It's not working.
> 3. /ftp:^(%00)*./i  It's not working.
> 
> The problem is ignore any character till particular string i.e "%00"
> not come.
> 
> So,please help me out.
> 
> Regards,
> Vikrant
> 

1. was pretty close but you forgot to escape the literal .
try
/ftp:.*%00\./i


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

Date: Thu, 09 Aug 2007 10:51:21 -0700
From:  vikrant <vikrant.kansal@gmail.com>
Subject: Re: Need help in writing PCRE
Message-Id: <1186681881.595780.280790@e16g2000pri.googlegroups.com>

On Aug 9, 10:26 pm, David Sudlow <inva...@invalid.org> wrote:
> vikrant wrote:
> > Hi everyone,
>
> > I know this not the right place to ask this question but i did not
> > found any group specific for discussion problem related to PCRE. But,
> > i believe members of  this forum are having good in writing PCRE thats
> > why i am posting my question here.
>
> > I need ur help in writing the pcre for the following string
>
> > string :-   ftp:\\abnssjs%20jfdhjdh.htc%00.mnd
>
> > Now, what i need to match is "ftp:" "anything in between except i.e
> > ^(%00)" followed by "%00" then Dot
>
> > What i have tried so far is
>
> > 1.   /ftp:.*%00./i   but .* match any thing including %00 (except
> > newline)
> > 2.  /ftp:(^\%00)*./i  It's not working.
> > 3. /ftp:^(%00)*./i  It's not working.
>
> > The problem is ignore any character till particular string i.e "%00"
> > not come.
>
> > So,please help me out.
>
> > Regards,
> > Vikrant
>
> 1. was pretty close but you forgot to escape the literal .
> try
> /ftp:.*%00\./i

Hi David,

Thanks for the reply.You are right i forgot this but my problem is
still persist because the problem occurring in  .*

 /ftp:.*%00\./i

here this pcre first matches "ftp:" then "any thing including %00
(except newline) because of .* " which i don't want.I want it to match
anything till it'll not find any "%00" then match DOT

Please correct me if i am wrong.

Regards,
Vikrant



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

Date: Thu, 09 Aug 2007 17:50:50 -0000
From:  Larry <larry.grant.dc@gmail.com>
Subject: pass by reference
Message-Id: <1186681850.185112.255040@g4g2000hsf.googlegroups.com>

The following code snippet shows how I do "pass by reference" in
Perl.  It works fine, but I'm wondering... is there a less verbose way
to do this?

(I know in this simple example, I could avoid the typeglob assignment
and just use $$arg instead of $arg, but in a more complex usage, that
would bug me... I'd rather just use the more normal-looking $arg
everywhere.)

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

sub squareMe (\$) {
    my ($argRef) = @_;
    local *arg = $argRef;
    our $arg;

    $arg *= $arg;
}

my $n = 7;
squareMe $n;
print "$n\n";  # prints 49



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

Date: Thu, 09 Aug 2007 18:04:08 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: pass by reference
Message-Id: <871wecinzb.fsf@hacking.dk>

Larry <larry.grant.dc@gmail.com> writes:

> The following code snippet shows how I do "pass by reference" in
> Perl.  It works fine, but I'm wondering... is there a less verbose way
> to do this?

Perl already implements a kind of pass by reference in the @_
argument.

#!/usr/bin/perl -l
sub squareMe {
    $_[0] *= $_[0];
}

my $n = 7;
squareMe $n;
print $n;  # Does indeed print 49

__END__

> (I know in this simple example, I could avoid the typeglob assignment
> and just use $$arg instead of $arg, but in a more complex usage, that
> would bug me... I'd rather just use the more normal-looking $arg
> everywhere.)

No, using pass by reference isn't the normal case, so hiding it will
only make you code more obscure and less maintainable when you forget
whatever samrtness you have put into the code.

Pass by reference can be useful, but keep it well documented and let
it stand out.

//Makholm


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

Date: Thu, 09 Aug 2007 18:05:47 -0000
From:  Larry <larry.grant.dc@gmail.com>
Subject: Re: pass by reference
Message-Id: <1186682747.757896.223810@o61g2000hsh.googlegroups.com>

On Aug 9, 2:04 pm, Peter Makholm <pe...@makholm.net> wrote:
> Larry <larry.grant...@gmail.com> writes:
> > The following code snippet shows how I do "pass by reference" in
> > Perl.  It works fine, but I'm wondering... is there a less verbose way
> > to do this?
>
> Perl already implements a kind of pass by reference in the @_
> argument.
>
> #!/usr/bin/perl -l
> sub squareMe {
>     $_[0] *= $_[0];
>
> }
>
> my $n = 7;
> squareMe $n;
> print $n;  # Does indeed print 49
>
> __END__
>
> > (I know in this simple example, I could avoid the typeglob assignment
> > and just use $$arg instead of $arg, but in a more complex usage, that
> > would bug me... I'd rather just use the more normal-looking $arg
> > everywhere.)
>
> No, using pass by reference isn't the normal case, so hiding it will
> only make you code more obscure and less maintainable when you forget
> whatever samrtness you have put into the code.
>
> Pass by reference can be useful, but keep it well documented and let
> it stand out.
>
> //Makholm

I don't like the $_[0] method, because it doesn't give me a chance to
name my variables.... I prefer names, not numbers, thank you!  :)



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

Date: Thu, 09 Aug 2007 16:47:51 -0000
From:  Bad Dog <bdbaddog@gmail.com>
Subject: perl 5.8.8 make test hangs on ext/Sys/Syslog/t/syslog................... indefinitely
Message-Id: <1186678071.125160.229360@i13g2000prf.googlegroups.com>

Building perl 5.8.8 on Red Hat Enterprise Linux WS release 3 (Taroon
Update 6)

When I run make test the ext/Sys/Syslog/t/syslog test hangs
indefinitely.
How do I go about debugging what's causing the hang?

Thanks,
Billl



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

Date: Thu, 09 Aug 2007 12:51:13 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: perl to parse out iostat information on solaris 9
Message-Id: <f9erj4$35b$2@nntp.fujitsu-siemens.com>

anno4000@radom.zrz.tu-berlin.de wrote:
> Tad McClellan  <tadmc@seesig.invalid> wrote in comp.lang.perl.misc:

>=20
>>Another solution would be to discard the empty leading field:
>>
>>    (undef, $usrcpu, $syscpu, $wiocpu, $idlecpu) =3D split(/\s+/, $CPU)=
;
>=20
>=20
> That is only a solution if the empty field is guaranteed to be present.=

> Since we don't know the format of the line, that's not a given.

In these circumstances (parsing /proc/interrupts on a Linux machine),=20
I've done it like this:

my @f =3D split(/\s+/, $line);
shift @f unless length $f[0];

Josef
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html



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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 733
**************************************


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