[29876] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1119 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 15 06:09:42 2007

Date: Sat, 15 Dec 2007 03:09:11 -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           Sat, 15 Dec 2007     Volume: 11 Number: 1119

Today's topics:
    Re: (1)[0] ok but not 1[0] <hjp-usenet2@hjp.at>
    Re: Archive::Zip on windows <rkb@i.frys.com>
        Binary to Hexadecimal conversion <pradeep.bg@gmail.com>
    Re: Binary to Hexadecimal conversion <noreply@gunnar.cc>
    Re: Binary to Hexadecimal conversion <1usa@llenroc.ude.invalid>
    Re: Binary to Hexadecimal conversion (Doug Miller)
    Re: Binary to Hexadecimal conversion <jurgenex@hotmail.com>
    Re: FAQ 4.3 Why isn't my octal data interpreted correct <sensorflo@gmail.com>
    Re: How to write a "caller-inspecting" module? <ced@blv-sam-01.ca.boeing.com>
        new CPAN modules on Sat Dec 15 2007 (Randal Schwartz)
    Re: Question about "undef'ing" variables <stoupa@practisoft.cz>
    Re: Question about "undef'ing" variables <joe@inwap.com>
        value or reference inside foreach <expr>? <xueweizhong@gmail.com>
    Re: value or reference inside foreach <expr>? <xueweizhong@gmail.com>
    Re: value or reference inside foreach <expr>? <xueweizhong@gmail.com>
    Re: value or reference inside foreach <expr>? <krahnj@telus.net>
    Re: value or reference inside foreach <expr>? <xueweizhong@gmail.com>
    Re: value or reference inside foreach <expr>? <xueweizhong@gmail.com>
    Re: value or reference inside foreach <expr>? <xueweizhong@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 15 Dec 2007 10:58:27 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <slrnfm79a9.vs5.hjp-usenet2@hrunkner.hjp.at>

On 2007-12-13 16:52, Uri Guttman <uri@stemsystems.com> wrote:
>>>>>> "FK" == Florian Kaufmann <sensorflo@gmail.com> writes:
>  FK> Maybe you are right and I shouldn't make it public, because it will
>  FK> definitely have much more mistakes in it than any official
>  FK> documentation. So there is a concern that it would only confuse
>  FK> people. Then again maybe there are people who can profit from it.
>  FK> Maybe I have to make it very very clear in the abstract and/or
>  FK> introduction that it's a book written by a non-professional and thus
>  FK> will contain tons of mistakes.
>
> then why even do it if it will have so many mistakes?

I'm not sure what you mean by "do it". Writing the tutorial or
publishing it? For the first: Trying to put concepts into your own words
is a good way to clarify them. As you try to write it down you will find
that you are unsure about some aspects and do some more research. 
As for the second: Trying to explain something to somebody else will
further clarify the concept (as you don't only need to think of some
words, but words that somebody else will understand) and will also shake
out many misconceptions, because you will have to answer all those pesky
"why ..." and "yes, but ..." questions.

I often find that I haven't understood something until I've successfully
explained it to somebody else. However, explaining face to face is much
better there than writing it down because you can see when the other
guy's eyes begin to glaze over - otherwise you never know if somebody
bothered to read your stuff at all and if they did whether they
understood it. 

Maybe usenet postings are a reasonable compromise: Write short articles
about perl. If you got it right, it the article will be added to the
collective wisdom of the newsgroup. If you are unclear or wrong, people
will point it out.

	hp



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

Date: Fri, 14 Dec 2007 21:10:06 -0800 (PST)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: Archive::Zip on windows
Message-Id: <0944afec-6aa5-401f-913b-19025368d80d@t1g2000pra.googlegroups.com>

On Dec 14, 5:12 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth ebm <ebmarq...@gmail.com>:
>
>
>
> > I'm trying to have Archive::Zip zip a file on a windows systems.  When
> > I create this file using the full path I end up with an empty zip
> > file.
> > Example:
> > use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
>
> >            my $file = 'c:/TEST.xls';
> >            my $zip = Archive::Zip->new();
> >            print STDOUT "Adding $file\n";
>
> >            $zip->addFile($file) or warn "Error adding file $file\n";
> >            die "write error." if $zip->writeToFileNamed ("c:/file.zip") !=
> > AZ_OK;
>
> > __END__
>
> > I will end up with c:/file.zip but it will be empty.  Now If I copy
> > the xls file to the same directory the script is running in it will be
> > zipped into c:/file.zip.  It seems to be something to do with the C:\
> > part of the path it doesn't like.  The pod file says something about
> > using Unix file formats.....  Am i screwed or is there a way around
> > this.
I tested your code as well as a couple slight variations and they all
worked for me.
>
> Try specifying a separate path to store the file as in the zip: a zip
> member cannot have a volume specification. So:
That is not correct.  The volume specification will be stripped from
the first parameter, but if you supply it in the optional second
parameter, it will be retained in the zip.
>
>     $zip->addFile($file, 'TEST.xls');
>
> or use File::Spec to split up the path and join it back together, sans
> volume, as a Unix filespec.
>
The following test script worked for me and retained the volume spec
in the zip, without the need to use File::Spec.

The script was ran from and executed as D:/zipme.pl

use strict;
use warnings;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

my $file = 'c:/testing/test.pl';
print "Adding $file\n";

my $zip = Archive::Zip->new();

$zip->addFile($file, $file) or warn "Error adding file $file\n";

die "write error." if $zip->writeToFileNamed("d:/temp/file.zip") !=
AZ_OK;


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

Date: Fri, 14 Dec 2007 18:54:01 -0800 (PST)
From: Deepu <pradeep.bg@gmail.com>
Subject: Binary to Hexadecimal conversion
Message-Id: <a9f54740-4cb7-4f06-a8e6-2000d2bc85dc@b40g2000prf.googlegroups.com>

Hi All,

I have a $test with 32 bit binary number.

$test = 00000000011111000000010111100100

How can i get the hexadecimal number for this.

Thanks for the help..


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

Date: Sat, 15 Dec 2007 04:09:56 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Binary to Hexadecimal conversion
Message-Id: <5sguohF196oquU1@mid.individual.net>

Deepu wrote:
> I have a $test with 32 bit binary number.
> 
> $test = 00000000011111000000010111100100
> 
> How can i get the hexadecimal number for this.

That's a FAQ.

perldoc -q numeric

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


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

Date: Sat, 15 Dec 2007 03:09:06 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Binary to Hexadecimal conversion
Message-Id: <Xns9A06E1573B2A2asu1cornelledu@127.0.0.1>

Deepu <pradeep.bg@gmail.com> wrote in news:a9f54740-4cb7-4f06-a8e6-
2000d2bc85dc@b40g2000prf.googlegroups.com:

> Hi All,
> 
> I have a $test with 32 bit binary number.
> 
> $test = 00000000011111000000010111100100

No, you don't.


C:\DOCUME~1\asu1\LOCALS~1\Temp> cat t.pl
#!/usr/bin/perl

use strict;
use warnings;

my $test = 00000000011111000000010111100100;

C:\DOCUME~1\asu1\LOCALS~1\Temp> t
Integer overflow in octal number at C:\DOCUME~1\asu1\LOCALS~1\Temp\t.pl 
line 6.
Octal number > 037777777777 non-portable at C:\DOCUME~1\asu1\LOCALS~1
\Temp\t.pl
line 6.

You have something else.

We don't know what you have. It seems like you don't know it either.

> How can i get the hexadecimal number for this.

perldoc -f sprintf

Check out %x and %X format specifiers.

Now, maybe you have a string which contains the binary representation of 
an integer:

my $test = '00000000011111000000010111100100';

In that case, use oct (see perldoc -f oct):

C:\DOCUME~1\asu1\LOCALS~1\Temp> cat t.pl
#!/usr/bin/perl

use strict;
use warnings;

my $test = '00000000011111000000010111100100';

printf "%8.8x\n", oct( "0b$test" );


C:\DOCUME~1\asu1\LOCALS~1\Temp> t
007c05e4

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: Sat, 15 Dec 2007 03:17:26 GMT
From: spambait@milmac.com (Doug Miller)
Subject: Re: Binary to Hexadecimal conversion
Message-Id: <aHH8j.31200$JD.822@newssvr21.news.prodigy.net>

In article <a9f54740-4cb7-4f06-a8e6-2000d2bc85dc@b40g2000prf.googlegroups.com>, Deepu <pradeep.bg@gmail.com> wrote:
>Hi All,
>
>I have a $test with 32 bit binary number.

Really?
>
>$test = 00000000011111000000010111100100

After discarding the leading zeros, it looks more like a 23-digit decimal 
number to me... it just doesn't happen to contain any decimal digits greater 
than one.

-- 
Regards,
        Doug Miller (alphageek at milmac dot com)

It's time to throw all their damned tea in the harbor again.


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

Date: Sat, 15 Dec 2007 03:38:33 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Binary to Hexadecimal conversion
Message-Id: <Z_H8j.75$L91.49@trndny05>

Deepu wrote:
> I have a $test with 32 bit binary number.
>
> $test = 00000000011111000000010111100100

Actually that is not a binary number but the octal representation of approx. 
8.43253994239781e+019

> How can i get the hexadecimal number for this.

There is no such thing as a hexadecimal number. Numbers are abstract 
concepts. 13, 0xD, thirteen, 0b1101, 015, etc, etc, are just different 
representations(!) of the same number.

If you are looking for the hexadecimal representation of a specific number 
please see printf().

jue 




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

Date: Sat, 15 Dec 2007 00:50:17 -0800 (PST)
From: Florian Kaufmann <sensorflo@gmail.com>
Subject: Re: FAQ 4.3 Why isn't my octal data interpreted correctly?
Message-Id: <3b86f24d-0660-4dd9-8e39-78e8283063eb@d21g2000prf.googlegroups.com>

>     This problem shows up most often when people try using "chmod()",

"This problem shows up ...." is a bit misleading. When reading it for
the first time, it is not very clear to which problem this text
fragment refers to. Because of the title of the FAQ, and because the
first paragraph mainly talks about that one should keep in mind that
only literal numbers are automatically converted if they are given in
oct or hex format, one thinks "This problem...." refers to that kind
of problem. It then turns out that if refers to another problem -
namely that one should keep in mind that the literal number he wants
pass to chmod, mkdir etc almost certainly is in oct format because of
tradition.

Flo


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

Date: Sat, 15 Dec 2007 00:59:44 -0800 (PST)
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: How to write a "caller-inspecting" module?
Message-Id: <f6c03d33-bc16-4604-887c-d23a4071d124@a35g2000prf.googlegroups.com>

On Dec 13, 5:31 pm, kj <so...@987jk.com.invalid> wrote:
> Is it possible to write a module Foo such that if one wrote
>
>   package Bar;
>   use Foo;
>
>   # rest of Bar defined here
>
>   sub last_sub_in_Bar { do_something() }
>
>   last_top_level_statement_in_Bar();
>
>   # suitable moment!
>
>   1; # end of Bar
>
> then, at some *suitable moment* Foo would automatically inspect
> the Bar package (the "caller") and do something (e.g. add some
> methods to Bar) on the basis of this inspection.  The "suitable
> moment" I'm referring to is right after last_sub_in_Bar has been
> defined and "last_top_level_statement_in_Bar();" has been executed.
>
> After playing around endlessly with CHECKs and INITs, I still have
> not come up with a solution to this problem.  The closest to a
> solution I can come up with is to move the "use Foo" statement to
> right after last_top_level_statement_in_Bar().
>
> Is what I'm trying to do possible?
>

Carp's 'longmess' provides some stack introspection, eg,

   package Foo;
   use Carp;
   my $trace = Carp::longmess;
   ...

$trace might then contain, eg,
at Bar.pm line 2
       Bar::BEGIN() called at Foo.pm line 0
       eval {...} called at Foo.pm line 0
       require Bar.pm called at -e line 1
       main::BEGIN() called at Foo.pm line 0
       eval {...} called at Foo.pm line 0

You'd then have to pry 'Bar' from this 'mess'.
Kludgy and fragile though...so there may well
be a better way.

--
Charles DeRykus


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

Date: Sat, 15 Dec 2007 05:42:15 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sat Dec 15 2007
Message-Id: <Jt2t6F.1v0p@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.

AI-NaiveBayes1-1.4
http://search.cpan.org/~vlado/AI-NaiveBayes1-1.4/
Bayesian prediction of categories 
----
Acme-Terror-NL-0.03
http://search.cpan.org/~blom/Acme-Terror-NL-0.03/
Fetch the current NL terror alert level 
----
Alvis-NLPPlatform-0.4
http://search.cpan.org/~thhamon/Alvis-NLPPlatform-0.4/
Perl extension for linguistically annotating XML documents in Alvis 
----
Alvis-NLPPlatform-0.5
http://search.cpan.org/~thhamon/Alvis-NLPPlatform-0.5/
Perl extension for linguistically annotating XML documents in Alvis 
----
Apache2-AutoIndex-XSLT-0.04
http://search.cpan.org/~nicolaw/Apache2-AutoIndex-XSLT-0.04/
XSLT Based Directory Listings 
----
Audio-LADSPA-0.019
http://search.cpan.org/~jdiepen/Audio-LADSPA-0.019/
Modular audio processing using LADSPA plugins. Implements a LADSPA 1.1 host. 
----
Business-TNTPost-NL-0.02
http://search.cpan.org/~blom/Business-TNTPost-NL-0.02/
Calculate Dutch (TNT Post) shipping costs 
----
CPAN-FindDependencies-2.0
http://search.cpan.org/~dcantrell/CPAN-FindDependencies-2.0/
find dependencies for modules on the CPAN 
----
Cisco-CopyConfig-1.5
http://search.cpan.org/~eug/Cisco-CopyConfig-1.5/
IOS running-config manipulation 
----
Class-MOP-0.49
http://search.cpan.org/~stevan/Class-MOP-0.49/
A Meta Object Protocol for Perl 5 
----
DateTime-Format-Natural-0.62_03
http://search.cpan.org/~schubiger/DateTime-Format-Natural-0.62_03/
Create machine readable date/time with natural parsing logic 
----
EV-1.85
http://search.cpan.org/~mlehmann/EV-1.85/
perl interface to libev, a high performance full-featured event loop 
----
File-Stata-DtaReader-0.32
http://search.cpan.org/~reckon/File-Stata-DtaReader-0.32/
CPAN release history 
----
Games-Sudoku-Solver-1.1.0
http://search.cpan.org/~mehner/Games-Sudoku-Solver-1.1.0/
Solve 9x9-Sudokus recursively. 
----
Geo-IP2Location-2.10
http://search.cpan.org/~location/Geo-IP2Location-2.10/
Fast lookup of country, region, city, latitude, longitude, ZIP code, ISP and domain name from IP address by using IP2Location database. Supports IPv4 and IPv6. 
----
HTTP-Size-1.13
http://search.cpan.org/~bdfoy/HTTP-Size-1.13/
Get the byte size of an internet resource 
----
IO-Lambda-0.03
http://search.cpan.org/~karasik/IO-Lambda-0.03/
non-blocking I/O in lambda style 
----
Moose-0.33
http://search.cpan.org/~stevan/Moose-0.33/
A complete modern object system for Perl 5 
----
Music-Audioscrobbler-MPD-0.04
http://search.cpan.org/~ealleniii/Music-Audioscrobbler-MPD-0.04/
Module providing routines to submit songs to last.fm from MPD 
----
Net-Digg-0.11
http://search.cpan.org/~kwilms/Net-Digg-0.11/
Quickly consume and interface with the Digg API. 
----
Net-Scan-SMTP-Banner-0.02
http://search.cpan.org/~mcantoni/Net-Scan-SMTP-Banner-0.02/
scan for banner message from a SMTP server 
----
Net-UCP-0.31
http://search.cpan.org/~nemux/Net-UCP-0.31/
Perl extension for EMI - UCP Protocol. 
----
ONTO-PERL-1.07
http://search.cpan.org/~easr/ONTO-PERL-1.07/
----
POE-Component-Client-NSCA-0.01
http://search.cpan.org/~bingos/POE-Component-Client-NSCA-0.01/
a POE Component that implements send_nsca functionality 
----
Perl6-Slurp-Interpret-0.15
http://search.cpan.org/~ctbrown/Perl6-Slurp-Interpret-0.15/
Interpret slurped files 
----
Pod-MultiLang-0.12
http://search.cpan.org/~hio/Pod-MultiLang-0.12/
multi languages in Pod 
----
Pod-MultiLang-0.13
http://search.cpan.org/~hio/Pod-MultiLang-0.13/
multi languages in Pod 
----
Sepia-0.95_03
http://search.cpan.org/~seano/Sepia-0.95_03/
Simple Emacs-Perl Interface 
----
String-Clean-0.021
http://search.cpan.org/~notbenh/String-Clean-0.021/
use data objects to clean strings 
----
Term-ReadPassword-0.11
http://search.cpan.org/~phoenix/Term-ReadPassword-0.11/
Asking the user for a password 
----
Text-Template-Simple-0.49_08
http://search.cpan.org/~burak/Text-Template-Simple-0.49_08/
Simple text template engine 
----
Wurst
http://search.cpan.org/~wurst/Wurst/
Perl extension for playing with alignment methods 
----
Wurst-0.50
http://search.cpan.org/~wurst/Wurst-0.50/
Perl extension for playing with alignment methods 
----
XHTML-MediaWiki-0.01
http://search.cpan.org/~gam/XHTML-MediaWiki-0.01/


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: Sat, 15 Dec 2007 04:17:47 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Question about "undef'ing" variables
Message-Id: <fjvhjd$1547$3@ns.felk.cvut.cz>

A. Sinan Unur wrote:
> "Petr Vileta" <stoupa@practisoft.cz> wrote in
> news:fju8j6$g9a$4@ns.felk.cvut.cz:
>
>> Ehm, $a and $b are magic for Perl 5.8.x, not for Perl 5.6.x, and I
>> think this was be a stupid idea. Maybe could be used some like $_a
>> and $_b or $__ and $___ . But now is too late :-(
>
> You hardly ever make much sense.
>
> Now, the magic $a and $b are package variables. Even in situations
> where it is perfectly safe to declare lexically scoped variables
> named $a and $b, I would avoid using them because of the potential
> for confusion.
>
> However, that does not make names such as $_a or $___ any less silly.
>
> What is wrong with the tail end of the alphabet?
>
> my ($x, $y, $z, $w);
>
IHMO use any _basic_ variables for special purpose is stupid. The good idea is 
to use variables like $^, $-, $+, $\ $_ etc. Yes, in real script is used to 
name variables in tontext to their using, say $web_root_url, but in very short 
scripts or examples programmers tend to use variable names as short as 
possible. When I want to write some script for 3 nested loops then I probably 
will tend to write some like
for my $a(1..3) {
    for my $b(1..3) {
        for my $c(1..3) {
            do_something($a,$b,$c);
        }
    }
}

Is very stupid all time to keep in mind "Hey, do not use $a and $b !!!" :-)

-- 
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)

Please reply to <petr AT practisoft DOT cz>



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

Date: Sat, 15 Dec 2007 01:01:20 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Question about "undef'ing" variables
Message-Id: <iradneXod4V5Cv7anZ2dnUVZ_hadnZ2d@comcast.com>

Petr Vileta wrote:
> When I want to write some script for 3
> nested loops then I probably will tend to write some like
> for my $a(1..3) {
>    for my $b(1..3) {
>        for my $c(1..3) {
>            do_something($a,$b,$c);
>        }
>    }
> }

Old FORTRAN programmers don't use a, b, c for that: single-letter integer
variables are I, J, K, etc.

	-Joe


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

Date: Fri, 14 Dec 2007 22:24:53 -0800 (PST)
From: Todd <xueweizhong@gmail.com>
Subject: value or reference inside foreach <expr>?
Message-Id: <30605649-ef0e-4bf2-b8bf-ff556da4e630@n20g2000hsh.googlegroups.com>

Hi,

I've met some questions regarding the copy @array or reference inside
for <expr>:

In the code snippets blow, 2 strange cases are using @array copies
rather than modifying original ones:

case5: sub foo1 (\@) { ++$_ for @$_[0] }
case9: sub foo5 (\@) { ++$_ for @{shift} }


Why are they different than others?


--The complete sample codes---

    #! /bin/perl -l


    {
        my @a = 1..5;
        ++$_ for @a;
        print "case1: ",  @a;
    }
    {
        my @a = 1..5;
        ++$_ for @{ \@a };
        print "case2: ", @a;
    }
    {
        my @a = 1..5;
        my $r = \@a;
        ++$_ for @$r;
        print "case3: ", @a;
    }
    {
        my @a = 1..5;
        my $r = \@a;
        ++$_ for @{$r};
        print "case4: ", @a;
    }
    {
        my @a = 1..5;
        sub foo1 (\@) { ++$_ for @$_[0] }
        foo1 @a;
        print "case5: ", @a;
    }
    {
        my @a = 1..5;
        sub foo2(\@) { ++$_ for @{$_[0]} }
        foo2 @a;
        print "case6: ",  @a;
    }
    {
        my @a = 1..5;
        sub foo3 (\@) { my $r=shift; ++$_ for @$r }
        foo3 @a;
        print "case7: ", @a;
    }
    {
        my @a = 1..5;
        sub foo4 (\@) { my $r=shift; ++$_ for @{$r} }
        foo4 @a;
        print "case8: ", @a;
    }
    {
        my @a = 1..5;
        sub foo5 (\@) { ++$_ for @{shift} }
        foo5 @a;
        print "case9: ", @a;
    }

    __END__

    case1: 23456
    case2: 23456
    case3: 23456
    case4: 23456
    case5: 12345
    case6: 23456
    case7: 23456
    case8: 23456
    case9: 12345

-Todd


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

Date: Fri, 14 Dec 2007 23:01:16 -0800 (PST)
From: Todd <xueweizhong@gmail.com>
Subject: Re: value or reference inside foreach <expr>?
Message-Id: <c72912a3-3ba5-4b79-be3e-906492dab48f@s8g2000prg.googlegroups.com>

To make some clarification:

    #! /bin/perl -l
    use Data::Dumper;

    @a = 1..5;

    sub F1(@) { print Dumper shift; }
    sub F2(\@) { print Dumper shift; }

    F1 @a;
    F2 @a;

    $VAR1 = 1;

    $VAR1 = [
              1,
              2,
              3,
              4,
              5
            ];

So sub foo(\@) definitely passes a reference into the function in my
previous examples.

-Todd


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

Date: Fri, 14 Dec 2007 23:42:13 -0800 (PST)
From: Todd <xueweizhong@gmail.com>
Subject: Re: value or reference inside foreach <expr>?
Message-Id: <e3c97c1d-9139-4323-8010-3c65d02bd495@a35g2000prf.googlegroups.com>



Todd wrote:
> In the code snippets blow, 2 strange cases are using @array copies
> rather than modifying original ones:
>
> case5: sub foo1 (\@) { ++$_ for @$_[0] }
> case9: sub foo5 (\@) { ++$_ for @{shift} }

Now I see, `@$_[0]' is actually means `@{$_}[0]', but not `@{$_[0]}',
So case5 is not strange.

But I still don't understand case9:

  sub foo5 (\@) { ++$_ for @{shift} }

Why it doesn't modify the origin array?

      #! /bin/perl -l
      {
          my @a = 1..5;
          sub foo5 (@) { ++$_ for @{shift} }
          foo5 @a;
          print "case9: ", @a;
      }

      __END__
      case9: 12345


-Todd


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

Date: Sat, 15 Dec 2007 08:48:20 GMT
From: "John W. Krahn" <krahnj@telus.net>
Subject: Re: value or reference inside foreach <expr>?
Message-Id: <476394CC.B852B07F@telus.net>

Todd wrote:
> 
> Todd wrote:
> > In the code snippets blow, 2 strange cases are using @array copies
> > rather than modifying original ones:
> >
> > case5: sub foo1 (\@) { ++$_ for @$_[0] }
> > case9: sub foo5 (\@) { ++$_ for @{shift} }
> 
> Now I see, `@$_[0]' is actually means `@{$_}[0]', but not `@{$_[0]}',
> So case5 is not strange.
> 
> But I still don't understand case9:
> 
>   sub foo5 (\@) { ++$_ for @{shift} }
> 
> Why it doesn't modify the origin array?

Because @{shift} is the same as @shift so you are modifying the @shift
array.

See the "Scalar value constructors" section of perldata:

perldoc perldata


Syntactically {shift} is the same as 'shift' which is also why barewords
as hash keys don't require quotes around them.



John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 15 Dec 2007 01:23:16 -0800 (PST)
From: Todd <xueweizhong@gmail.com>
Subject: Re: value or reference inside foreach <expr>?
Message-Id: <6ce2a193-468c-4f41-92c4-9e74f4f040c6@d27g2000prf.googlegroups.com>



John W. Krahn wrote:
> Because @{shift} is the same as @shift so you are modifying the @shift
> array.
> Syntactically {shift} is the same as 'shift' which is also why barewords
> as hash keys don't require quotes around them.

In documents I see in `@{...}', the `{...}' is treated as a BLOCK, but
now it seems even `{' presents, The interpreter still checks if is the
`@{<simple-idendifier>}' case.

I listed some cases:

   @{shift} ==means==> @shift
   @{shift;} ==means==> $r=shift; @$r

Even `do' is a keyword of lanuages, the one blow still not interpreted
as a BLOCK:

   @{do{shift}}   --- Actually, i'm trying to figure out what it is?
   @{do{shift};}  --- Same as above
   @{do{shift;}}  --- Failed to compile



-Todd


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

Date: Sat, 15 Dec 2007 01:33:02 -0800 (PST)
From: Todd <xueweizhong@gmail.com>
Subject: Re: value or reference inside foreach <expr>?
Message-Id: <a95a0ad5-e8b4-434b-ad61-7300f1683a67@b40g2000prf.googlegroups.com>

So i got the intentions:

To use BLOCK inside expression:

   @{;shift}
   @{;do{shift}}

This is the hint from perldoc.

But not the ones below:

   @{shift;}     -- still good, but challange the compiler
   @{do{shift};} -- Wow, the compiler is defeated this time. Not
recognize it as a BLOCK!
   @{do{shift;}} -- Defeated also!, Even further, Not knowing how to
do with it, then give syntax error....


-Todd


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

Date: Sat, 15 Dec 2007 01:37:18 -0800 (PST)
From: Todd <xueweizhong@gmail.com>
Subject: Re: value or reference inside foreach <expr>?
Message-Id: <2b4554e3-f5f1-4b01-9149-f488d805bc0f@s8g2000prg.googlegroups.com>



John W. Krahn wrote:
> Syntactically {shift} is the same as 'shift' which is also why barewords
> as hash keys don't require quotes around them.

shift is not a bareword, it's an built-in function name. Does this
still make sense?

-Todd




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

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


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