[25054] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7304 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 25 18:05:44 2004

Date: Mon, 25 Oct 2004 15:05: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           Mon, 25 Oct 2004     Volume: 10 Number: 7304

Today's topics:
        @ARGV not working (Ray)
    Re: @ARGV not working <ioneabu@yahoo.com>
    Re: @ARGV not working <1usa@llenroc.ude.invalid>
    Re: arrays of arrays question <jgibson@mail.arc.nasa.gov>
    Re: arrays of arrays question <nospam@nospam.com>
    Re: arrays of arrays question <jurgenex@hotmail.com>
    Re: arrays of arrays question <nospam@nospam.com>
        Common file operations (Seymour J.)
    Re: copying files <ioneabu@yahoo.com>
    Re: FAQ 4.56: What happens if I add or remove keys from <comdog@panix.com>
        FAQ 5.30: How do I do a "tail -f" in perl? <comdog@panix.com>
    Re: foreach vs. for <jurgenex@hotmail.com>
    Re: foreach vs. for <tim@vegeta.ath.cx>
    Re: foreach vs. for <cwilbur@mithril.chromatico.net>
    Re: foreach vs. for (Hae Jin)
    Re: foreach vs. for <jurgenex@hotmail.com>
    Re: list vs array <dha@panix.com>
    Re: list vs array <cwilbur@mithril.chromatico.net>
    Re: list vs array <nospam@nospam.com>
    Re: list vs scalar context for localtime? <uguttman@athenahealth.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 25 Oct 2004 12:52:58 -0700
From: ray.fernandez@barcap.com (Ray)
Subject: @ARGV not working
Message-Id: <30adaa65.0410251152.67a415e6@posting.google.com>

For some reason, @argv doesn't work on my machine, but when I run the
script on a coworker's machine (which has the same NT build as I do it
works).

Example:

When I type at the command line: perl test.pl foo
I don't get any output. No error messages, nothing. When I run the
script on another machine it works as expected. Here's the code
snippet I'm using:


print @INC;
print @ARGV;


The first print statement works as expected, but the @ARGV doesn't.

Any ideas?

Thanks


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

Date: Mon, 25 Oct 2004 16:28:16 -0400
From: wana <ioneabu@yahoo.com>
Subject: Re: @ARGV not working
Message-Id: <10nqol6bl5seq10@news.supernews.com>

Ray wrote:

> For some reason, @argv doesn't work on my machine, but when I run the
> script on a coworker's machine (which has the same NT build as I do it
> works).
> 
> Example:
> 
> When I type at the command line: perl test.pl foo
> I don't get any output. No error messages, nothing. When I run the
> script on another machine it works as expected. Here's the code
> snippet I'm using:
> 
> 
> print @INC;
> print @ARGV;
> 
> 
> The first print statement works as expected, but the @ARGV doesn't.
> 
> Any ideas?
> 
> Thanks

It worked for me:

perl -e 'print @ARGV' 'it ' 'works'

output: it works

wana


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

Date: 25 Oct 2004 20:36:26 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: @ARGV not working
Message-Id: <Xns958DA8F0052B0asu1cornelledu@132.236.56.8>

wana <ioneabu@yahoo.com> wrote in news:10nqol6bl5seq10@news.supernews.com:

> Ray wrote:
> 
>> For some reason, @argv doesn't work on my machine, but when I run the

You are positive that you did not misspell @ARGV in your script?

> It worked for me:
> 
> perl -e 'print @ARGV' 'it ' 'works'

If you are using cmd.exe, you might want to change that to:

C:\Home> perl -e"print qq{@ARGV}" it works
it works

Sinan


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

Date: Mon, 25 Oct 2004 12:05:15 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: arrays of arrays question
Message-Id: <251020041205151229%jgibson@mail.arc.nasa.gov>

In article <1098716627.269712@nntp.acecape.com>, daniel kaplan
<nospam@nospam.com> wrote:


> 
> my code essentially was to run a MySQL query, then put all the found records
> in ONE array.
> 
> so originally i did this:
> 
>  while (@row = $sth ->fetchrow_array)
>         push @rows, \@row;
> 

You have a scoping problem here. @row is a global array, and at each
iteration through the loop you are fetching values into @row, then
storing a reference to @row in the @rows array. Unfortunately, all of
the references you are storing are to the same array, the one global
array @row. Also, each assignment to @row with the return values from
the call to fetchrow_array overwrites the previous values in @row. The
last call to fetchrow_array returns a null array, and that is what is
in @row when the loop exits. Therefore, at the end of the loop, you
have many array references in @rows all pointing to the same, empty
array.

Replace the loop by:

   while( my @row = $sth->fetchrow_array ) {
      push @rows, \@row;
   }

Then, each iteration through the loop creates a new, temporary array
@row, and a reference to each of these distinct arrays will be added to
@rows. The reference to each of the temporary arrays in @rows ensures
that the temporary arrays will be kept around as long as @rows exists
and does not go out of scope.

> my thinking was that this give me an array of references to all found
> records, for me to access later.  somewhere this went wrong and i couldn't
> pull anything out.  i was under the impression from my reading that somehow
> perl keeps the references even after you leave a subroutine that created the
> reference.  which is so beyond me i have to keep re-reading that chapter,
> because i am so used to having to treat references (pointers in C) under
> much stricter rules.

Perl has similar scoping rules for references as C has for pointers.
References/pointers are scalars that can have a file scope (globals) or
a block scope ('my' variables) (ignore package variables for now). It
is the thing the reference/pointer points to that is different. In C,
the referent may go out of scope and the memory reused, even though the
pointer still points to it. In Perl, the referent will be kept around
until the reference variable goes out of scope or is changed so it no
longer refers to the referent and there is no other reference variable
pointing at the same referent.

> 
> so that didn't work, i don't recall the exact problem i ran into, my
> solution was this:
> 
>  while (@row = $sth ->fetchrow_array)
>         push @rows, [@row];

This works because [@row] creates a new, anonymous array that is a copy
of @row and returns a reference to it, which is then pushed onto @rows.
However, you can avoid the unnecessary copying by using the modified
loop shown above.
> 
> which i was then able to get each item i needed with
> 
> $rows[x]->[y]
> 

When you get into trouble like this, start printing out things like the
values returned by fetchrow_array in each iteration or the array
reference values. You can use the Data::Dumper module to print complex
data structures easily. If you had 'use strict' at the beginning of
your program, Perl would have complained about global variables without
an explicit package name. Posting a complete, working program would
also have let people point out the problem much sooner.


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

Date: Mon, 25 Oct 2004 15:25:34 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: arrays of arrays question
Message-Id: <1098732391.316427@nntp.acecape.com>

>>   while( my @row = $sth->fetchrow_array ) {
>>      push @rows, \@row;
>>   }

AHHA!   and THAT was my problem, the "missing my"!!!!!  thank you so very
very very much for pointing that out.  funny thing was, i realized i was
getting the same array ptr, but couldn't find a solution.  i still need to
re-read the REFERENCES section again for like the fifth time.  in cozens
book, the first thing he says is, if you know pointers from C, please try
and forget that right now.  or something to that extent!  oh, and add to
that i am from C, not C++ where you just don't declare a NEW or a MY in mid
code.  am guessing the rigid structure of C is goign to be one of my biggest
drawbacks in learning Perl properly.

but believe me that is very hard.  i think the biggest problem i have with
References in Perl is the whole, let Perl handle the behind the scenes stuff
for you.  i come from C.  i make the pointer, and every aspect of it is my
repsonsibilty till my app ends.  and it's nice that Perl does the heavy
things for you, but to me, saying making a new "@row" in a subroutine means
that when i leave the subroutine, the pointer shouldn't be valid, although
it seems that Perl is just smarter than that.  it's nice since most C errors
are usually NULL pointer errors.

as i said, i will obiously have to keep re-reading the "references" section
again and again.  frustrating since i learned poitners ages ago, but
understandble in that i went through the same thing with them back then.

anyway, not trying to drag on, just like to leave written notes of where i
went wrong, in case others read this thread.  plus it helps to drill it into
my brain.

thank you so much again, this error was really beginning to bug me....




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

Date: Mon, 25 Oct 2004 21:10:36 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: arrays of arrays question
Message-Id: <gZdfd.5080$kr4.1874@trnddc01>

daniel kaplan wrote:
>  funny thing was, i
> realized i was getting the same array ptr, but couldn't find a
> solution.

Then why, oh why, did you write
<quote>
    somewhere this went wrong and i couldn't pull anything out.
</quote>

I don't know about you, but at least to me "nothing" is very different from 
"always the same reference".
If you were trying to misslead people I guess you were pretty successful. 
Congratulations!

jue 




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

Date: Mon, 25 Oct 2004 17:37:30 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: arrays of arrays question
Message-Id: <1098740309.791942@nntp.acecape.com>

>>Then why, oh why, did you write
>>    somewhere this went wrong and i couldn't pull anything out.
>>
that was just my first problem, you know how it egos, as your code changes,
the problem dos as well

> If you were trying to misslead people I guess you were pretty successful.
> Congratulations!

 ....deleting smart alecky answer.....someone in here who i like and have
respect for, so will try to avoid answering remarks like this.....




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

Date: Mon, 25 Oct 2004 15:52:30 -0300
From: "Shmuel (Seymour J.) Metz" <spamtrap@library.lspace.org.invalid>
Subject: Common file operations
Message-Id: <417d597e$12$fuzhry+tra$mr2ice@news.patriot.net>

I'm trying to find Perl equivalents for some common operations in
other languages. I'm also looking for some style guides.

 1. If I have a partial file name, how do I get the complete path?
    I tried canon and glob, but both returned the partial name.

 2. If I have a directory name and a file specification, ho do I find
    all files in that directory matching the specification. File::Find
    and issuing an ls command seem like overkill. I could use readdir
    if I don't need a recursive search, but I was hoping for an 
    equivalent of SysFileTree in OS/2.

Any advice? Thanks.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



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

Date: Mon, 25 Oct 2004 15:27:11 -0400
From: wana <ioneabu@yahoo.com>
Subject: Re: copying files
Message-Id: <10nql2kbhrnck23@news.supernews.com>

A. Sinan Unur wrote:

> ioneabu@yahoo.com (wana) wrote in
> news:bf0b47ca.0410240743.5571a1df@posting.google.com:
> 
>> yadurajj@yahoo.com (yaduraj) wrote in message
>> news:<3668515b.0410240242.998b3ee@posting.google.com>...
>>> I have a simple question,pardon me..
>>> 
>>> if I have to copy a file, I can use something like this:
>>> 
>>> copy ("$DIR/test.c" ,"$INP_DIR/");
>>> 
>>> this copies test.c from one location to another..but
>>> if i have to copy all the files with .c extension like, what is the
> 
> ...
> 
>> maybe this would work:
>> 
>> system("mv $DIR/*.c $INP_DIR/");
> 
> Ahem, the OP said copy, note move.
> 
> Sinan.

sorry,


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

Date: Mon, 25 Oct 2004 13:52:34 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: FAQ 4.56: What happens if I add or remove keys from a hash while iterating over it?
Message-Id: <251020041352343808%comdog@panix.com>

In article <654yk8f0.fsf@online.no>, Peter J. Acklam
<pjacklam@online.no> wrote:

> brian d foy <comdog@panix.com> wrote:
> 
> > In article <hdojjpin.fsf@online.no>, Peter J. Acklam
> > <pjacklam@online.no> wrote:

> >> PerlFAQ Server <comdog@panix.com> wrote:

> >> > 4.56: What happens if I add or remove keys from a hash while
> >> > iterating over it?

> >> >     [lwall] In Perl 4, you were not allowed to modify a hash
> >> >     at all while iterating over it. In Perl 5 you can delete
> >> >     from it, but you still can't

> >> According to the docs for delete() it is safe to delete the
> >> key/value pair most recently returned from each().

> > that's what the answer says, too. :)

> It says "you can delete from it" as if *any* deletion is OK, which
> is not true.  Those who are most likely to look up in the FAQ are
> the inexperienced which might interpret the statement incorrectly.

ah, I see.  I'll look into it.

In general, you have to point at specifically what you think is
wrong so I can fix the right thing. :)

-- 
brian d foy, comdog@panix.com


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

Date: Mon, 25 Oct 2004 22:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 5.30: How do I do a "tail -f" in perl?
Message-Id: <cljt6l$qb$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

5.30: How do I do a "tail -f" in perl?

    First try

        seek(GWFILE, 0, 1);

    The statement "seek(GWFILE, 0, 1)" doesn't change the current position,
    but it does clear the end-of-file condition on the handle, so that the
    next <GWFILE> makes Perl try again to read something.

    If that doesn't work (it relies on features of your stdio
    implementation), then you need something more like this:

            for (;;) {
              for ($curpos = tell(GWFILE); <GWFILE>; $curpos = tell(GWFILE)) {
                # search for some stuff and put it into files
              }
              # sleep for a while
              seek(GWFILE, $curpos, 0);  # seek to where we had been
            }

    If this still doesn't work, look into the POSIX module. POSIX defines
    the clearerr() method, which can remove the end of file condition on a
    filehandle. The method: read until end of file, clearerr(), read some
    more. Lather, rinse, repeat.

    There's also a File::Tail module from CPAN.



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Mon, 25 Oct 2004 18:13:59 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: foreach vs. for
Message-Id: <Hnbfd.6531$8W6.940@trnddc05>

Austin P. So (Hae Jin) wrote:
>> Austin P. So (Hae Jin) wrote:
>>> Sisyphus wrote:
>>>> I mean 'for' and 'foreach' are simply synonymous, irrespective of
>>>> which of the "two distinct meanings" you're referring to.
> Perhaps I am mistaken, but the Perl Programming book (3rd ed) states
> the following (p. 101):
>
> "Perl executes a foreach statement more rapidly than it would a for
> loop because the elements are accessed directly instead of through
> subscripting."
> To me that implies memory use...but I may be mistaken...

I think this is simply sloppy terminology (in an otherwise good book). In 
particular considering that my version (2nd edition) explicitely states "The 
foreach keyword is actually a synonym for the for keyword, so you can use 
foreach for readability or for for brevity." (page 100).

What Larry et.al. probably meant by your quote is

 "Perl executes a foreach _style_ statement more rapidly than it would a for
 _style_ loop because the elements are accessed directly instead of through
 subscripting."

That would be the difference between

    for (@array) {
        do something with $_;
    }

and

    for ($i = 0; i <= $#array; $i++) {
               do something with $array[$i];
    }

And in this case it's easy to see why the C for style loop will be slower 
than the corresponding Perl foreach style loop, no matter which keyword you 
are using.

jue 




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

Date: Mon, 25 Oct 2004 18:25:44 -0000
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: foreach vs. for
Message-Id: <slrncnqh53.gb9.tim@vegeta.saiyix>

Question (found in the Subject header) was the phrase "foreach vs. for".

daniel kaplan <nospam@nospam.com> wrote:
> am trying to find out if there is an essential difference between the
> way the two run that you would chose one over the other.  the best
> answer i have found so far (book) was "foreach is longer to type".

Well, foreach is indeed 133% longer to type, indeed, that that would be
one of the few practical reasons to choose the keyword "for" over
"foreach".  OTOH, you probably want a comparison of the *functioning* of
the different *types* of loops.

First, "for" and "foreach" are synonyms (as described in perlsyn(3)).
You can do any one of the following:

    for (INIT;CONDITION;MOD) { ... }
    foreach (INIT;CONDITION;MOD) { ... }
    foreach (LIST) { ... }
    for (LIST) { ... }

However, the difference between a for-*STYLE* loop (first two examples
above) and a foreach-*STYLE* (second pair of examples).  loop is
significant.  Other than the C-style being somewhat cluttered and *gasp*
cryptic, it has it's usefulness, as describe in perlsyn(3).

The foreach-style loop has a performance advantage, hinted at in
perlsyn(3) and explained in more detail elsewhere:

: The "foreach" loop iterates over a normal list value and sets the
: vari- able VAR to be each element of the list in turn.

Given this loop:

    foreach $alias (@array) {
        ...
    }

for each iteration of the loop, $alias is actually an *ALIAS* for each
subsequent element of @array.  So, if $alias is modified in the foreach
loop on the first iteration, that change will show in $alias[0] after
the foreach loop has terminated. This provides a slight performance
improvement over a C-style implementation of a for loop iterating over
array elements.

Dangers and possible applications of this feature are described in...
yes, perlsyn(3).

*sigh*

Perhaps daniel might want to sign up for a class in learning perl, as
the docs still leave him asking questions so frequently.

HTH,
Tim Hammerquist


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

Date: Mon, 25 Oct 2004 19:49:00 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: foreach vs. for
Message-Id: <871xfmlh3n.fsf@mithril.chromatico.net>

>>>>> "TH" == Tim Hammerquist <tim@vegeta.ath.cx> writes:

    TH> Perhaps daniel might want to sign up for a class in learning
    TH> perl, as the docs still leave him asking questions so
    TH> frequently.

Oddly enough, the documentation works better when you actually read it.

Charlton


-- 
cwilbur at chromatico dot net
cwilbur at mac dot com


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

Date: Mon, 25 Oct 2004 13:49:00 -0700
From: "Austin P. So (Hae Jin)" <who@what.where>
Subject: Re: foreach vs. for
Message-Id: <cljot1$75i$1@nntp.itservices.ubc.ca>

Jürgen Exner wrote:

>>"Perl executes a foreach statement more rapidly than it would a for
>>loop because the elements are accessed directly instead of through
>>subscripting."
> 
> I think this is simply sloppy terminology (in an otherwise good book). In 
> particular considering that my version (2nd edition) explicitely states "The 
> foreach keyword is actually a synonym for the for keyword, so you can use 
> foreach for readability or for for brevity." (page 100).

Actually I was mistaken...I was looking at the 2nd edition. So you will 
see that quote near the middle of the page.





Austin


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

Date: Mon, 25 Oct 2004 21:14:41 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: foreach vs. for
Message-Id: <51efd.5085$kr4.249@trnddc01>

Austin P. So (Hae Jin) wrote:
> Jürgen Exner wrote:
>
>>> "Perl executes a foreach statement more rapidly than it would a for
>>> loop because the elements are accessed directly instead of through
>>> subscripting."
>>
>> I think this is simply sloppy terminology (in an otherwise good
>> book). In particular considering that my version (2nd edition)
>> explicitely states "The foreach keyword is actually a synonym for
>> the for keyword, so you can use foreach for readability or for for
>> brevity." (page 100).
>
> Actually I was mistaken...I was looking at the 2nd edition. So you
> will see that quote near the middle of the page.

Yes, you are right. And it is following a directly a comparison of C-style 
loops and Perl-style loops.
Unless Larry says otherwise I definitely believe that the "for" and 
"foreach" refer to C-style verus Perl-style loops, not the different 
keywords.

jue 




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

Date: Mon, 25 Oct 2004 18:29:28 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: list vs array
Message-Id: <slrncnqhg8.i27.dha@panix2.panix.com>

On 2004-10-25, daniel kaplan <nospam@nospam.com> wrote:
> Except that you're receiving abuse because you're being an ass, and
>> you're giving abuse because... well, because you persist in being an
>> ass.
>
> well lets make this final than shall we?
>
> see, same as i getting , and if you read the first nine threads, i think
> they set the tone...both sides
>
> i've invited people here to let this thread die finally and that if they
> have a problem with me personally, i listed my email...but when they
> contniue on here, i think it's just people who like to get up on their
> soapbox and "must" spout their views....

There are many who have learned form experience that certain guidelines
keep this forum from becoming unreadable.  Over the years, we've lost
some of the people here who could be the most helpful (for instance this
Larry Wall fellow of whom you may have heard) due to noise disrupting
signal.

Hence, the guidelines have been codified and posted frequently and
people actually point out when people violate them so that others
realize that that's not considered ok.  You've talked about people being
rude to you here, but in this forum, it's considered rude to not follow
the guidelines, particularly after they've been pointed out to you.

Then there's the fact that none of this should be surprising to you if
you've followed age-old usenet guidelines which suggest you lurk a while
to see how a group functions before posting.

So, although I understand how much of what goes on in situations like is
can be seen as rude, it's the result of many years of people spitting in
the face of people trying to help.

Hence the Serge of negativity in your direction.  As has been pointed
out endlessly, one would not walk into a room full of people who have
been chatting about something and insisting they talk about what you
want to talk about all of a sudden.

Just some historical/cultural data for you.  Do what you will with it.

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"If it's not Jewish, it's CRAP!:)"	- IsraelBeta on #DWC


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

Date: Mon, 25 Oct 2004 19:19:01 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: list vs array
Message-Id: <87is8ylimg.fsf@mithril.chromatico.net>

>>>>> "lazy fuckwit" == daniel kaplan <nospam@nospam.com> writes:

    lazy fuckwit> i've invited people here to let this thread die
    lazy fuckwit> finally and that if they have a problem with me
    lazy fuckwit> personally, i listed my email...but when they
    lazy fuckwit> contniue on here, i think it's just people who like
    lazy fuckwit> to get up on their soapbox and "must" spout their
    lazy fuckwit> views....

Nobody has a problem with you personally.  Nobody *cares* about you
personally.  It's your behavior that people have a problem with.  As
long as you behave like a lazy fuckwit, people are going to treat you
like a lazy fuckwit.  If you don't like that treatment, perhaps you
should see to changing your behavior?  There's even a set of Posting
Guidelines that you might consult so you can determine what behavior
is appropriate!

Charlton


-- 
cwilbur at chromatico dot net
cwilbur at mac dot com


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

Date: Mon, 25 Oct 2004 15:27:25 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: list vs array
Message-Id: <1098732502.370866@nntp.acecape.com>

in regards to Charlton's posts

just not reading them anymore charles, good day




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

Date: Mon, 25 Oct 2004 17:58:56 -0400
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: list vs scalar context for localtime?
Message-Id: <m34qki31en.fsf@linux.local>

>>>>> "IW" == Ian Wilson <scobloke2@infotop.co.uk> writes:

  IW> Which X and Y in `perldoc -X Y` will explain why we need parentheses
  IW> around localtime in

-X??

  IW>    my ($d,$m,$y) = (localtime)[3,4,5];

  IW> AFAIK Perl uses parentheses for list context and for precedence, I
  IW> think they are used here to force a list context?

  IW> In the assignment statement, since the LHS is a list, I'd have thought
  IW> it would supply a list context to the RHS anyway.

  IW> Also, it superficially appears to me that the [3,4,5] ought to be a
  IW> hint that the thing to the left ought not to be interpreted in a
  IW> scalar context.

try to parse localtime[3,4,5].

without trying, it looks like illegal syntax. a [] subscript needs a
list or an array (scalar or list mode) to index into. (localhost)
provides the list whereas localhost doesn't.

the parens are always for precedence or syntax and (almost) never to
create a list. list/scalar context is provided by nearby code and not by
the list (or what looks like a list) itself.

uri


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

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 V10 Issue 7304
***************************************


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