[29505] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 749 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 13 06:09:43 2007

Date: Mon, 13 Aug 2007 03:09:07 -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           Mon, 13 Aug 2007     Volume: 11 Number: 749

Today's topics:
        ANNOUNCE: Javascript::MD5 V 1.06 <ron@savage.net.au>
        Car Air Conditioners <digitalplusmail@gmail.com>
    Re: Directory change and system xhoster@gmail.com
    Re: Directory change and system <noreply@gunnar.cc>
    Re: Directory change and system <bill@ts1000.us>
    Re: Directory change and system (Randal L. Schwartz)
    Re: File::Find problem? (Randal L. Schwartz)
    Re: File::Find problem? (Randal L. Schwartz)
    Re: how to tranpose a huge text file <nospam-abuse@ilyaz.org>
        Javascript::SHA1 V 1.03 <ron@savage.net.au>
        new CPAN modules on Mon Aug 13 2007 (Randal Schwartz)
    Re: Optimized count of files in tree (Randal L. Schwartz)
    Re: Optimized count of files in tree <quetzalcotl@consultant.com>
        Pass by reference question <cdalten@gmail.com>
    Re: Pass by reference question <spamtrap@dot-app.org>
    Re: Pass by reference question <cdalten@gmail.com>
    Re: Pass by reference question (Jens Thoms Toerring)
    Re: Pass by reference question <josef.moellers@fujitsu-siemens.com>
    Re: Pass by reference question <josef.moellers@fujitsu-siemens.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 12 Aug 2007 04:15:25 GMT
From: Ron Savage <ron@savage.net.au>
Subject: ANNOUNCE: Javascript::MD5 V 1.06
Message-Id: <JMox6A.59p@zorch.sf-bay.org>

The pure Perl module Javascript::MD5 V 1.06
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.

On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.

An extract from the docs:

1.06  Sat Aug 04 13:52:00 2007
	- Extend method javascript() to take a second parameter,
	which is the number of the CGI form within the HTML page.
	The allows the module to operate on an HTML page containing
	more than one CGI form.
	The default value is 0, which is the first form, and perhaps
	the only form, on the page. So, no need to upgrade if you
	only have one form per page
	- Update the docs to describe this new parameter
	- Note: Original patch kindly supplied by Thomas Goik
-- 
Ron Savage
ron@savage.net.au
http://savage.net.au/




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

Date: Mon, 13 Aug 2007 08:18:55 -0000
From:  Lepi Duja <digitalplusmail@gmail.com>
Subject: Car Air Conditioners
Message-Id: <1186993135.781943.172330@l70g2000hse.googlegroups.com>

All the informations about car air conditioners can be found on this
website...

http://car-air-conditioning.blogspot.com/



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

Date: 12 Aug 2007 21:47:05 GMT
From: xhoster@gmail.com
Subject: Re: Directory change and system
Message-Id: <20070812174707.923$g5@newsreader.com>

Bill H <bill@ts1000.us> wrote:
> I am using system in script to run ImageMagick top convert a file to a
> different format, but for it to work I have to be in the directory
> that the file is in before doing the system.

I haven't used ImageMagick, but that seems like an odd requirement for it
to make.  Are you sure there isn't another way to accomplish the task?

> What would be the best
> way of saving the current directory, change to the new one, doing my
> system and then going back to the old one?

If you can't figure out how to overcome the need to chdir at all,
then I'd just add a "cd /whatever/dir;" to the front of the string
you are passing to system (assuming you are using the single-argument
form of system).  That way you don't have to worry about changing back,
plus if you ever add threads to your code you don't have to worry
about the chdir complications.

Xho

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


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

Date: Mon, 13 Aug 2007 00:39:34 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Directory change and system
Message-Id: <5i9gh8F3nthc8U1@mid.individual.net>

Bill H wrote:
> I am using system in script to run ImageMagick

Why don't you use the Perl module Image::Magick as the interface to the 
IM library? Then I guess you wouldn't have that chdir issue.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Sun, 12 Aug 2007 18:12:55 -0700
From:  Bill H <bill@ts1000.us>
Subject: Re: Directory change and system
Message-Id: <1186967575.202241.12210@57g2000hsv.googlegroups.com>

On Aug 12, 6:39 pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> Bill H wrote:
> > I am using system in script to run ImageMagick
>
> Why don't you use the Perl module Image::Magick as the interface to the
> IM library? Then I guess you wouldn't have that chdir issue.
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl

Gunnar

I looked at that and will try that again, but it wasnt working right,
and for what I need to do, simple conversions from one format to
another, it seems much easier (and probably faster) just to use a
system and use convert.

Bill H



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

Date: Sun, 12 Aug 2007 20:38:20 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Directory change and system
Message-Id: <86sl6oje8j.fsf@blue.stonehenge.com>

>>>>> "Bill" == Bill H <bill@ts1000.us> writes:

Bill> I am using system in script to run ImageMagick top convert a file to a
Bill> different format, but for it to work I have to be in the directory
Bill> that the file is in before doing the system. What would be the best
Bill> way of saving the current directory, change to the new one, doing my
Bill> system and then going back to the old one?

Keep in mind that system("date") is essentially:

    defined (my $kid = fork) or die "Cannot fork: $!";
    unless ($kid) {
      # put your chdir here
      exec "date";
      die "date not found"; # just like me last friday night
    }
    waitpid($kid, 0);

So add your chdir where it says.  It affects only the kid.

print "Just another Perl hacker,"; # the original

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Sun, 12 Aug 2007 20:41:12 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: File::Find problem?
Message-Id: <86k5s0je3r.fsf@blue.stonehenge.com>

>>>>> "Henry" == Henry Law <news@lawshouse.org> writes:

Henry> This, for example, is based on your code and works on my Win XP machine. (I've
Henry> replaced your "hdr" extension with "doc" for convenience).

Try an example with a subdir, and it won't.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Sun, 12 Aug 2007 20:40:12 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: File::Find problem?
Message-Id: <86odhcje5f.fsf@blue.stonehenge.com>

>>>>> "Monty" == Monty  <dale.schmitz@offutt.af.mil> writes:

Monty> I'm using the File::Find module to search through a directory tree and
Monty> perform operations on files with a .hdr suffix for the file name.  I
Monty> have a test environment set up and known defects in the files, but I
Monty> get an error I hadn't expected with the find() function.  The set up
Monty> is like this:

Monty> use File::Find;

Monty> find (\&process_file,".");

Monty> sub process_file {
Monty>     if (/\.hdr/) {
Monty>         print "$File::Find::name\n";
Monty>         open HDR_FILE, "<$File::Find::name" or die "Can't open file
Monty> for input: $!\n";
Monty>         ...etc.

Monty> It prints the correct file name, complete with relative path, but it
Monty> dies on the open statement every time. What am I doing wrong?

You are opening $File::Find::name while still in the context of the
callback.  You should either (a) put $File::Find::name into an array
to process when everything is done or (b) use $_ instead of $File::Find::name,
which is properly adjusted for the current directory.

File::Find does a whole lot of chdir'ing.  So you have to comply.

print "Just another Perl hacker,"; # the original

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Sun, 12 Aug 2007 23:39:00 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: how to tranpose a huge text file
Message-Id: <f9o5mk$21l3$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Ted Zlatanov 
<tzz@lifelogs.com>], who wrote in article <m2fy2p542l.fsf@lifelogs.com>:
> On Sun, 12 Aug 2007 06:19:37 +0000 (UTC) Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote: 
> IZ> Doing one "SELECT column FROM table" (which results in a megaarray)
> IZ> may be not *that* slow - given quick enough hardware.  Doing it 1000
> IZ> times would unravel all the missing optimizations in the
> IZ> implementation of the database.
> 
> You don't have to get all the results of a SELECT at once.  You can
> fetch each row of the result set, which does not generate a large array.

Fetching by rows is trivial (with data at hand).  It is fetching by
columns which leads to very hard-to-optimize signature of disk access.

> I don't know the internal mechanics of result set management in the
> various databases on the market, nor do I want to; from practical
> experience with large result sets under Oracle I can tell you that
> performance is quite good there.  Do you want benchmarks to be convinced?

Sure, I would be very much interested.

E.g., on a machine with 512MB memory, create a 1e3 x 1e6 array with 5bit
entries.  Then access all its columns one-by-one, then all its rows
one-by-one.  This would mimic the problem at hand.

Thanks,
Ilya


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

Date: Sun, 12 Aug 2007 04:16:40 GMT
From: Ron Savage <ron@savage.net.au>
Subject: Javascript::SHA1 V 1.03
Message-Id: <JMox6I.5AF@zorch.sf-bay.org>

The pure Perl module Javascript::SHA1 V 1.03
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.

On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.

An extract from the docs:

1.03  Sat Aug 04 13:52:00 2007
	- Extend method javascript() to take a second parameter,
	which is the number of the CGI form within the HTML page.
	The allows the module to operate on an HTML page containing
	more than one CGI form.
	The default value is 0, which is the first form, and perhaps
	the only form, on the page. So, no need to upgrade if you
	only have one form per page
	- Update the docs to describe this new parameter
	- Note: Original patch kindly supplied by Thomas Goik
-- 
Ron Savage
ron@savage.net.au
http://savage.net.au/




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

Date: Mon, 13 Aug 2007 04:42:19 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Mon Aug 13 2007
Message-Id: <JMp3qJ.B58@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Acme-ESP-1.001004
http://search.cpan.org/~tyemq/Acme-ESP-1.001004/
The power to implant and extract strings' thoughts. 
----
Acme-ESP-1.001005
http://search.cpan.org/~tyemq/Acme-ESP-1.001005/
The power to implant and extract strings' thoughts. 
----
Acme-ESP-1.001006
http://search.cpan.org/~tyemq/Acme-ESP-1.001006/
The power to implant and extract strings' thoughts. 
----
Atompub-0.0.1
http://search.cpan.org/~takeru/Atompub-0.0.1/
Atom Publishing Protocol implementation 
----
Bricklayer-Templater-0.9
http://search.cpan.org/~zaphar/Bricklayer-Templater-0.9/
yet another templating system. Pure perl, highly flexible with very few dependincies. 
----
Business-ISBN-2.01
http://search.cpan.org/~bdfoy/Business-ISBN-2.01/
work with International Standard Book Numbers 
----
CPAN-Testers-0.01
http://search.cpan.org/~fhoxh/CPAN-Testers-0.01/
QA of CPAN distributions via cross-platform testing 
----
CPAN-Testers-0.02
http://search.cpan.org/~fhoxh/CPAN-Testers-0.02/
QA of CPAN distributions via cross-platform testing 
----
DBIx-Class-0.08006
http://search.cpan.org/~ash/DBIx-Class-0.08006/
Extensible and flexible object <-> relational mapper. 
----
Devel-PPPort-3.11_02
http://search.cpan.org/~mhx/Devel-PPPort-3.11_02/
Perl/Pollution/Portability 
----
Devel-Size-0.69
http://search.cpan.org/~tels/Devel-Size-0.69/
Perl extension for finding the memory usage of Perl variables 
----
Devel-Timer-0.04
http://search.cpan.org/~szabgab/Devel-Timer-0.04/
Track and report execution time for parts of code 
----
Egg-Release-2.21
http://search.cpan.org/~lushe/Egg-Release-2.21/
Version of Egg WEB Application Framework. 
----
FabForce-DBDesigner4-DBIC-0.04
http://search.cpan.org/~reneeb/FabForce-DBDesigner4-DBIC-0.04/
create DBIC scheme for DBDesigner4 xml file 
----
File-Fcntl_Lock-0.08
http://search.cpan.org/~jtt/File-Fcntl_Lock-0.08/
File locking with fcntl(2) 
----
Games-Bingo-0.15
http://search.cpan.org/~jonasbn/Games-Bingo-0.15/
a bingo game Perl implementation 
----
Graph-0.83
http://search.cpan.org/~jhi/Graph-0.83/
graph data structures and algorithms 
----
Graph-Convert-0.08
http://search.cpan.org/~tels/Graph-Convert-0.08/
Convert between graph formats: Graph and Graph::Easy 
----
Graph-Easy-0.57
http://search.cpan.org/~tels/Graph-Easy-0.57/
Render graphs as ASCII, HTML, SVG or via Graphviz 
----
Graph-Easy-Manual-0.39
http://search.cpan.org/~tels/Graph-Easy-Manual-0.39/
HTML manual for Graph::Easy 
----
Kx-0.02
http://search.cpan.org/~markpf/Kx-0.02/
Perl extension for Kdb+ http://kx.com 
----
Kx-0.03
http://search.cpan.org/~markpf/Kx-0.03/
Perl extension for Kdb+ http://kx.com 
----
Language-MuldisD-0.4.1
http://search.cpan.org/~duncand/Language-MuldisD-0.4.1/
Formal spec of Muldis D relational DBMS lang 
----
Perl-Critic-More-0.16
http://search.cpan.org/~cdolan/Perl-Critic-More-0.16/
Supplemental policies for Perl::Critic 
----
Perl-Repository-APC-1.259
http://search.cpan.org/~andk/Perl-Repository-APC-1.259/
Class modelling "All Perl Changes" repository 
----
Plucene-Plugin-Analyzer-MetaphoneAnalyzer-1.01
http://search.cpan.org/~alansz/Plucene-Plugin-Analyzer-MetaphoneAnalyzer-1.01/
Metaphone analyzer 
----
SOAP-WSDL-2.00_09
http://search.cpan.org/~mkutter/SOAP-WSDL-2.00_09/
SOAP with WSDL support 
----
Test-Env-1.08
http://search.cpan.org/~bdfoy/Test-Env-1.08/
test the environment 
----
Test-Reporter-1.34
http://search.cpan.org/~fhoxh/Test-Reporter-1.34/
sends test results to cpan-testers@perl.org 
----
Test-URI-1.07
http://search.cpan.org/~bdfoy/Test-URI-1.07/
Check Uniform Resource Identifiers 
----
Tie-Trace-0.06
http://search.cpan.org/~ktat/Tie-Trace-0.06/
easy print debugging with tie, for watching variable 
----
Tie-Trace-0.07
http://search.cpan.org/~ktat/Tie-Trace-0.07/
easy print debugging with tie, for watching variable 
----
Time-Fuzzy-0.31
http://search.cpan.org/~jquelin/Time-Fuzzy-0.31/
Time read like a human, with some fuzziness 
----
Time-Fuzzy-0.32
http://search.cpan.org/~jquelin/Time-Fuzzy-0.32/
Time read like a human, with some fuzziness 
----
Time-Fuzzy-0.33
http://search.cpan.org/~jquelin/Time-Fuzzy-0.33/
Time read like a human, with some fuzziness 
----
WWW-Scraper-ISBN-AmazonDE_Driver-0.01
http://search.cpan.org/~reneeb/WWW-Scraper-ISBN-AmazonDE_Driver-0.01/
Search driver for the (DE) Amazon online catalog. 
----
WebService-Recruit-Dokoiku-0.07
http://search.cpan.org/~kawasaki/WebService-Recruit-Dokoiku-0.07/
A Interface for Dokoiku Web Service Beta 
----
WebService-Recruit-Jalan-0.07
http://search.cpan.org/~kawasaki/WebService-Recruit-Jalan-0.07/
A Interface for Jalan Web Service 
----
WebService-TimeLine-0.01
http://search.cpan.org/~kazeburo/WebService-TimeLine-0.01/
Perl interface to @nifty TimeLine API 
----
XML-Atom-Service-0.14.0
http://search.cpan.org/~takeru/XML-Atom-Service-0.14.0/
Atom Service Document object 
----
XML-OverHTTP-0.07
http://search.cpan.org/~kawasaki/XML-OverHTTP-0.07/
A base class for XML over HTTP-styled web service interface 
----
XML-Parser-YahooRESTGeocode-0.2
http://search.cpan.org/~ahicox/XML-Parser-YahooRESTGeocode-0.2/
an XML::Parser subclass for parsing results returned from YAHOO REST geocode webservice 
----
XML-TreePP-0.27
http://search.cpan.org/~kawasaki/XML-TreePP-0.27/
Pure Perl implementation for parsing/writing xml files 
----
forks-0.25
http://search.cpan.org/~rybskej/forks-0.25/
drop-in replacement for Perl threads using fork() 
----
namespace-clean-0.05
http://search.cpan.org/~phaylon/namespace-clean-0.05/
Keep imports and functions out of your namespace 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Sun, 12 Aug 2007 20:35:23 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Optimized count of files in tree
Message-Id: <86wsw0jedg.fsf@blue.stonehenge.com>

>>>>> "Patrick" == Patrick  <patrick@frii.fr> writes:

Patrick> In an application I write in Perl, I must count the total number of files (not
Patrick> directories) in a complete tree.

You haven't clarified whether you want to count a symlink pointing
at a file as a separate file or not.  Your code counts it separately,
even if it's pointing at a file not in your starting tree.

Patrick> 	recurse { -f && $nb++ } $dir;

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Mon, 13 Aug 2007 01:58:42 -0700
From:  Ingo Menger <quetzalcotl@consultant.com>
Subject: Re: Optimized count of files in tree
Message-Id: <1186995522.547300.19260@o61g2000hsh.googlegroups.com>

On 12 Aug., 17:40, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
> On Sun, 12 Aug 2007 16:44:14 +0200, Patrick wrote:
> > Thanks for your answer but I have tried with File::Find : I got exactly
> > the same time for the same tree : 16 seconds for 10,000 files.
>
> > I have also tried with a "manual" solution :
>
> > sub getFileNb {
> >    my $nb = 0;
>
> >    return if ! opendir DIR,$_;
> >    my @list = readdir DIR;
> >    closedir DIR;
>
> >    $nb += grep { -f "$dir/$_" } @list;
> >    my @subdirs = grep { /^[^\.]/ && -d "$dir/$_" } @list;
>
> >    foreach ( @subdirs ) {
> >      $nb += &getFileNb("$dir/$_");
> >    }
>
> >    return $nb;
> > }
>
> > The result is about the same : 16 seconds for my 10,000 files.
>
> > I search for a really better performance ...
>
> Looks like IO is the bottleneck. If you are on unix, do a
>
> $ time find . -type f | wc -l
>
> and see if that is significantly faster. If not, get a faster harddisk,
> put the files on another (fast(er)) harddisk, switch to raid, add more
> memory so you have more buffers, tume OS parameters, use another type of
> filesystem. Mix and match to taste.

And, in addition, repeat the command to see whether it get's faster
the second time. Most likely, the directory blocks to be read will be
already in memory so the 2nd attempt may be that much faster.




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

Date: Sun, 12 Aug 2007 19:26:54 -0700
From:  grocery_stocker <cdalten@gmail.com>
Subject: Pass by reference question
Message-Id: <1186972014.120403.171610@e9g2000prf.googlegroups.com>

If perl can pass stuff by reference, then why do you have to deference
it. Like for example

@tailings = popmany ( \@a, \@b, \@c, \@d );


    sub popmany {
        my $aref;
        my @retlist = ();
        foreach $aref ( @_ ) {
            push @retlist, pop @$aref;
        }
        return @retlist;
    }


Wouldn't it be more accurate to say that perl passes the reference by
value? I just find this sort of odd because in both Java (withc uses
pass the reference by value) and C++ (which supports pass by
reference), I never recall having to dereference a reference like what
I have to in perl.



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

Date: Sun, 12 Aug 2007 22:34:12 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Pass by reference question
Message-Id: <m2myww88nv.fsf@dot-app.org>

grocery_stocker <cdalten@gmail.com> writes:

> Wouldn't it be more accurate to say that perl passes the reference by
> value?

Yes. So why did you say it passes by reference, when you already know a
more accurate way of saying it?

> I just find this sort of odd because in both Java ... and C++ ...

Perl is Perl. It's neither Java nor C++. Leave your preconceptions at
the door please.

sherm--

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


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

Date: Sun, 12 Aug 2007 19:41:32 -0700
From:  grocery_stocker <cdalten@gmail.com>
Subject: Re: Pass by reference question
Message-Id: <1186972892.307863.73590@i38g2000prf.googlegroups.com>

On Aug 12, 7:34 pm, Sherm Pendley <spamt...@dot-app.org> wrote:
> grocery_stocker <cdal...@gmail.com> writes:
> > Wouldn't it be more accurate to say that perl passes the reference by
> > value?
>
> Yes. So why did you say it passes by reference, when you already know a
> more accurate way of saying it?
>

Because too my knowledge, ALL the perldocs and perl books say perl
just passes the reference. I couldn't find anything in the perldocs
that would hint that perl uses 'pass  the reference by value'.




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

Date: 13 Aug 2007 09:43:05 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: Pass by reference question
Message-Id: <5iand9F3nlkotU1@mid.uni-berlin.de>

grocery_stocker <cdalten@gmail.com> wrote:
> If perl can pass stuff by reference, then why do you have to deference
> it.

No, you can't. Perl only allows to pass scalars to functions and
those are passed by value. The only thing that's a bit special
in Perl is that if you e.g. have an argument that is an array it
automatically gets converted into a list of scalars and the values
of these scalars get passed to the subroutine. (Other languages
have similar ways that may look strange at a first glance, e.g.
in C and C++ if you use an array as the argument of a function
it automatically gets converted into a pointer to the first
element of the array and this value is passed to the function.)

> Like for example

> @tailings = popmany ( \@a, \@b, \@c, \@d );

Sorry, but here you pass scalars to Perl whose values are
references. This is not the same as "passing by reference".
"Passing by reference" means that an argument automatically
gets converted to a reference and that within the subroutine
receiving it in all places the argument is also automatically
dereferenced without you having to spell it out explicitely.

Compare the these two C++ functions: that do the same thing:

void foo_by_val( int* i ) {
    *i = 3;
}

void foo_by_ref( int& i ) {
    i = 3;
}

The first one you would have to call as

int x;
foo_by_val( &x );

and the second as

foo_by_ref( x );

Perl only has an equivalent for the foo_by_val() function but
not for foo_by_val().

>     sub popmany {
>         my $aref;
>         my @retlist = ();
>         foreach $aref ( @_ ) {
>             push @retlist, pop @$aref;
>         }
>         return @retlist;
>     }

> Wouldn't it be more accurate to say that perl passes the reference by
> value? 

It's redundant since Perl only passes by value. A reference is
nothing than a scalar (basically what you would call a pointer
in C or C++) and scalars, the only things you can pass to sub-
routines, are always passed by values.

> I just find this sort of odd because in both Java (withc uses
> pass the reference by value) and C++ (which supports pass by
> reference), I never recall having to dereference a reference like what
> I have to in perl.

You have to because Perl (like e.g. C but unlike Java or C++)
simply doesn't do "pass by reference", just "pass by value".

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


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

Date: Mon, 13 Aug 2007 11:52:03 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Pass by reference question
Message-Id: <f9p9k6$660$1@nntp.fujitsu-siemens.com>

Jens Thoms Toerring wrote:
> grocery_stocker <cdalten@gmail.com> wrote:
>=20
>>If perl can pass stuff by reference, then why do you have to deference
>>it.
>=20
>=20
> No, you can't. Perl only allows to pass scalars to functions and
> those are passed by value.

Why, then, does the following script print "Bar"?

sub f($) {
    $_[0] =3D 'Bar';
}
my $v =3D 'Foo';
f($v);
print "$v\n";

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: Mon, 13 Aug 2007 11:54:21 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Pass by reference question
Message-Id: <f9p9oh$660$3@nntp.fujitsu-siemens.com>

Jens Thoms Toerring wrote:
> grocery_stocker <cdalten@gmail.com> wrote:
>=20
>>If perl can pass stuff by reference, then why do you have to deference
>>it.
>=20
>=20
> No, you can't. Perl only allows to pass scalars to functions and
> those are passed by value.

Why, then, does the following script print "Bar"?

sub f($) {
    $_[0] =3D 'Bar';
}
my $v =3D 'Foo';
f($v);
print "$v\n";

And what does this script's error message tell us?

sub f($) {
    $_[0] =3D 'Bar';
}
f('Foo');

With all due respect,

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


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