[10469] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4061 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 24 14:04:38 1998

Date: Sat, 24 Oct 98 11:00:17 -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           Sat, 24 Oct 1998     Volume: 8 Number: 4061

Today's topics:
    Re: A CPAN mirror (Steffen Beyer)
    Re: File upload script (Snowhare)
    Re: File upload script (David Alan Black)
    Re: Help - dynamic images nana@my-dejanews.com
        Help Please! <mattfreeman@mcmail.com>
    Re: How do I print one of many? <egwong@netcom.com>
        Lexical scoping with foreach () {} continue {} <Paul.Makepeace@POBox.com>
        Not to start a language war but.. <m.v.wilson@erols.com>
    Re: Perl & Y2K - booby trap code <jpw22@cus.cam.ac.uk>
    Re: Perl & Y2K - booby trap code (Larry Rosler)
    Re: Perl unix to nt port (Honza Pazdziora)
    Re: Problems with plus sign in perl script (David Alan Black)
    Re: Problems with plus sign in perl script <bertilow@algonet.se>
    Re: Problems with plus sign in perl script (Joergen W. Lang)
    Re: Problems with plus sign in perl script <r28629@email.sps.mot.com>
    Re: Problems with plus sign in perl script (Joergen W. Lang)
    Re: programing fun: trees: Part... <xah@best.com>
    Re: programing fun: trees: Part... <rick.delaney@shaw.wave.ca>
    Re: reference to array <r28629@email.sps.mot.com>
    Re: reference to array <rick.delaney@shaw.wave.ca>
    Re: reference to array (Larry Rosler)
    Re: Single word ouptu from aa array (Tad McClellan)
    Re: Stranges errors messages <rick.delaney@shaw.wave.ca>
        why use do BLOCK? (Boson)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 24 Oct 1998 16:46:46 GMT
From: sb@engelschall.com (Steffen Beyer)
Subject: Re: A CPAN mirror
Message-Id: <70t09m$orq$1@en1.engelschall.com>

> On Fri, 23 Oct 1998 tmcguiga@my-dejanews.com wrote:

>> Anyone know how large is CPAN and what kind of traffic would a mirror be
>> expecting?

I recently copied a CPAN snapshot to a CD-R, it was about 470 MB.

I suppose the traffic is between some hundred kB and a few MB per day.

Yours,
-- 
    Steffen Beyer <sb@engelschall.com>
    Free Perl and C Software for Download: www.engelschall.com/u/sb/download/


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

Date: 24 Oct 1998 08:47:48 -0600
From: snowhare@xmission.xmission.com (Snowhare)
Subject: Re: File upload script
Message-Id: <70spak$3qp$1@xmission.xmission.com>



Nothing above this line is part of the signed message.

In article <36322A51.98AFEA40@purestar.com>,
Michael  <michael@purestar.com> wrote:
>Snowhare,
>
>Could you elaborate on those secury holes, what are the risks involved to
>other parts of a Site except the target directories where the script is set
>to upload files?

A malicious person could run any program on your system accessible as the
user your web server runs as, and upload any program they wished to run: 
Unrestricted access to the shell. Also, the target directory is easily
overridden - 'hidden' fields are worthless for security. Ditto for
'Referer' header checking. I can set the 'Referer' to anything I want to -
it is not at all secure.

If you want to get an idea of where the worst problems are coming from,
add the '-T' taint flag to the #!/usr/local/bin/perl startup line to see
where the author has done unsafe things. The script can't even display the
_initial_ screen without encountering fatal errors with taint turned on. 

Benjamin Franz


Version: 2.6.2

iQCVAwUBNjHoj+jpikN3V52xAQF1nQP9H0xkki6PDhuVLqrbG0hnSKbtOrvy3QkY
0vvOwD5uPsRFnSc7Yr+jlXokw/ibWrcNusxNsxf/OqYYdRM2c0WWMF/T963pgNVK
3fS7rHWv5YKnXRYw9gZ5Yb+bkfQ9PGAeb6/uVDkOb/foUxEiYPhKC1dkF1Ea/EAm
j8QMN9vvjGI=
=Ga7p
-----END PGP SIGNATURE-----


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

Date: 24 Oct 1998 10:52:57 -0400
From: dblack@pilot.njin.net (David Alan Black)
Subject: Re: File upload script
Message-Id: <70spk9$9c7$1@pilot.njin.net>


Hello -

>Based on the following facts: 1) Firstly sending the author a message
>prior to newsposting but not having got a reply as yet. 2) Sending a CC
>of the newsposting to the author so he may express his wishes. 3)
>Pointing the newsreaders to author's Site where the script is already
>publicly offered for others to use (including the script directly on the
>posting was for reason of clarity only as some people might find it
>difficult to navigate to the specific section of the Site). 4) If the
>author objects I would cancel the newsposting.

1. That "not having got a reply" is, ummmm, rather important.  Can I
write to you and say, "If I don't hear back from you within two days,
you owe me a million dollars?"

2. He already expressed his wishes.  Those wishes precluded your posting
his script to a newsgroup.  What you mean is: you didn't like his
wishes, so you're giving him a chance - after the fact, though - to
change his wishes so that they accord with what you have done.

3. Perhaps Bernard, like many software authors, wanted to make sure that
everyone who was interested in the script downloaded it from a single
place, so that they would get only the most recent version.  You have,
in effect, vetoed any such plan.  Moreover, anyone who can't navigate
a Web site shouldn't be programming computers anyway.

4. The author is on record as "objecting" to the redistribution of his
script.  Posting it on a newsgroup is a form of redistribution - whether
you cancel it or not.  

If "Do not redistribute this script", in your mind, means, "Do whatever
you want and then tell me about it after it's too late," then we have to
agree to disagree on the matter.  

You might ask yourself:  What would someone have to write, in order to
convince you?  Do they have to mention every newsgroup by name?  Usenet
in general?  Spell out every possible form of redistribution, and say,
"Yeah, I mean that one, too" ?

I am not the script redistribution police.  I have nothing riding on this,
except a distaste for these kinds of behaviors (and the hope that whatever
copying and acquisition restrictions I put on my computer programs, or
other forms of intellectual property, will actually be followed).

David Black
dblack@pilot.njin.net



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

Date: Sat, 24 Oct 1998 13:28:22 -0400
From: nana@my-dejanews.com
Subject: Re: Help - dynamic images
Message-Id: <nana-2410981328220001@jvs.gdn.org>


You can use GIFgraph, it does exactly that - generates graphs onfly.

> Dale Sutcliffe wrote in message ...
> >I need to create graph images on the fly.  For instance one web page may
> >contain 20 different images that were created on the fly. I have used
> gd.pm,
> >but I believe that I would have to create, save, and then display the
> image.
> >How can I display multiple images in a web page without the image existing
> >as a gif or jpeg file on the server?
> >
> >


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

Date: Sat, 24 Oct 1998 18:39:37 +0100
From: "Matt Freeman" <mattfreeman@mcmail.com>
Subject: Help Please!
Message-Id: <36321103.0@news2.mcmail.com>

Hi,

My friend had a problem with his PC, so I
told him to press del at the start-up to show
the cmos (bios) screen. I then told him to
select 'Load Setup Defaults' and 'Save.

Now when his PC starts, it does the HD detect,
memory test then show veryifing DMI pool, then
just stops...

I need Help now, please email me.
mailto:mattfreeman@mcmail.com






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

Date: Sat, 24 Oct 1998 15:28:41 GMT
From: Eric Wong <egwong@netcom.com>
Subject: Re: How do I print one of many?
Message-Id: <egwongF1C8Bt.70M@netcom.com>

Poohba <poohba@io.com> wrote:
: Hey all,
: 	
: Lets say I have this data file that looks like this:
: #Catagory|Sub1|Sub2|Titel|Address|Comments
[ ... ]

: This is the result I want on my web page:
[ cut ]

: How do I do this?
: I know how to get the tags and things like that using a foreach loop but I
: don't know how to get "Internet to show up just once" or Reservations or
: Air.  Please help

Since the data is sorted, all you need to do is to check the
last values to see if they have changed.  I'd suggest using
a hash for the sake of clarity.  Something like this oughta do:

    #!/bin/perl -w
   
	# initialize %last
    @last{'catagory', 'sub1', 'sub2', 'title', 'address', 'comments'} = 
      ( 0, 0, 0, 0, 0, 0 );

	# loop through data file
    while(<>) {
      chop;
      @data{'catagory', 'sub1', 'sub2', 'title', 'address', 'comments'} =
    	   split( '\|' );
    
	# print fields if they have changed
      if ( $last{'catagory'} ne $data{'catagory'} ) {
        print $data{'catagory'}."\n"; }
      if ( $last{'sub1'} ne $data{'sub1'} ) { 
        print "     ".$data{'sub1'}."\n"; }
      if ( $last{'sub2'} ne $data{'sub2'} ) { 
        print "          ".$data{'sub2'}."\n"; }

	# output rest of data
      printf("%s %s %s %s\n", 
        " " x 15, $data{'title'}, $data{'address'}, $data{'comments'});
    
      %last = %data;
    }

Adding HTML to the print/printf's is left as an exercise
to the reader, as it's neither particularly difficult nor
relevant to perl.

Eric
[cc'd]

: 	      *		Web Page Designs	  *
: 	    <  poohba@io.com  |  www.io.com/~poohba >

p.s. I'm not sure that your homepage ("Sorry!!! This site is
     down ... while under reconstuction") will attract a lot
     of interest to your business :)


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

Date: Sat, 24 Oct 1998 16:13:45 +0100
From: "Paul Makepeace" <Paul.Makepeace@POBox.com>
Subject: Lexical scoping with foreach () {} continue {}
Message-Id: <70t0ri$a57$1@statler.server.colt.net>

First off I wonder how many people realise a continue {}  block can be used
with a foreach statement. I say this since it's not explicitly mentioned or
examples given in the docs according to my (possibly broken?) reading,
whereas it is explicitly enumerated with the while() case. Perhaps the list
isn't exhaustive (it doesn't mention until for example). If this is true,
the wording in perlsyn..
    The following compound statements may be used to control flow:
 ..strikes me as misleading.

(Next point) I'm a great fan of generally defining variables at the lowest
scope I can get away with. I hate defining them outside loops. So I was
disappointed when I noticed:

foreach my $item (1..3) {
    my ($stuff, @more_stuff, %etc);

    # vast amounts of processing

} continue {
    # $item is in lexical scope but
    # $stuff and friends aren't
}

It makes sense of course, it's just a shame for the above idiom.

Another mild frustration is:

do_something($value) if my $value = more_processing();
# doh, but $value's out of scope by then.

Can anyone suggest gotchas for these two, i.e. if they worked how I'd like
them to what would it break/lead to nasty things? What's the
rationale/explanation for the second?

Paul
--
Paul Makepeace, Independent Thinkers Ltd (UK)
0171 377 8668 / 0973 800436
"People are all monkeys, and I am Captain Banana"
-- Vincent Gallo






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

Date: Sat, 24 Oct 1998 16:30:34 +0000
From: WMWilson <m.v.wilson@erols.com>
Subject: Not to start a language war but..
Message-Id: <363200AA.613CF211@erols.com>

Just wondering why Perl is so much more popular than python...I've just
started learning Perl and have somewhat of an interest in possibly
giving Python a try as well, just to see which works better for me.  It
doesn't seem like there's as much Python info out there though, I don't
even have any man pages (that I've found at least) for Python.  What's
the deal?  Is it harder, or just newer and hasn't quite been recognized
yet, or something else?  Also, from everything I've read Python is
object-oriented, I've read a little about object-oriented programming,
but all in all I haven't really been able to figure out what the big
deal is, can someone clue me in on this.


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

Date: Sat, 24 Oct 1998 11:53:53 +0100
From: "J.P. Wright" <jpw22@cus.cam.ac.uk>
Subject: Re: Perl & Y2K - booby trap code
Message-Id: <Pine.SOL.3.96.981024114151.16407A-100000@taurus.cus.cam.ac.uk>

On 23 Oct 1998, Mark-Jason Dominus wrote:

> In article <MPG.109a951cc238f130989838@nntp.hpl.hp.com>,
> Larry Rosler <lr@hpl.hp.com> wrote:
> >In article <70qqem$auj$1@monet.op.net> on 23 Oct 1998 16:54:46 -0400, 
> >Mark-Jason Dominus <mjd@op.net> says...
> >> It would have been really easy for people to define their month name
> >> arrays with an extra dummy element 0 on the front:
> >> 
> >> 	@month =qw(Bad Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
> >
> >Or they might have designed it now -- when my laptop PC has 96M of RAM -
> >- instead of then -- when everything had to be crammed into a few dozen 
> >*K* on a PDP-11.  
> 
> I believe that time.h stuff wasn't designed until sometime around
> 1980, unless you'd like to correct me.  The waste space is only one
> extra array element, a pointer.  That's four bytes; eight if you want
> to be fancy and actually include the string "Bad".  What was the cost
> of four bytes in 1978 or whenver time.h was invented?
> 
> I'll stick with my original assessment, which is that someone was a
> little too clever for their own good.
> 

Isn't the cost 4 bytes times the number of times you store or use a date?
Perhaps they expected to store lots and lots of dates, meaning the cost
becomes significant? Perhaps they never envisaged people using their code
in 20 years time? After all who used 20 year old code in 1978? (OK,
someone did and I don't want to hear about it)

Anyway, they were too clever for *our* own good, 'they' had no Y2K
problem!



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

Date: Sat, 24 Oct 1998 08:28:30 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl & Y2K - booby trap code
Message-Id: <MPG.109b91f83063bb279898dc@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <70rg3a$d1g$1@monet.op.net> on 23 Oct 1998 23:04:10 -0400, 
Mark-Jason Dominus <mjd@op.net> says...
 ...
> I believe that time.h stuff wasn't designed until sometime around
> 1980, unless you'd like to correct me.

I said "a couple of decades", which conveys the right imprecision 
without being accused of reesing.  I recall that stdio.h was designed 
around 1977.  Without digging through crates of old papers, I find it 
difficult and unnecessary to be more precise about the rest of the 
Standard C Library.

>     The waste space is only one
> extra array element, a pointer.  That's four bytes; eight if you want
> to be fancy and actually include the string "Bad".  What was the cost
> of four bytes in 1978 or whenver time.h was invented?

A decade earlier, I crammed a virtual-memory paging system into 4K of 12 
bits-per-word RAM on a PDP-5.  I shamelessly (in fact, proudly) 
perpetrated obscenities such as using instructions as constants if they 
had the right bit patterns.  (This was written in assembler, of course.)  
Even then I called such code pornographic (and as you may recall, 
because you printed my certificate, I am now a Certifiable Perl 
Pornographer -- samples on request).

> I'll stick with my original assessment, which is that someone was a
> little too clever for their own good.

I agree with J.P. Wright -- they (including me, then) were a little to 
clever for *our* own good (including me, now).  It worked fine for them.  
And it still works fine for us, if you RTFM.  Perl is full of little 
"gotchas" (samples on request), of which this is one of the smallest, or 
at least one that has lots of history behind it.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 24 Oct 1998 16:14:48 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Perl unix to nt port
Message-Id: <F1CAGo.79q@news.muni.cz>

On Fri, 23 Oct 1998 19:45:38 GMT, scheiner@my-dejanews.com <scheiner@my-dejanews.com> wrote:

>     open(TFILE, "$htmlpath/$postcard\pre.html");

You cannot expect anything to go smoothly if you do not check the
return values of system calls:

	open TFILE, $file or die "Error reading $file: $!\n";

Hope this helps you to locate the bug,

-- 
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: 24 Oct 1998 10:59:33 -0400
From: dblack@pilot.njin.net (David Alan Black)
Subject: Re: Problems with plus sign in perl script
Message-Id: <70sq0l$9ea$1@pilot.njin.net>

Hello -

"Bertil Wennergren" <bertilow@algonet.se> writes:

>What's wrong with this script?

>#!/usr/bin/perl

It doesn't use -w....

>$string1 =~ s|$plus_sign|$plus_word|g;

+ is a special character in regular expressions, so you'd
have to escape it in the assignment to $plus_sign (which
I just deleted, but, well, anyway).

Speaking of assigning to $plus_sign, you don't do so at all
in your second script.  But the escape principle is incorporated,
which is why it (if corrected) would work.


David Black
dblack@pilot.njin.net


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

Date: Sat, 24 Oct 1998 17:21:28 +0200
From: "Bertil Wennergren" <bertilow@algonet.se>
Subject: Re: Problems with plus sign in perl script
Message-Id: <70sr9p$5gg$1@cubacola.tninet.se>


David Alan Black wrote:

>"Bertil Wennergren" <bertilow@algonet.se> writes:

>>What's wrong with this script?

>>#!/usr/bin/perl

>It doesn't use -w....


OK. I added that, but no luck.

>>$string1 =~ s|$plus_sign|$plus_word|g;

>+ is a special character in regular expressions, so you'd
>have to escape it in the assignment to $plus_sign (which
>I just deleted, but, well, anyway).


I tried that too. No luck.

>Speaking of assigning to $plus_sign, you don't do so at all
>in your second script.  But the escape principle is incorporated,
>which is why it (if corrected) would work.


Yes, but the following does not work:

#!/usr/bin/perl -w

use diagnostics;
use strict;

my $plus_sign = "\+";
my $plus_word = "plus";

my $string1 = "word $plus_sign word";

print "$string1\n";

$string1 =~ s|$plus_sign|$plus_word|g;

print "$string1\n";
-----------------------------------------

?????

___________________________________________________________________

                         Bertilo Wennergren
                 <http://purl.oclc.org/NET/bertilo>
                     <bertilow@hem1.passagen.se>
___________________________________________________________________





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

Date: Sat, 24 Oct 1998 18:37:15 +0100
From: jwl@_munged_worldmusic.de (Joergen W. Lang)
Subject: Re: Problems with plus sign in perl script
Message-Id: <1dhf08g.15artnt5r0ivrN@host003-210.seicom.net>

Bertil Wennergren <bertilow@algonet.se> wrote:

> What's wrong with this script?
> 
> #!/usr/bin/perl
> 
> use strict;
> 
> my $plus_sign = "+";

unescaped "+" sign to be used in regex.

<snip>

> /+/: ?+*{} follows nothing in regexp at test.pl line 12.

from perldiag:

=item ?+* follows nothing in regexp

(F) You started a regular expression with a quantifier.  Backslash it
if you meant it literally.   See L<perlre>.

<snip>

> 
> $string1 =~ s|\+|$plus_word|g;

"+"- sign escaped.

<snip>

use Perl's "quotemeta" - function to get the result you want:
$plus_sign = quotemeta $plus_sign;


hth, HANW

Joergen
-- 
  To reply by email please remove _munged_ from address Thanks !
-------------------------------------------------------------------
   "Everything is possible - even sometimes the impossible"
             HOELDERLIN EXPRESS - "Touch the void"


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

Date: Sat, 24 Oct 1998 11:19:10 -0500
From: Tk Soh <r28629@email.sps.mot.com>
To: Bertil Wennergren <bertilow@hem1.passagen.se>
Subject: Re: Problems with plus sign in perl script
Message-Id: <3631FDF1.B0C4B87@email.sps.mot.com>

[posted and copy mailed]

Bertil Wennergren wrote:
> my $plus_sign = "+";
> my $plus_word = "plus";
[snip] 
> $string1 =~ s|$plus_sign|$plus_word|g;

$string1 =~ s|\Q$plus_sign|$plus_word|g;
              ^^
also see:
   perldoc -f quotemeta

-tk


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

Date: Sat, 24 Oct 1998 19:53:46 +0100
From: jwl@_munged_worldmusic.de (Joergen W. Lang)
Subject: Re: Problems with plus sign in perl script
Message-Id: <1dhf3pg.7ykhwj1wav6glN@host003-210.seicom.net>

David Alan Black <dblack@pilot.njin.net> wrote:

> Hello -
> 
> "Bertil Wennergren" <bertilow@algonet.se> writes:
> 
> >What's wrong with this script?
> 
> >#!/usr/bin/perl
> 
> It doesn't use -w....
> 
> >$string1 =~ s|$plus_sign|$plus_word|g;
> 
> + is a special character in regular expressions, so you'd
> have to escape it in the assignment to $plus_sign.

Not quite right.

$plus_sign = "\+"; interpolates, so you end up with yet another bare
plus sign in the regex. 

$plus_sign = '\+'; does not interpolate, but after the substitution you
end up with: $string = "word \and word"; 
                                 ^ 
which I find a little weird and unintuitive, but, heck, maybe it's a
feature ;-) 

To get the result you want escape it using the "quotemeta" function or
the \Q modifier in your regex: 
$string =~ s/\Q$plus_sign/$plus_word/;

<snip>

hth, HANS

Joergen
-- 
  To reply by email please remove _munged_ from address Thanks !
-------------------------------------------------------------------
   "Everything is possible - even sometimes the impossible"
             HOELDERLIN EXPRESS - "Touch the void"


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

Date: Sat, 24 Oct 1998 07:05:19 +0000
From: "Xah" <xah@best.com>
Subject: Re: programing fun: trees: Part...
Message-Id: <3631dd3a$0$6399@nntp1.ba.best.com>

Correction:

the line

> Part(['a','b','c'], 0); # returns 'b'.

should be

 Part(['a','b','c'], 0); # returns 'a'.

Thanks David Black for pointing out.

 Xah, xah@best.com
 http://www.best.com/~xah/PageTwo_dir/more.html
 Petty penguins make way: GNU HURD is coming! <www.gnu.org>


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

Date: Sat, 24 Oct 1998 17:38:07 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: programing fun: trees: Part...
Message-Id: <36321205.69A6AFB7@shaw.wave.ca>

[posted & mailed]

Xah wrote:
> 
> Here's another fun programing problem on trees.
 
You sure have a lot of these.  Are you sure they're not homework?  :-)

> Attached below is the problem description. I'll be coding a solution this weekend. Gurus, masters, and experts: please join in the fun and show us your solution! I'll post mine when I'm done.

The preceding poorly quoted paragraph is what results when my crappy
newsreader meets too-long lines from your crappy newsreader.

Homework or not, I enjoy these little exercises.  Here is my solution
with a couple of test cases.

#!/usr/local/bin/perl -w

use strict;
use Data::Dumper;

my $tree = [
    [
        ['000', '001'],
        ['010', '011'],
    ],
    [
        ['100', '101'],
        ['110', '111'],
    ],
];

print Dumper(Part($tree, 0, [1,0], [1,0]));
print Dumper(Part($tree, [1,-4], [4,1,4], [0]));

sub Part {
    my ($ref, @indices) = @_;
    my $index;
    while(defined($index = shift @indices)) {
        if (ref $index) {
            $ref = [ map { Part($ref, $_, @indices) }  @$index ];
            last;
        }
        $index = $index % @$ref;
        $ref = $ref->[$index];
    }
    return $ref;
}

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Sat, 24 Oct 1998 08:55:19 -0500
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: reference to array
Message-Id: <3631DC45.5029536C@email.sps.mot.com>

Michael J Gebis wrote:
> 
> Tk Soh <r28629@email.sps.mot.com> writes:
> }Uri Guttman wrote:
> }>   UG> you can index from the end of any array (anon or real) with
> }>   UG> negative numbers. so the last element is @array[-1]. i leave it as
> }>   UG> an very easy exercise to make that work for an anon array.
> }> me brain dead. it is friday. the phase of the moon bothering me.  it
> }> should be $array[-1]. somedays i just can't type what i mean.
> 
> }but @array[-1] still works, in this case:
> 
> }  DB<31> @a = (1,2,3,4,5)
> }  DB<32> $s = @a[-1]
> 
> It works, but for the wrong reasons.  Really.
> 
> If writing unharmonious perl doesn't deter you, perhaps the fact that
> it's not -w clean will.  "Scalar value @a[-1] better written as $a[-1]
> at - line 3."


I am actual quite surprise that $s didn't get a '1', i.e the number of element
in the array slicing returned by @a[-1]. Is my intepretation of this FAQ wrong?

=head2 What is the difference between $array[1] and @array[1]?
The former is a scalar value, the latter an array slice, which makes
it a _list_ with one (scalar) value. ....

-tk


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

Date: Sat, 24 Oct 1998 16:01:34 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: reference to array
Message-Id: <3631FB73.E6F8FFAE@shaw.wave.ca>

[posted & mailed]

Tk Soh wrote:
> 
> 
> I am actual quite surprise that $s didn't get a '1', i.e the number of 
> element in the array slicing returned by @a[-1]. Is my intepretation 
> of this FAQ wrong?

Yes.  See the section, "List value constructors" in perldata.

> =head2 What is the difference between $array[1] and @array[1]?
> The former is a scalar value, the latter an array slice, which makes
> it a _list_ with one (scalar) value. ....
       ^^^^^^
An array slice is a list, not an array.

Compare these:

@a = ('a', 'b', 'c');

$m = @a;
$n = @a[-1];
$o = @a[-1, -2];
$p = ('a', 'b', 'c');
$q = ('a', 'b', 'c')[-1];
$r = ('a', 'b', 'c')[-1, -2];

for ('m' .. 'r') {
    print "${$_}\n";
}
__END__
3
c
b
c
c
b

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Sat, 24 Oct 1998 08:49:05 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: reference to array
Message-Id: <MPG.109b96cbd4b63c639898dd@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <3631DC45.5029536C@email.sps.mot.com> on Sat, 24 Oct 1998 
08:55:19 -0500, Tk Soh <r28629@email.sps.mot.com> says...
> Michael J Gebis wrote:
 ...
> > If writing unharmonious perl doesn't deter you, perhaps the fact that
> > it's not -w clean will.  "Scalar value @a[-1] better written as $a[-1]
> > at - line 3."
> 
> I am actual quite surprise that $s didn't get a '1', i.e the number of element
> in the array slicing returned by @a[-1]. Is my intepretation of this FAQ wrong?
> 
> =head2 What is the difference between $array[1] and @array[1]?
> The former is a scalar value, the latter an array slice, which makes
> it a _list_ with one (scalar) value. ....

Assigning an _array_ to a scalar gives the scalar the size of the array.   
Assigning a _list_ to a scalar gives the scalar the last value in the 
list.  An "array slice" is a list, not an array.  Gotcha!

#!/usr/local/bin/perl -w
use strict;

my @a = ('a', 'b', 'c');
my $x = @a;
print "$x\n"; # Prints 3
my $y = ('a', 'b', 'c');
print "$y\n"; # Prints c

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 24 Oct 1998 09:14:01 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Single word ouptu from aa array
Message-Id: <9bns07.pk2.ln@flash.net>

Jakob V. Nielsen (jakob@gemino.no) wrote:

: Do it like this:

   Please don't do it like that.


: open (INFILE, "c:\\csv\\cpu_in\\test.txt");
                   ^^   ^^      ^^ gak. use single quotes for readability

   You should always, yes always, check the return value from
   open() calls.

   Really.


: @csvfiles = <INFILE>;
: close (INFILE);
: foreach $FILESTR (@csvfiles) {
:     print $FILESTR;
: }


   That just prints each line.

   The poster wants to print each _character_ of each line.


: MSmith skrev i meldingen <0%Mx1.338$ML4.1093024@news4.mia.bellsouth.net>...
: >Im new to Perl. I'M trying to place a file, a txt file, into an array..then
: >print out the first character of the first line..and then the second
: >character....etc..but IM having a bit of trouble.  IM only able to print
: out
: >a line at a time:


   # UNTESTED!

   open (INFILE, 'c:\csv\cpu_in\test.txt') || 
      die "could not open test.txt  $!";         # stop if open() failed

   while (<INFILE>) {
      foreach $char (split //) {
         print "$char\n"
      }
   }

   close (INFILE);



--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sat, 24 Oct 1998 15:13:31 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Stranges errors messages
Message-Id: <3631F028.5649216E@shaw.wave.ca>

[posted & mailed]

Felix Maurer wrote:
> 
> Hello all,
> 
> Since yesterday, I'm having stranges errors on my system when using 
> perl.
> The simple following command is an example:
> 
> # perl -e 'print "test";'
> use: Command not found.
> cnt: Undefined variable.
> #
> 

That's odd.

> I was developing a small program which contains a use and a variable 
> $cnt, but I can't explain me why all perl programms are affected by 
> this. And I also tryed to reboot my system, but it's still the same.
> 
> My program looks so at the moment and is producing the same error as
> above:

Ah, is it possible that you have a copy of this script called 'perl' on
your path?

> 
> # Program start
> 
> use lib "/usr/local/lib/perl5";
> 
> $cnt     = 0;

No shebang line?
#!/your/path/to/perl

If you try to run this script as

$ your_script_name 

it will be treated as a shell script and give you the errors above.  If
you have a copy of this script in your path called 'perl' then 

$ perl any args here

will give the same thing.

Try running

$ /your/path/to/perl -e 'print "test";'

If you still get the same errors, then I'm afraid you have copied your
script over your perl binary.

Hope you didn't (or at least have good backups).

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Sat, 24 Oct 1998 16:06:12 GMT
From: boson@earthlink.net (Boson)
Subject: why use do BLOCK?
Message-Id: <3631f8ff.344938768@news.earthlink.net>

Hello,
I have been looking for examples that shows the benefit of using the
do BLOCK format. I could only find examples like this one:

   $file = do {local $/; scalar <FILE>};
versus
   $/ = undef;
   $file = <FILE>;

But that merely looks like a question of style to me. It would be
great if someone had a real nifty example of how to use do{...} that
would convince me to use do more often.

Boson



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

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


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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