[9113] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2731 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 26 22:07:26 1998

Date: Tue, 26 May 98 19:00:30 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 26 May 1998     Volume: 8 Number: 2731

Today's topics:
        alternation, grouping, and backreferences <David.Boyce@fmr.com>
    Re: An unwelcome and undeserved slap (E. Gkioulekas)
    Re: An unwelcome and undeserved slap (E. Gkioulekas)
    Re: GNU attacks on the open software community <harman@omsi.com>
    Re: GPL documentation == unspeakable evil <birgitt@order.booktraders.com>
    Re: grep -v? (Martien Verbruggen)
    Re: how to make a Perl program receive email under Unix (Earl Hood)
    Re: list context: || vs or (Matt Knecht)
    Re: list context: || vs or (Matt Knecht)
    Re: list context: || vs or (Matt Knecht)
    Re: list context: || vs or <tchrist@mox.perl.com>
    Re: list context: || vs or <tchrist@mox.perl.com>
    Re: list context: || vs or (Matt Knecht)
    Re: list context: || vs or (Martien Verbruggen)
    Re: list context: || vs or <metcher@spider.herston.uq.edu.au>
    Re: Online Message from PERL to WIN95 (Martien Verbruggen)
        Q: How much data will closure handle? (Lanny Ripple)
    Re: regexp to delete trailing spaces? <danboo@negia.net>
    Re: SECURITY - simple perlscript for taking orders <p-fein@uchicago.edu>
    Re: string to ASCII question <rootbeer@teleport.com>
    Re: system call question (Martien Verbruggen)
    Re: Writing to a file (Martien Verbruggen)
        x.html is not an ELF object file? What kind of an error (Jugal Kolita)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 26 May 1998 20:34:34 -0400
From: David Boyce <David.Boyce@fmr.com>
Subject: alternation, grouping, and backreferences
Message-Id: <356B5F9A.3BE080D7@fmr.com>

I recently ran into a surprising (to me, anyway) result and just
wondered if it's documented somewhere ... I've looked in the Camel, FAQ,
FMTEYEWTK, perlre, and perlop without finding anything that discusses
this scenario. Trying to make an RE to extract a field from one of two
different line formats, I wrote something which I've trimmed down to:

	% perl -we '"Y" =~ /^(X)$|^(Y)$/ && print "$1\n"'

Which results in a warning "Use of uninitialized value at -e line 1" and
no output when the LHS is "Y", though it succeeds when the LHS is "X". 
After some time trying to figure out why the (Y) didn't match I realized
that in fact it *was* being matched but assigned to $2, not $1.
Apparently the ()-counting for purposes of backreferences takes
precedence over the | alternation, as demonstrated by the fact that this
minor mod works (if you subtract the -w):

	% perl -e '"Y" =~ /^(X)$|^(Y)$/ && print "$1$2\n"'

BTW, I'm perfectly aware that this test case could be written as
/^(X|Y)$/ and would work fine, but that's just an artifact of trimming
it down; the real code needs to extract the 2nd space-separated field
from one line-format or the last from another, so the patterns are
substantially different. I'm really trying to find out (a) where this
behavior is documented (did I miss it?) and (b) is it considered a
feature and why? Because it seems more intuitive to me that whichever
pattern matches in this case would assign to $1.

Thanks,
David


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

Date: 26 May 1998 23:16:52 GMT
From: egkioule@u.washington.edu (E. Gkioulekas)
Subject: Re: An unwelcome and undeserved slap
Message-Id: <6kfih4$1bdg$1@nntp6.u.washington.edu>

Wolfgang Denk <wd@denx.muc.de> writes:

>egkioule@u.washington.edu (E. Gkioulekas) writes:

>>But there's a difference. I think the GNU Linux issue is valid, whereas
>>calling Perl, GNU Perl wouldn't make sense.

>Ok, let's state that here we disagree.

It is a subjective issue, so it's ok to disagree.

>>Let me explain why. When we talk of a kernel, it's called Linux. No doubt
>>about that. When we talk of a system, I claim we should call it GNU/Linux. 
>>The key is understanding what we mean when we say "system". For me
>>system is all the components that combined with the kernel make your
>>computer sufficiently usable so you can do software development
>>and write _applications_ that run on that system. So if you look at
>>the base minimal system, it is predominantly indeed composed of GNU tools,
>>the kernel, and some additional tools that are linux only (like the 'free'
>>command). So it makes sense to talk of the GNU/Linux *system*

>Umm... Now what about perl? Perl is part of  the  toolkit,  providing
>some   excellent  features  of  its  own,  and  making  use  of  it's
>environment for other things where it doesn't make sense to re-invent
>the wheel.

>So when I code
>	system ("cp -r $old_dir $new_dir");
>and I happen to use a `cp' command from the GNU fileutils - is this a
>GNU Perl then? Where is the line to draw?

Of course not. See later, wrt to line.

>>That is really GNU/Linux + free applications (by many communities, Linux, Tcl,
>>Perl, X11, TeX, etc...). I am not sure if FSF really means it like this,

>Yes, they mean it like this, and so do you. Or you would have written:

>"That is really Linux + free applications (by many communities,
> Linux, GNU, Tcl, Perl, X11, TeX, etc..."

I'll give you my reason for this. What makes the GNU utilities distinct is
that together with the kernel, and a few kernel specific utilities are the
foundation on which all the other communities build their work. You can't
have X11, Tcl and Perl without a C library, the compiler and so on.
It is because of _this_ reason that I single out GNU. Once you acknowledge
this, we can agree to disagree about where the line is drawn. We can
also agree to disagree on whether this observation warrants a name change.
In fact I think that people realizing the contribution of GNU, and the   
importance of their ideas, is more important than the naming.

>Free software (and documentation, of course) is excellent, but I
>cannot understand why all this has to be labeled "GNU". It's wrong.

I agree to a very large extent. Hypothetical designations like "GNU/Perl"
(which I emphasize for Pavlovian-wired folks is HYPOTHETICAL) are absurd.

lf.


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

Date: 26 May 1998 23:26:10 GMT
From: egkioule@u.washington.edu (E. Gkioulekas)
Subject: Re: An unwelcome and undeserved slap
Message-Id: <6kfj2i$177q$1@nntp6.u.washington.edu>

David Kastrup <dak@mailhost.neuroinformatik.ruhr-uni-bochum.de> writes:

>egkioule@u.washington.edu (E. Gkioulekas) writes:

>> Let me explain why. When we talk of a kernel, it's called Linux. No
>> doubt about that. When we talk of a system, I claim we should call
>> it GNU/Linux.

>My correct name is David Kastrup, but everybody familiar with me calls
>me David.  People insisting that nobody including my friends should
>call me familiarly "David" are not necessarily improving the
>atmosphere, whether or not there is some reasoning behind it.

Granted. When I talk casually I drop the GNU too. Some cultures do place
importance on their last names, and would be offended if they were
told to deny or change a last name even if in casual conversation it is
not spoken. But point taken. 

I think I said my piece on this issue, and have very little to add at this
point. 

lf.


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

Date: 26 May 1998 16:02:31 -0700
From: Harmanjit Singh <harman@omsi.com>
Subject: Re: GNU attacks on the open software community
Message-Id: <xfgd8d08wl4.fsf@omsi14.omsi.com>

>>>>> "Horst" == Horst von Brand <vonbrand@inf.utfsm.cl> writes:


    Horst> As long as it's just plans and grandiose ideas... Hurd is
    Horst> _still_ 0.2, still totally unusable (never could get grub
    Horst> to grok the disks of a standard PC clone), and dates from
    Horst> June 12, 1997. Linux started way later than the hurd, and
    Horst> it just _works_.

	Hurd is not "totally unusable".  The whole point of making
pre-releases is that people will use it inspite of its infancy and
contribute bug-fixes and optimizations instead of complaining about
its "total unusability".

	Many (the number runs in thousands), including myself, have
successfully booted hurd on their PCs.  I agree that it is difficult
and takes a lot of patience.

	I think due to its complex design and lack of documentation,
the pace of its further development has been slowed down.

	Instead of flaming the hurd development, it is better to
contribute to it so that the free software community has more options
to choose from.  Hurd has a different design, and it is a great piece
of work.  It *does* need more work, no question about that.

Why put two things in opposition when there's no need to?
-- 
With Warm Regards,	| Open Management Software Inc. 
Harmanjit Singh.	| 5600 Mowry School Rd., #180, Newark CA 94560, USA.
			| Ph: 1-510-360-1107, Fax: 1-510-360-1112
			| Email: harman@omsi.com


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

Date: Tue, 26 May 1998 20:34:52 -0400
From: Birgitt Funk <birgitt@order.booktraders.com>
Subject: Re: GPL documentation == unspeakable evil
Message-Id: <356B5FAC.ABBC7ADC@order.booktraders.com>

Stefaan A Eeckels wrote:


> Yes. I think you shouldn't stress 'his' package, because it
> contains his code, and that of numerous other people. The
> way you've described it, the package really is a group effort,
> coordinated by the lead author. 

No, that is not what I described (at least I didn't want it,
but I have my difficulties to express myself). I made a 
hypothetical case where one author did 95 percent of the work, 
building on a smaller piece in the beginning and used later 
lots of modules too. The case I wanted to get at, is one where
it actually is *not* a group effort, but a one man work with
modules included, which any good perl programmer would use.

(Didn't I just learned that here the last couple of weeks ?
Isn't any newbie reminded to use them instead of reinventing
the wheel all the time ?)  


> Because in your scenario the second (lead) author based
> his work on GPL'ed code. He supposedly thought this to
> be a tremendous advantage compared to writing the whole
> shebang himself. 

Well, then I expressed myself badly, I wanted to get at
the opposite case, where author#1 had a very nice piece,
left it GPLed, which gave author#2 a lot of ideas to
make something out of it. No problems between the authors.
I just wondered how all the authors of modules needed to
be handled in case (here we go) *both*, author#1 and
author#2, would like to change the license to something
else than GPL. My real question was if you have to get
permission from all authors whose modules are used.


> Why would you want to change the license? I can see only
> one reason, and that is that you hope to make more money
> from selling a proprietary program. 

This is an assumption one should draw only if one has proof
of it. And what a sin that is to make a living out of your
work (just kidding). 

> If your work is based on that of other people, this is what
> is usually called 'theft'. 

I really don't want an example I made, turned upsite down.
Noone in this example has stolen anything, both authors,
all authors of modules have with due respect been
recognized and no copyrights have been violated whatsoever.
The program is just fine and nicely GPL'ed and respected.

> Getting their permission, and allowing them to
> share in the monetary rewards of the change in license
> is nothing more than honourable.
> >


Of course, noone said anything less than honourable intentions
were involved on all sides.


> Then don't base your world-shattering new program on GPL'ed
> code. The GPL is clear (to people with an open mind) and
> unambiguous, and you should understand its implications
> before you embark on developing a program incorporating
> other people's GPL'ed work.

Yes, Sir, I hear you, it just seems to me that especially very 
open minded people might change their mind in the course of their 
lifetime work. They are open minded, mind you...8-)

Thank you for clearing that up. (I assume now that all
authors of all GPL'ed modules you ever include in a GPL'ed
program must give their permission if the license of
the whole package is going to be changed).

Birgitt Funk


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

Date: 26 May 1998 23:40:31 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: grep -v?
Message-Id: <6kfjtf$ime$1@comdyn.comdyn.com.au>

In article <6kf84p$26p$1@campus1.mtu.edu>,
	swlaemmr@dilbert.tdg.mtu.edu (Shawn Laemmrich) writes:

> I need to write a simple script that searches line by line through a
> text file and finds any characters that are NOT letters or numbers.
> In bourne shell I would use a grep -v to do this, how do I do it in
> perl?

It would be good if you defined exactly what you meant by 'not letters
and numbers'

I will assume for this that you are looking for characters outside the
character class [A-Za-z0-9]. You can adapt this class by looking at the
perlre man page

# perldoc perlre

# perl -ne 'print unless /^[A-Za-z0-9]+$/' file1 file2 

This regexp looks for lines that have one or more characters in the
character class, and nothing else.

If you need to include whitespace:

# perl -ne 'print unless /^[A-Za-z0-9\s]+$/' file1 file2 

If you need to be locale independent a bit more, you could think of
using the \w character class (which also includes _ though).

# perl -ne 'print unless /^[\w\s]+$/' file1 file2

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: 27 May 1998 01:42:41 GMT
From: ehood@geneva.acs.uci.edu (Earl Hood)
Subject: Re: how to make a Perl program receive email under Unix?
Message-Id: <6kfr2h$rdk@news.service.uci.edu>

	[mail & posted]
In article <6kagu2$n3j@bgtnsc02.worldnet.att.net>,
Benjamin Geer  <benjamin.geer@worldnet.att.net> wrote:

>I would also appreciate any recommendations about Perl modules for
>processing email and MIME attachments.

Try <URL:http://www.oac.uci.edu/indiv/ehood/mhonarc.html>.
Probably will do most of what you want.

	--ewh
-- 
             Earl Hood              | University of California: Irvine
      ehood@medusa.acs.uci.edu      |      Electronic Loiterer
http://www.oac.uci.edu/indiv/ehood/ | Dabbler of SGML/WWW/Perl/MIME


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

Date: Wed, 27 May 1998 00:08:05 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: list context: || vs or
Message-Id: <FPIa1.189$_3.1145421@news2.voicenet.com>

On 26 May 1998 22:12:58 GMT, Tom Christiansen <tchrist@mox.perl.com> wrote:
>:Hrm.  What's the difference between:
>:
>:$scalar = scalar @list;
>		   ^ wrong name
>
>That's not a list.  That's an array.
>
>:$scalar = scalar some_sub_that_returns_a_list();
>
>:or even:
>:
>:@list = qw(x y z);
>
>That's not a list.  That's an array.
>
>:$scalar = @list;
>
>That's not a list.  That's an array.
>
>:print $scalar;
>:3
>
>:One is a defined operation and one is not?  Why?  I can't find
>:anything in the documentation that says there is a difference between
>:a list, and a function that returns a list.  

I still don't know the answer to this question.  Why is one defined
behaviour, and the other is not?  And why doesn't "perl -w;use
strict;usediagnostics" catch it if it is wrong?

>There isn't.  But you're calling @whatever a list, and it's not.
>It's an array.  

Looking through the documentation, I come upon this (Camel 2nd ed.
p36):
"Perl has 3 basic data types: scalars, arrays of scalars, and hashes
of scalars..."

When I typed 'list', I meant 'array of scalars'.  My apology for the
incorrect terminology.

I also find this (Camel 2nd ed. p32):
"...Perl has two main contexts, scalar context (for dealing with
singular things) and list context (for dealing with plural things)."

And searching the FAQ for the term ' list ' I get:
"How do I skip some return values? 

One way is to treat the return values as a list and index into it: "


I am using the term 'list' and 'array' interchangably.  The
documentation also seems to use them interchangably.  Your reply below
sums up the difference between a list and array nicely, though (But I
can't find it anywhere in the documentation).

>    Question:   How do you produce a reference to a list?
>    Type:       References
>    Difficulty: 6/7 (Hard)
>
>    Answer:     \@array
>    Correct:    No.
>    Why:        @array is not a list, but an array.  
>
>    Answer:     [ @array ]
>    Correct:    No.
>    Why:        That makes a reference to a newly allocated anonymous
>		array, and populates it with a copy of the contents
>		of @array.
>
>    Answer:     \($s, @a, %h, &c)
>    Correct:    No.
>    Why:        The backslash operator is distributive across a list, and
>		produces a list in return, this being (\$s, \@a, \%h, \&c).
>		Well.  In list context.  In scalar context, it's a strange
>		way to get a reference to the function &c.
>
>    Answer:	You can't take a reference to a list.  
>    Correct:    Yes.
>    Why:	A list is not an array, although is many places one may be
>		used for the other.  An array has an AV allocated,
>		whereas a list is just some values on a stack somewhere.
>		You cannot alter the length of a list, for example, any
>		more than you could alter a number by saying something
>		like 23++.  While an array contains a list, it is not
>		a list itself.

AHA!  So, a list is like a local or auto variable in C.  It has relevance as
long as we're in this stack frame, and as soon as the function
returns, it's gone?

If this is so, when do we ever see 'lists' in Perl?  When stat()
returns it's values, aren't they given storage somewhere as an array?
If not, how can they survive after stat() has gone out of context?

>Beyond that, you cannot have a "list in scalar context".  This is
>like dividing by 0.  It can't happen.  The universe will not allow it.
>
>    @a = (1,2,3);
>    $s = (1,2,3);
>
>The second is not assigning a list, you know.  It is not a "list
>in scalar context".

I don't want the list in scalar context.  I want the number of
elements in the list as a scalar.  Something like ($#x + 1).

Even if the elements of a list only exist on a stack somewhere, why
can't we count them?

>There's something about the entire contexture of the language
>that is unclear to the general public, and I'm not sure
>what to do to clear it up.  

Well, I think you may clear it up for me if you answer these
questions. :)

>--tom
>-- 
>    If you want to program in C, program in C.  It's a nice language.  I
>    use it occasionally...   :-)
>            --Larry Wall in <7577@jpl-devvax.JPL.NASA.GOV>

How apropos. :)

-- 
Matt Knecht + <hex@voicenet.com>


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

Date: Wed, 27 May 1998 00:34:13 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: list context: || vs or
Message-Id: <9cJa1.256$j4.1145685@news3.voicenet.com>

On 26 May 1998 22:18:42 GMT, Tom Christiansen <tchrist@mox.perl.com> wrote:
>:stat() returns a list.  In scalar context, that should be equal to
>:something like:
>:
>:  DB<2> @list = ();
>:  DB<3> print scalar @list;
>
>This is your unbelievably bogus misunderstanding.
>It's just off.  Apparently you break this:
>
>    @pwent = getpwnam("fred");
>    $uid   = getpwnam("fred");
>
>Or this:
>
>    @struct_tm   = localtime($time);
>    $datestring  = localtime($time);

I think that's already broken...and I had nothing to do with it :).  I
find it much easier to be able to test a sub when it's called then
having to comb over variables after they are assigned.  Your code
snippets are misleading.  They should be something like:

    @pwent = getpwnam("fred");
    if ($#ar == -1) {
	failure_code();
    } else {
	success_code();
    }

    # Scalar's work here... Yay!
    $uid = getpwnam("fred") or catch_the_error();

The scalar example there is much easier, and Perlish, IMHO, than the
first.

As for the localtime example, I've long ago fallen into the idiom:
print STDERR scalar localtime, "\tSome error occured\n";

But would be happy with:
print STDERR format_time(localtime), "\tSome error occured.\n";

All this is beside the point.  I just want an easy idiom to test
system calls.  Is that so wrong?

>I've said it a thousand times, in capital letters, in bold, and still
>many hear me not.
>
>    JUST BECAUSE YOU KNOW WHAT SOMETHING DOES IN LIST
>    CONTEXT IN NO FASHION WHATSOEVER ALLOWS YOU TO 
>    INFER *ANYTHING* ABOUT ITS BEHAVIOR IN SCALAR CONTEXT.

I just want to count the elements in the list!  I don't want to
manipulate it in any fashion.  And searching deja-news for "caps bold
scream tom" turned up _way_ to many hits for me to search. :)


-- 
Matt Knecht + <hex@voicenet.com>


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

Date: Wed, 27 May 1998 00:41:06 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: list context: || vs or
Message-Id: <CiJa1.257$j4.1145685@news3.voicenet.com>

On Tue, 26 May 1998 22:50:00 GMT, Tom Phoenix <rootbeer@teleport.com> wrote:
>You did this time. :-)
>
>    @list = stat($filename) or die "Can't stat '$filename': $!";

Hmmmm.. so I did.  I didn't realize that 'short circuiting' wasn't
really happening, it was just precedence.  It's a strange concept to
get used to.  I always thought the 'short circuiting' was magic that
happened inside a comparison, not on a whole line.

>> Hmm... maybe all system calls should be checked to see if they are
>> returning true/false on a succeed/fail?  
>
>Well, ideally, anything which can fail _should_ signal failure in some
>way. The stat call does return a proper succeed/fail value if you're
>calling it in a list context, as above or similarly (say, in an 'if'
>test).

At least we agree here.  So, in summation, the handy-dandy method of
checking things by saying:

open(FILE, $path) || die "Fooey: $!\n";

only works for a very select few system calls?

-- 
Matt Knecht + <hex@voicenet.com>


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

Date: 27 May 1998 00:53:27 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: list context: || vs or
Message-Id: <6kfo67$m7l$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, hex@voicenet.com (Matt Knecht) writes:
:So, in summation, the handy-dandy method of
:checking things by saying:
:   open(FILE, $path) || die "Fooey: $!\n";
:only works for a very select few system calls?

Not at all!  The exceptions are waitpid and wait, which perversely
return -1 on error, and syscall, which doesn't remap things. The ioctl
and fcntl calls can return "0 but true" just to accomodate you.

You just haven't gotten haven't got the hang of lists yet, is your
problem.

    jhereg(tchrist)% perl -le 'printf "%d\n", scalar stat "/etc/motd/"'
    0
    jhereg(tchrist)% perl -le 'printf "%d\n", scalar stat "/etc/motd"'
    1

Your major problem was trying not understanding = and ||.

    @x = f() || die;

Will never work because it calls f() in scalar context because
|| is a scalar operator.  You can never get @x populated
with that construct.

You have to use

    (@x = f()) || die;

or 

    die unless @x = f();

There is no workaround for not grokking precedence.

--tom
-- 
    "You can't have filenames longer than 14 chars.  
     You can't even think about them!"
        --Larry Wall in Configure from the perl distribution


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

Date: 27 May 1998 01:04:34 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: list context: || vs or
Message-Id: <6kfor2$oeg$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    hex@voicenet.com (Matt Knecht) writes:
:On 26 May 1998 22:18:42 GMT, Tom Christiansen <tchrist@mox.perl.com> wrote:
:>    $uid   = getpwnam("fred");
:>    $datestring  = localtime($time);
:
:I think that's already broken...and I had nothing to do with it :).  I
:find it much easier to be able to test a sub when it's called then
:having to comb over variables after they are assigned.  Your code
:snippets are misleading.  

No, they aren't -- not once you know Perl.  What you're saying tells me
that you haven't come to think Perlian Thoughts yet.  You still
struggle with the desire to predict based on non-dwimmer principles.
This is your error.

Here's what we wrote in the Camel:

    For functions that can be used in either scalar or list context,
    non-abortive failure is generally indicated in a scalar context by
    returning the undefined value, and in a list context by returning the
    null list.  Successful execution is generally indicated by returning
    a value that will evaluate to true (in context).
    
	Remember the following rule:  there is no general rule for
	    converting a list into a scalar!

	[NOTE: That's somewhat misleading, sadly.  You can't ever
	trick a list into being in scalar context.  It cannot happen.
	You cannot begin to even go down that path.  The compiler knows
	what you do not, that the power to infer context is greater than
	the power to specify it, with apologies to Blood of the Martyr.]

    Many operators can return a list in list context.  Each such
    operator knows whether it is being called in scalar or list
    context, and in scalar context returns WHICHEVER SORT OF VALUE IT
    WOULD BE MOST APPROPRIATE TO RETURN.  Some operators return the
    length of the list that would have been returned in list context.
    Some operators return the first value in the list.  Some operators
    return the last value in the list.  Some operators return the "other"
    value, when something can be looked up either by number or by name.
    Some operators return a count of successful operations.  In general,
    Perl operators do exactly what you want, unless you want consistency.

Perl follows a very predictable rule here: it returns in scalar content
the thing that are most likely to need to use.  It is not a slavish
prisoner of formal grammars.  Perl dwimmer dweomer is getting to you.
Go with the magic.  Discard your ugly cyberlinguistic heritage.
Embrace intuitiveness.

:I just want to count the elements in the list!  

Then count them.  You know how to write a function, I'm sure.
Why isn't your function behaving correctly in scalar context anyway?

The stupid scalar @{[ .. ]} hack is almost always wasteful hack caused by 
someone who didn't understand precedence, context, or both.

--tom
-- 
    Sorry.  My testing organization is either too small, or too large, depending
    on how you look at it.  :-)
            --Larry Wall in <1991Apr22.175438.8564@jpl-devvax.jpl.nasa.gov>


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

Date: Wed, 27 May 1998 01:37:36 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: list context: || vs or
Message-Id: <A7Ka1.194$_3.1184899@news2.voicenet.com>

On 27 May 1998 01:04:34 GMT, Tom Christiansen <tchrist@mox.perl.com> wrote:
>No, they aren't -- not once you know Perl.  What you're saying tells me
>that you haven't come to think Perlian Thoughts yet.

For this crime, I blame Perl.  Perl makes it far to easy to program in
C. :)

>	Remember the following rule:  there is no general rule for
>	    converting a list into a scalar!
>
>	[NOTE: That's somewhat misleading, sadly.  You can't ever
>	trick a list into being in scalar context.  It cannot happen.
>	You cannot begin to even go down that path.  The compiler knows
>	what you do not, that the power to infer context is greater than
>	the power to specify it, with apologies to Blood of the Martyr.]

This quote from the Camel explains everything.  It's hard to get used
to the idea that the compiler is smarter than the operator.

>Perl follows a very predictable rule here: it returns in scalar content
>the thing that are most likely to need to use.  It is not a slavish
>prisoner of formal grammars.  Perl dwimmer dweomer is getting to you.
>Go with the magic.  Discard your ugly cyberlinguistic heritage.
>Embrace intuitiveness.

Except when it's wrong... which isn't often.  I think I understand
your point.  Thanks for a clear answer!

>The stupid scalar @{[ .. ]} hack is almost always wasteful hack caused by 
>someone who didn't understand precedence, context, or both.

I almost used that example from the FAQ.  Now I'm sorry that I didn't.
:)

-- 
Matt Knecht + <hex@voicenet.com>


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

Date: 27 May 1998 01:32:02 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: list context: || vs or
Message-Id: <6kfqei$j8m$2@comdyn.comdyn.com.au>

In article <FPIa1.189$_3.1145421@news2.voicenet.com>,
	hex@voicenet.com (Matt Knecht) writes:

> If this is so, when do we ever see 'lists' in Perl?  When stat()
> returns it's values, aren't they given storage somewhere as an array?
> If not, how can they survive after stat() has gone out of context?

The documentation states clearly that stat returns an array. Not a list.

# perldoc -f stat
=item stat FILEHANDLE

=item stat EXPR

=item stat

Returns a 13-element array giving the status info for a file
[snip]


Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: Wed, 27 May 1998 11:55:00 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: list context: || vs or
Message-Id: <356B7274.2A878408@spider.herston.uq.edu.au>

Matt Knecht wrote:
> 
> Perl is the first language where I've had to worry about the
> precedence of the assignment operator.  A quick look at the list shows
> me that '=' lies between '||' and 'or' (And my mistake).
> 
> I love Perl.  It's a fantastic language, but having to worry about the
> precedence of '=' seems a bit kooky to me.  I can't think of any time
> where I would want '=' to be a higher precedence than _anything_.
> 

Perl's assignment is vastly expanded over, say, Pascal's.  Not only does
it produce a value (as opposed to just assign a value), but it can
itself be an lvalue.  That is, you can assign to an assignment.  In
Pascal, assignment is a special case, but in Perl assignment is an
operator like any other and must fight for a place in the precedence
table.  Like many things in Perl, this can be very weird but very
useful.

-- 
Jaime Metcher


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

Date: 26 May 1998 23:27:24 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Online Message from PERL to WIN95
Message-Id: <6kfj4s$iju$1@comdyn.comdyn.com.au>

In article <01bd88ab$46ef1260$01ea040a@5thyear.petech.ac.za>,
	"William Krige" <9435697@ml.petech.ac.za> writes:
> Hi
> 
> Does anyone know how to send a online message from PERL running on a
> UNIX(HP-UX) platform to a normal WIN 95 machine or NT machine without PERL
> on. Can this be done? IF so do you possibly know how or have some code as
> to how to do it

What is an 'online message'? I don't think anyone here will be able to
help you unless you define that.

Martien

PS. It's Perl if you talk about the language, perl if you talk about
the interpreter. There really isn't a PERL.
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: 27 May 98 00:20:04 GMT
From: lanny@cisco.com (Lanny Ripple)
Subject: Q: How much data will closure handle?
Message-Id: <lanny.356b5c34@lanny-ss20.cisco.com>
Keywords: perl closure my

I was trying to write a perl fgrep and ran into a problem with
closure.  I was using the routines from the FAQ for using regexps
to match many items efficiently and it blows up on trying to
match against more than a couple of hundred items.

I'm assuming there is some limit to how large an array involved
in closure can be.  I worked around it by only grabbing so many
items to be matched at a time.  To me this is a poor solution
and I was hoping someone could shed some light on how much data
can be held during closure?

  -ljr

PS - If you could drop e-mail as well as posting that would be
great.  We expire articles pretty quickly and clpm tends to
fill up faster than I can search.  :\

-- 
Lanny Ripple <lanny@cisco.com>		Voice: (408) 527-0328
ECS / Cisco Systems, Inc.		Pager: (408) 814-8224
					Fax  : (408) 526-4575
-- 
Lanny Ripple <lanny@cisco.com>		Voice: (408) 527-0328
ECS / Cisco Systems, Inc.		Pager: (408) 814-8224
					Fax  : (408) 526-4575


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

Date: Tue, 26 May 1998 18:49:11 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: regexp to delete trailing spaces?
Message-Id: <356B46E7.EAD20E96@negia.net>

matthew d. p. k. lanier wrote:
> 
> ross-
> 
> my $foo = 'all that glitters          ';
> 
> $foo =~ s/\s*$//;
> 

this gets the job done just fine. however, my first inclination would
be '$foo =~ s/\s+$//', the only difference being that the asterisk is
replaced with plus. at first this may sound overly picky, but the goal
is to replace one or more whitespace characters bound to the end of the
string not zero or more. so, for $foo = 'all that glitters', your
version matches and does a useless substitution, but with a plus it
fails. also i think you'll find a significant speed increase:

use Benchmark;
$string = $string = 'all that glitters        ';
timethese( 500_000,
  {
    'cont' => ' $foo = $string;                   ',
    'plus' => ' $foo = $string; $foo =~ s/\s+$//; ',
    'star' => ' $foo = $string; $foo =~ s/\s*$//; ',
  }
);

Benchmark: timing 500000 iterations of cont, plus, star...
      cont:  0 secs ( 0.51 usr  0.00 sys =  0.51 cpu)
      plus:  2 secs ( 2.98 usr  0.00 sys =  2.98 cpu)
      star:  9 secs ( 8.98 usr  0.00 sys =  8.98 cpu)

cheers,

-- 
Dan Boorstein   home: danboo@negia.net  work: danboo@y-dna.com

 "THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
                         - Cosmic AC


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

Date: Tue, 26 May 1998 23:43:13 GMT
From: Peter A Fein <p-fein@uchicago.edu>
Subject: Re: SECURITY - simple perlscript for taking orders
Message-Id: <87g1hwvbse.fsf@bj2-64.rh.uchicago.edu>

nem@aae.com writes:

> Hi All,
> 
> I'm still getting the hang of writing in Perl, and am just looking at
> snippets of code from available scripts. My goal is to write my own script
> that, along with an encryption certificate, will take in credit card orders,
> write them to a flat txt file, send an email reminder to a staff person, and
> then generate a custom HTML for the user to know it's been received.
> 
> I've got it up and running, but am wondering how secure it is. I started w/
> simple mailto: routines, combined with a section that writes to the file. The
> flat file is OUTSIDE of the w3 path, and the email reminder (that says to go
> look at the file to process manually) does NOT contain any sensitive
> information, such as the card type or number or exp. date.
> 
> Any pointers? I would include the script, but it's a bit long.

An important (non-perl) tip is to make sure that your script does not
have read privleges enabled for all (ie, web) users.  You'll need
execute privileges of course, but if someone can d/l your script,
it'll be a lot easier for them to find holes.

-- 
Peter Fein                                                         773-834-6206
1005 E. 60th St.                                              Chicago, IL 60637
p-fein@uchicago.edu                                   http://pfein.home.ml.org/


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

Date: Tue, 26 May 1998 22:59:23 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: string to ASCII question
Message-Id: <Pine.GSO.3.96.980526155848.8000B-100000@user2.teleport.com>

On Tue, 26 May 1998, Brian wrote:

> I need to convert an array of characters to its numeric ASCII value.

You could use unpack or ord, among other ways. Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 27 May 1998 01:26:30 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: system call question
Message-Id: <6kfq46$j8m$1@comdyn.comdyn.com.au>

In article <356A9A76.71D8@ptsc.slg.eds.com>,
	Glenn West <westxga@ptsc.slg.eds.com> writes:

> Use pipes as in:
> 
> open R_PIPE, "shell_command |" || die "Error $! on open of pipe\n";
> while (<R_PIPE>) {
> # do something with $_
> }

You might also want to read

# perldoc perlfaq9
/Why doesn't open() return an error when a pipe open fails?

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: 26 May 1998 23:06:30 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Writing to a file
Message-Id: <6kfhtm$if6$1@comdyn.comdyn.com.au>

In article <6kdutf$rnd$1@toster.te.net.ua>,
	Alexandr Dubovikov <shurik@iron.Te.NeT.UA> writes:

>   open(DATABASE, ">>records.dat"); 

Especially if your code is an example, check the return value of an
open statement.

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: 27 May 1998 01:21:21 GMT
From: kalita@linc.cis.upenn.edu (Jugal Kolita)
Subject: x.html is not an ELF object file? What kind of an error is this?
Message-Id: <6kfpqh$hqp$1@netnews.upenn.edu>



Hi!

I am trying to edit some html files I downloaded from the Web.
I am simply using some s/// statements in my program.
However, quite frequently I get an error that says:
        Error: x.html is not an ELF object file.
Can anyone tell me what kind of an error this is? How can
I get around it? Please write to me directly at 
kalita@pikespeak.uccs.edu.

Thanks!

Jugal Kalita


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 2731
**************************************

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