[6574] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 199 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 29 00:07:14 1997

Date: Fri, 28 Mar 97 21:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 28 Mar 1997     Volume: 8 Number: 199

Today's topics:
     "Odd Number of elements in Hash List" and CGI.pm (Kermit Tensmeyer)
     Re: cant get sdbm_fil to work under win95 <billc@tibinc.com>
     CORRECT Re: perl5 string splitting question <eric@nettown.com>
     CORRECT Re: Q: sorting by date <eric@nettown.com>
     Re: Date-Time Conversion: backwards (Michael Fuhr)
     fcntl() problems with NFS and Irix <mleonard@bbnplanet.com>
     Re: File Locking (Lutz Albers)
     Re: Has anyone heard the rumour that Microsoft have bou <merlyn@stonehenge.com>
     Re: How to print to a handle that is a member of an obj <eryq@enteract.com>
     Re: How to sort an arrary? <merlyn@stonehenge.com>
     Re: Microsoft Running Naked Through the Streets? (John Robert Boynton)
     Re: Need Help Troubleshooting Script (Tad McClellan)
     Re: Need Help Troubleshooting Script <eric@nettown.com>
     Re: Perl hourly fees? <neiled@enteract.com>
     Perl lib or module for MS-Word docs and/or RTF needed! <blazer@mail.nevalink.ru>
     Re: Perl mishandles some multidimensional array referen <merlyn@stonehenge.com>
     Re: Perl mishandles some multidimensional array referen (Patrick Duff)
     Re: perl5 string splitting question <eric@nettown.com>
     perl: can't handle large lists? (Apple-O)
     Re: perl: can't handle large lists? (Nathan V. Patwardhan)
     Re: Q: sorting by date <eric@nettown.com>
     Re: term 'regular expressions' considered undesirable (Rahul Dhesi)
     Re: TPJ: Nukes <merlyn@stonehenge.com>
     Re: Using an "@" in a perl format <merlyn@stonehenge.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Sat, 29 Mar 1997 00:19:23 GMT
From: tensmek@cnad.dl.nec.comxx (Kermit Tensmeyer)
Subject: "Odd Number of elements in Hash List" and CGI.pm
Message-Id: <5hhn47$h7f$1@Reliant.cnad.dl.nec.com>

Problem solved.

 Data came from old Dejanews Archive
 Posted as hints to others looking for information 

  the message 
[Fri Mar 28 17:30:34 1997] form4.cgi: Odd number of elements in hash list 
at /usr/local/lib/perl5/site_perl/CGI.pm line 611

   was fixed by indentifing the problem.  The message is caused by a odd 
number of elements in a hash. 
  %name = (-field1=>'value1',
                  -field2=>'value2',
                  -field3=>'value3')

 Hash's are always two by two.

when the clause 
  print $h->textfield(-name=>'T13', 
                      -justification=>'RIGHT'
                      -size=>25,
                      -maxlength=>48);

 is used with CGI.pm   the missing comma between 'Right' and -size will cause 
this error

  maybe this will aid others in indentifing similar problems.

 thanks to all who assisted..



-----
Kermit Tensmeyer       Hey! I have my _own_ opinion
kermit@cnad.dl.nec.com   Dallas, Texas


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

Date: Fri, 28 Mar 1997 16:19:41 -0500
From: Bill Cowan <billc@tibinc.com>
To: "john z." <zephyr@wesell.com>
Subject: Re: cant get sdbm_fil to work under win95
Message-Id: <333C35ED.B93@tibinc.com>

john z. wrote:
> 
> im trying to use sdbm_file on a perl5/ win95 platform. i used the perl
> binaries to install
> 
> first thing i noticed was that several of the library files are shortened
> to fat16. this is
> apparently having quite an effect.
> 
> ive edited the dynaload.pm and sdbm_fil (the extra characters are dropped
> by fat 16
> on win95) as best as i could to shorten dynaloader.* and autoloader.*
> 
> right now i get an error: cant call method "bootstrap" in empty paackage ..
> line 7.
> 
> has anyone gotten this to work with a fat16? if so- how.
> tks.
> john z.
> zephyr@wesell.com

Win32 Perl includes support for one of the DBM file formats (sdbm, I
think). This is covered in one of the questions at:

  Evangelo's Frequently Asked Questions (FAQ):
    http://www.endcontsw.com/people/evangelo/Perl_for_Win32_FAQ.html

-- Bill
-----------------------------------------------------------------------
Bill Cowan <billc@tibinc.com>    Voice:919-490-0034   Fax:919-490-0143
Tiburon, Inc./3333 Durham-Chapel Hill Blvd Suite E-100/Durham, NC 27707


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

Date: Fri, 28 Mar 1997 20:31:48 +0000
From: Eric Poindexter <eric@nettown.com>
To: Pat Lashley <patl@tencor.com>
Subject: CORRECT Re: perl5 string splitting question
Message-Id: <333C2AB4.44D2B153@nettown.com>

Pat Lashley wrote:
> 
> Hi,
> 
> I've got a question for the wizards: What is the BEST
> way to split a string into equal-sized chunks?  (The
> chunk size is known a-priori; but the number of chunks
> in the string is not.)
> 
> I can think of several ways to perform the split; but
> none of them stands out as clearly better than, or even
> less ugly than, the others.
> 
> 
> Thanks,
> -Pat

Did you try something like this?

!/usr/bin/perl

$string = '123456789_123456789';
$chunkSize = 4;

for (split /(.{$chunkSize}?)/, $string) {
  next unless $_;
  push @result, $_;
}

$" = "\n";
print "@result\n";

Program output...
1234
5678
9_12
3456
789

--
Eric
<mailto:eric@nettown.com>
[http://nettown.com/perl/]
have a good day!


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

Date: Fri, 28 Mar 1997 20:26:25 +0000
From: Eric Poindexter <eric@nettown.com>
To: r27975@email.sps.mot.com
Subject: CORRECT Re: Q: sorting by date
Message-Id: <333C2971.1F4CE39C@nettown.com>

Brad Bosley wrote:
> 
> I have an associative array with the date (mm/dd/yy) as the keys.
> When I do a sort(keys(%ARRAY)), it will of course sort by
> month/day/year.  What I really need is year/month/day.  I was looking
> for a slick way to do this sort, without having build a 2nd array keyed
> with (yy/mm/dd).
> 
> Any Suggestions?
> 
> Thanks,
> Brad Bosley
> Motorola SPS

Well I did it one more time. I must need some sleep. Below isn't
elegant, but it works.

!/usr/bin/perl

$string = '123456789_123456789';
$chunkSize = 4;

for (split /(.{$chunkSize}?)/, $string) {
  next unless $_;
  push @result, $_;
}

$" = "\n";
print "@result\n";


Program Output:
1234
5678
9_12
3456
789

--
Eric
<mailto:eric@nettown.com>
[http://nettown.com/perl/]
have a good day!


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

Date: 28 Mar 1997 11:04:12 -0700
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: Date-Time Conversion: backwards
Message-Id: <5hh16s$63u@nova.dimensional.com>

DeathToSpam@dev.null.com (Lee) writes:

>What I need is a script-snip that will convert a date-time entry into
>perl time format, i.e.  convert 03/28/96 into the number of seconds
>since January 1 1970 (the exact opposite of the time function).

Look at the Time:: and Date:: modules on CPAN:

    http://www.perl.com/CPAN/CPAN.html

Hope this helps.
-- 
Michael Fuhr
http://www.dimensional.com/~mfuhr/


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

Date: Fri, 28 Mar 1997 19:48:50 -0800
From: Mark Leonard <mleonard@bbnplanet.com>
Subject: fcntl() problems with NFS and Irix
Message-Id: <Pine.SOL.3.95.970328193303.1997a-100000@cogswell.barrnet.net>

Greetings,

Previously, I was using flock() for file locking until I came across
problems locking NFS mounted files.  flock() worked fine for locking NFS
files on a Solaris box but ran into problems locking files from the same
NFS filesystem on an Irix 6.2 box.

Then, based on previous mailings to this list, I started experimenting
with the fcntl() function but ran into the very same problems.  Locking
local files on both a Solaris and Irix box worked OK, and locking NFS
files on the Solaris box worked but it failed for NFS files on Irix.

The script dies with the following message:
Cannot get write lock on file: No locks available

The test code is listed below:

############################
use Fcntl;
 
$flock_write_lock_rec = pack("ssllll", F_WRLCK, 0, 0, 0, 0, 0);
$flock_unlock_rec     = pack("ssllll", F_UNLCK, 0, 0, 0, 0, 0);
 
#open (FH, ">flocktest") || die "Cannot open flocktest: $!\n";
open (FH, ">/mnt/src/flocktest") || die "Cannot open flocktest: $!\n";
 
$ret_b = fcntl(FH, &F_SETLK, $flock_write_lock_rec);
if (!$ret_b)  { $ret_b = -1; }
if ($ret_b == -1)  { die "Cannot get write lock on file: $!\n"; }
print "Returned val from fcntl $ret_b\n";
print ("File locked\n");
##############################
 
Has anyone else run into similar problems with Irix, NFS and locking?
Any insights would be greatly appreciated.

Cheers,

-Mark



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

Date: Fri, 28 Mar 1997 11:26:08 +0100
From: lutz@muc.de (Lutz Albers)
Subject: Re: File Locking
Message-Id: <lutz-ya023480002803971126080001@news>

In article <01bc3ab8$f4457f40$3d8865ce@cnpc142>, "Rich Schramm"
<rdschramm@scripps.com> wrote:

>I am concerned about blocked processes attempting to write to my file after
>I unlock it but before I close it.
>
>For example, I open the file, lock the filehandle exclusive, write to the
>file, unlock the filehandle, then close the file.
>
>Is it possible that blocked processes will either do an open on the file
>immediately after I unlock it but before it is closed?  And what will keep
>two or more blocked processes from doing opens before any of them have time
>to do a lock?

I would recommend that you use your file handles in unbufferd mode, if you
want to use file locking. That way no harm should be done if you unlock the
file and another process opens it before yout close operation.

BTW: you should also do this if you code locking in C and use the C library
file operations ...

ciao
  lutz
--
Lutz Albers, lutz@muc.de
Do not take life too seriously, you will never get out of it alive.


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

Date: 28 Mar 1997 20:12:50 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Matthew.Healy@yale.edu (Matthew D. Healy)
Subject: Re: Has anyone heard the rumour that Microsoft have bought Perl?
Message-Id: <8cybb74ci5.fsf@gadget.cscaper.com>

>>>>> "Matthew" == Matthew D Healy <Matthew.Healy@yale.edu> writes:

Matthew> Um, the entire known universe already _has_ the rights to all present
Matthew> versions of Perl, and probably also all future versions as well.

Well, hating to pick nits, but I cringe at this amount of
disinformation.  Larry is the only one with the "rights" to Perl.  He
just happens to have granted the entire galaxy (more or less) the
ability to *use* this collective work called "Perl" without having to
pay anyone.

But Perl is *not* in the public domain, as some might derive from the
above statement.  There *are* a few things you cannot do with Perl,
but durn few.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 521 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Fri, 28 Mar 1997 19:21:29 -0600
From: Eryq <eryq@enteract.com>
To: Petr Kolar <petr.kolar@vslib.cz>
Subject: Re: How to print to a handle that is a member of an object?
Message-Id: <333C6E99.54E59FA4@enteract.com>

Petr Kolar wrote:
> 
>                 Hello
> 
> How can I say
> 
> print $self->{'HANDLE'} "something"

print {$self->{'HANDLE'}} "something";

-- 
  ___  _ _ _   _  ___ _   Eryq (eryq@enteract.com)
 / _ \| '_| | | |/ _ ' /  Hughes STX, NASA/Goddard Space Flight Cntr.
|  __/| | | |_| | |_| |   http://www.enteract.com/~eryq
 \___||_|  \__, |\__, |___/\  Visit STREETWISE, Chicago's newspaper by/
           |___/    |______/ of the homeless: http://www.streetwise.org


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

Date: 28 Mar 1997 20:10:20 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Eric Poindexter <eric@nettown.com>
Subject: Re: How to sort an arrary?
Message-Id: <8c208z5r6r.fsf@gadget.cscaper.com>

[sorry... typoed first one...]
>>>>> "Eric" == Eric Poindexter <eric@nettown.com> writes:

Eric> @unsorted = (
Eric> [qw(lastname2, firstname, date, phone, location, manager)],
Eric> [qw(lastname1, firstname, date, phone, location, manager)],
Eric> );

Of course, I'm pretty sure that Eric didn't mean to put the commas
in after each element in the qw().  Hint:

	qw(fred, barney, dino)

is

	"fred,","barney,","dino"

Bleh.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 521 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Fri, 28 Mar 1997 19:43:13
From: jrb@tdl.com (John Robert Boynton)
Subject: Re: Microsoft Running Naked Through the Streets?
Message-Id: <jrb.333.0013B906@tdl.com>

In article <5hgrup$s4f$1@bob-marley.nfic.com> nvp@bill-graham.nfic.com (Nate Patwardhan) writes:
>From: nvp@bill-graham.nfic.com (Nate Patwardhan)
>Subject: Re: Microsoft Running Naked Through the Streets?
>Date: 28 Mar 1997 16:34:33 GMT

>I R A Aggie (fl_aggie@hotmail.com) wrote:
>James> In article <5hc0e7$ger$1@bob-marley.nfic.com>, nvp@bill-graham.nfic.com
>James> (Nate Patwardhan) wrote:

>+ I've heard rumours that Microsoft is running naked through the
>+ streets.  Well I suppose it's their perogative, as they own the
>+ streets they're running naked through.

>James> Hey, as long as no one forces me to watch Bill G. run nekkid thru
>James> the streets...

>It's rumoured that running through the streets will become 
the>industry standard.  :-)

>Nate Patwardhan
>nvp@nfic.com
>nvp@shore.net

Anyone who didn't see His clothes is obviously incompetent (to write a decent 
operating system?).

John Robert Boynton



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

Date: Fri, 28 Mar 1997 16:13:40 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Need Help Troubleshooting Script
Message-Id: <kqfhh5.p5d.ln@localhost>

Keven D. Ficken (ficken@mobot.org) wrote:
: I need help with the following script. I can not figure out what is
: wrong with it. It seems to work fine from the command line, but  when
: I try to submit the form to which it is tied using a web browser, I
: get a "Document contains no Data" error. Can someone please help me? 


from the perl FAQ part 9:

-------------------------------------------------------
=head2 My CGI script runs from the command line but not the browser.  Can you help me fix it?

Sure, but you probably can't afford our contracting rates :-)

Seriously, if you can demonstrate that you've read the following FAQs
and that your problem isn't something simple that can be easily
answered, you'll probably receive a courteous and useful reply to your
question if you post it on comp.infosystems.www.authoring.cgi (if it's
something to do with HTTP, HTML, or the CGI protocols).  Questions that
appear to be Perl questions but are really CGI ones that are posted to
comp.lang.perl.misc may not be so well received.

The useful FAQs are:

    http://www.perl.com/perl/faq/idiots-guide.html
    http://www3.pair.com/webthing/docs/cgi/faqs/cgifaq.shtml
    http://www.perl.com/perl/faq/perl-cgi-faq.html
    http://www-genome.wi.mit.edu/WWW/faqs/www-security-faq.html
    http://www.boutell.com/faq/

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

-- 
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net



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

Date: Fri, 28 Mar 1997 19:51:01 +0000
From: Eric Poindexter <eric@nettown.com>
To: "Keven D. Ficken" <ficken@mobot.org>
Subject: Re: Need Help Troubleshooting Script
Message-Id: <333C2125.1A50A03C@nettown.com>

Keven D. Ficken wrote:
> 
> I need help with the following script. I can not figure out what is
> wrong with it. It seems to work fine from the command line, but  when
> I try to submit the form to which it is tied using a web browser, I
> get a "Document contains no Data" error. Can someone please help me?
> 
 
> print "Content-type: text/html\n\n";
> 
> print <<TOP;
> <html>
> <head>

just fyi you can put the header in the here string, i.e.

print <<TOP;
Content-type: text/html

<html>
<head>

Try running from telnet, e.g.

%telnet nettown.com 80
GET http://nettown.com/perl/

That way you can see what the server's sending.


--
Eric
<mailto:eric@nettown.com>
[http://nettown.com/perl/]
have a good day!


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

Date: 29 Mar 1997 01:50:13 GMT
From: "Neil Edmondson" <neiled@enteract.com>
Subject: Re: Perl hourly fees?
Message-Id: <01bc3be3$cce66f00$1894e5cf@nedmondson.iclretail.com>

I'll do it for $1 less than the others per hour..

Patrick Poon <poon@sgi.com> wrote in article <333C010D.41C6@sgi.com>...
> Hi folks,
> 
> I was just wondering...what's the going rate for a Perl programmer



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

Date: Sat, 29 Mar 1997 04:49:33 +0300
From: Mike <blazer@mail.nevalink.ru>
Subject: Perl lib or module for MS-Word docs and/or RTF needed!
Message-Id: <333C752D.25E9@mail.nevalink.ru>

If you know some perl program that can create/convert Word 6.0-7.0 and
Reach Text Format, or even the description of data format, please, send
me. I'd like both UNIX and Win32 versions.
Thanks.
-- 

***************************
Mike Blazer
blazer@mail.nevalink.ru
***************************


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

Date: 28 Mar 1997 20:34:41 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: pduff@airmail.net (Patrick Duff)
Subject: Re: Perl mishandles some multidimensional array references???
Message-Id: <8cohc34bhq.fsf@gadget.cscaper.com>

>>>>> "Patrick" == Patrick Duff <pduff@airmail.net> writes:

Patrick> I am really having trouble with multidimensional arrays and
Patrick> hashes.

Perl doesn't have multidimensional arrays or hashes.  You can have a
list of references to lists.  But not a list of lists.

Patrick>   I understand them, I use them a lot!  

Hmm.  The first doesn't follow from the second. :-)

Patrick>   It's just that
Patrick> in a few cases I've found that Perl (Win NT Build 302,
Patrick> version 5.003) acts brain damaged.  Today I finally got
Patrick> annoyed enough to put together a few simple examples showing
Patrick> Perl failing to correctly execute good Perl code.

It's not good Perl code.  You should be paying *serious* attention to
your error messages.  They are trying to help you.

Patrick> Consider the following programs.  The first one behaves correctly.
Patrick> Each of the following variants should behave identically to the first
Patrick> one, but instead they fail with various error messages, as indicated.

They fail because you broke them.  The error messages are really
trying to help.

Patrick> Only the last example is bad Perl code, which I threw in just to show
Patrick> what happens when I follow the advice in the previous variant's error
Patrick> message.

Yes.  You sent it into a long loop.  I'll show you why below.

Patrick> What I really want to use is something like the following fragment:

Patrick>         @Title[0] = ('A1','A2','A3','A4');
Patrick>         @Title[1] = ('B1','B2','B3','B4');
Patrick>         for $X (0 .. $#Title[0]) { ### };

No.  You don't.  You want $Title[0] to be a listref of those elements.
That would look like this:

	$Title[0] = [qw(A1 A2 A3 A4)];

Patrick> So, unless someone can point out something I'm doing wrong -- please
Patrick> Perl Gods, put this annoying quirk on your list of bugs to fix!

Not a bug.

And now for the comments on some of your code....

Patrick> -- 
Patrick> regards, Patrick Duff (pduff@airmail.net)

Patrick> ########################################

Patrick> $Title[0][0] = 'A1';
Patrick> $Title[0][1] = 'A2';
Patrick> $Title[0][2] = 'A3';
Patrick> $Title[0][3] = 'A4';
Patrick> $Title[1][0] = 'B1';
Patrick> $Title[1][1] = 'B2';
Patrick> $Title[1][2] = 'B3';
Patrick> $Title[1][3] = 'B4';

Patrick> for $X (0 .. 3) {
Patrick>    for $Y (0 .. 1) {
Patrick>       print("  $Title[$Y][$X]");
Patrick> }  };
Patrick> print("\n");

Patrick> #Output is:
Patrick> #  A1  B1  A2  B2  A3  B3  A4  B4

Yeah.  Bingo.  $Title[0] is a listref.  That's why this works.

Patrick> ########################################

Patrick> @Title[0] = ('A1','A2','A3','A4');  #This line changed
Patrick> @Title[1] = ('B1','B2','B3','B4');  #This line changed

Patrick> for $X (0 .. 3) {
Patrick>    for $Y (0 .. 1) {
Patrick>       print("  $Title[$Y][$X]");
Patrick> }  };
Patrick> print("\n");

Patrick> #Error messages:
Patrick> #Scalar value @Title[0] better written as $Title[0] at line 1.
Patrick> #Scalar value @Title[1] better written as $Title[1] at line 2.
Patrick> #No output.

Yeah.  These error messages are trying to save your bacon.  Sad
that you didn't notice that.

Here's a little rule I teach my beginning students:

	@FOO[$BAR] is generally WRONG!

and even perl -w tells you about that now.  Now, if you flip back up
to the top, you'll see how to initialize that correctly.

Patrick> ########################################

Patrick> $Title[0][0] = 'A1';
Patrick> $Title[0][1] = 'A2';
Patrick> $Title[0][2] = 'A3';
Patrick> $Title[0][3] = 'A4';
Patrick> $Title[1][0] = 'B1';
Patrick> $Title[1][1] = 'B2';
Patrick> $Title[1][2] = 'B3';
Patrick> $Title[1][3] = 'B4';

Patrick> for $X (0 .. $#Title[0]) {  #This line changed
Patrick>    for $Y (0 .. 1) {
Patrick>       print("  $Title[$Y][$X]");
Patrick> }  };
Patrick> print("\n");

Patrick> #Error message:
Patrick> #Can't use subscript on array length at line 10.
Patrick> #No output.

Yeah.  Broken code again.  $#Title[0] is invalid syntax.
[next example deleted as the same]

Patrick> ########################################

Patrick> $Title[0][0] = 'A1';
Patrick> $Title[0][1] = 'A2';
Patrick> $Title[0][2] = 'A3';
Patrick> $Title[0][3] = 'A4';
Patrick> $Title[1][0] = 'B1';
Patrick> $Title[1][1] = 'B2';
Patrick> $Title[1][2] = 'B3';
Patrick> $Title[1][3] = 'B4';

Patrick> for $X (0 .. @Title[0]) {  #This line changed -- array evaled in a
Patrick> scalar context
Patrick>    for $Y (0 .. 1) {
Patrick>       print("  $Title[$Y][$X]");
Patrick> }  };
Patrick> print("\n");

Patrick> #Error message:
Patrick> #Scalar value @Title[0] better written as $Title[0] at line 1O.
Patrick> #No output.

Again, Perl is trying to save your bacon.  The value of @Title[0] in a
scalar context is the last element of the slice, in this case the same
as $Title[0], which will be some listref.  I suspect you got a 0..0
thing going on there then.

Patrick> ########################################

Patrick> $Title[0][0] = 'A1';
Patrick> $Title[0][1] = 'A2';
Patrick> $Title[0][2] = 'A3';
Patrick> $Title[0][3] = 'A4';
Patrick> $Title[1][0] = 'B1';
Patrick> $Title[1][1] = 'B2';
Patrick> $Title[1][2] = 'B3';
Patrick> $Title[1][3] = 'B4';

Patrick> for $X (0 .. $Title[0]) {  #This line changed
Patrick>    for $Y (0 .. 1) {
Patrick>       print("  $Title[$Y][$X]");
Patrick> }  };
Patrick> print("\n");

Patrick> #No error message, but script goes into an infinite loop.
Patrick> #No output.

Not infinite.  $Title[0] is a listref.  In a numeric context, you get
the address.  It was probably some huge number.  Bleh.  That'll take a
*long* time.

I'd suggest you stare at the FAQ, and perldsc, and perllol, and
chapter 4 of the blue camel for a *very* long time.

Conclusion: no bug in perl.  just in absence of docs in your face. :-)

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 521 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Sat, 29 Mar 1997 03:49:48 GMT
From: pduff@airmail.net (Patrick Duff)
Subject: Re: Perl mishandles some multidimensional array references???
Message-Id: <333e8107.157432085@news.airmail.net>


Several people sent me helpful messages.  The critical piece of advice
turned out to be using square brackets instead of parentheses in the
first two lines.  Here's the corrected code:

$Title[0] = ['A1', 'A2', 'A3', 'A4'];
$Title[1] = ['B1', 'B2', 'B3', 'B4'];
for $X (0 .. $#{$Title[0]}) {
   for $Y (0 .. 1) {
      print("  $Title[$Y][$X]");
}  };
println("\n");

Output:  A1  B1  A2  B2  A3  B3  A4  B4

Actually, I should have thought to try this on my own, as just a few
months ago I helped someone else who had done something like

    %Hash = { Key1 => 'Value1', Key2 => 'Value2' };

when they should have done

    %Hash = ( Key1 => 'Value1', Key2 => 'Value2' );

So to get everything straight in my head, I decided to run through all
the possibilities to see what they do.  Here they are:

$Array = ( 'Value1', 'Value2');  # line 1
$Array = [ 'Value1', 'Value2'];  # line 2
@Array = ( 'Value1', 'Value2');  #line 3
@Array = [ 'Value1', 'Value2'];  #line 4
$Hash = ( Key1 => 'Value1', Key2 => 'Value2');  #line 5
$Hash = { Key1 => 'Value1', Key2 => 'Value2'};  #line 6
%Hash = ( Key1 => 'Value1', Key2 => 'Value2');  #line 7
%Hash = { Key1 => 'Value1', Key2 => 'Value2'};  #line 8

line 1:  error:  "Useless use of constant in a void context"
line 2:  reference to a two-element array
line 3:  a two-element array
line 4:  a one-element array whose first element contains a
two-element array
line 5:  3 errors:  "Useless use of constant in a void context"
line 6:  reference to a two-key hash
line 7:  a two-key hash
line 8:  error:  "Odd number of elements in hash list"

So if what you want is a two-value array or a two-key hash, use lines
3 and 7.  In both cases, you put what you want to get ("@" or "%") in
front of the variable name, then use parentheses for the specification
list.

But I used that heuristic in the original version of the sample code
(see my earlier message) and it failed.  What actually works correctly
(at the beginning of this message) seems counter-intuitive to me in
light of the above 8-line analysis.  So the moral seems to be when
working with multidimensional arrays, you have to just play around
with all the possibilities until one works!

Does anyone care to expand on the above analysis to come up with a
heuristic for determining the correct syntax ( $ or @ or %, and ( ) or
[ ] or { } ) to use in all circumstances when specifying arrays and
hashes with varying numbers of dimensions?

-- 
regards, Patrick Duff (pduff@airmail.net)

p.s.:  Here is some code I wrote a few months ago to print-out
multidimensional structures.  Enjoy, and thanks for the help!

###########################################################################

sub printsp {
   print("@_ ");
};

sub println {
   if ($html) {
      print("@_<BR>\n");
   } else {
      print("@_\n");
}  };

sub printvar {
   #Arg0 is a variable name in single quotes
   print("$_[0] = ");
   print('<B>') if $html;
   printref($_[0],'terse');
   print('</B>') if $html;
   println();
};

sub indent {
   #Note:  $indent_level = 1 is no indentation.
   $indent_level = $_[0] if $_[0];
   print('   ' x ($indent_level-1));
};

sub printref {
   #Arg0 is a variable name (e.g. '$ABC', '@ABC', '%ABC', etc.)
   #or a reference to a structure (e.g., \$ABC, \@ABC, \%ABC, etc.).
   #Prints the entire structure referenced by Arg0, using indent() to
   #show each level.  If Arg1 is true, uses a more compact listing
format.

   my($terse) = $_[1];
   if ($terse) {
      local($print) = \&printsp;
   } else {
      local($print) = \&println;
   };
   local($indent_level) = $indent_level + 1;

   my($structure,$ref);
   if ((ref $_[0]) eq '') {   #We were passed a variable name
      $structure = eval("\\$_[0]");
      $ref = ref $structure;
      println("$_[0]: $ref") unless (($indent_level > 1) || ($terse));
   } else {                   #We were passed a reference to a
structure
      $structure = $_[0];
      $ref = ref $structure;
      println("$ref") unless (($indent_level > 1) || ($terse));
   };

   if ($ref eq 'OLE') {
      $ref = $structure;  #Get type of reference from value of
variable if OLE
   };
   if ($ref =~ /REF/) {
      indent() unless ($terse);
      &$print($ref);
      printref(${$structure},$terse);
   }
   elsif ($ref =~ /SCALAR/) {
      indent() unless ($terse);
      &$print(${$structure});
   }
   elsif ($ref =~ /ARRAY/) {
      my($i)=0;
      foreach $element (@{$structure}) {
         indent() unless ($terse);
         print("[$i] ") unless ($terse);
         $i++;
         $ref = ref $element;
         if ($ref) {
            &$print($ref);
            printref($element,$terse);
         }
         else {
            &$print($element);
   }  }  }
   elsif ($ref =~ /HASH/) {
      my($element,$value);
      #OLE doesn't support FIRSTKEY and NEXTKEY, so "keys
%{$structure}" fails!
      foreach $element (sort keys %{$structure}) {
         $value = ${$structure}{$element};
         indent() unless ($terse);
         print("$element \=> ") unless ($terse);
         $ref = ref $value;
         if ($ref) {
            &$print($ref);
            printref($value,$terse);
         }
         else {
            &$print($value);
   }  }  }
   elsif ($ref =~ /GLOB/) {
      indent() unless ($terse);
      &$print(*{$structure});
   }
   else {  #Object has no known print method, e.g. $ref =~ /CODE/
      indent() unless ($terse);
      &$print($ref);
}  };



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

Date: Fri, 28 Mar 1997 19:54:43 +0000
From: Eric Poindexter <eric@nettown.com>
To: Pat Lashley <patl@tencor.com>
Subject: Re: perl5 string splitting question
Message-Id: <333C2203.4BB478B@nettown.com>

Pat Lashley wrote:
> 
> Hi,
> 
> I've got a question for the wizards: What is the BEST
> way to split a string into equal-sized chunks?  (The
> chunk size is known a-priori; but the number of chunks
> in the string is not.)
> 
> I can think of several ways to perform the split; but
> none of them stands out as clearly better than, or even
> less ugly than, the others.
> 
> Thanks,
> -Pat

@result = split /.{$chunkSize}?/, $string;

Is one way.

--
Eric
<mailto:eric@nettown.com>
[http://nettown.com/perl/]
have a good day!


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

Date: Sat, 29 Mar 1997 00:39:07 GMT
From: no_junk_mail@my_address.com (Apple-O)
Subject: perl: can't handle large lists?
Message-Id: <5hho5t$gfe$1@news.nac.net>

I wrote a script that's supposed to read and sort a large database document 
(1250 lines, 7 fields) by different keys. It worked with a small test list (5 
lines!) but is behaving quite strangely with the real data. It will output the 
data for one record repeatedly 5-20 times, then seemingly skip 10-20 records, 
and do the same thing for the next line. 

Is perl unable to handle this much data? Can I make provisions so that it is 
"ready" to? 

---

Apple-O
appleo@cybercomm.net

Apple-O
appleo@cybercomm.net


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

Date: 29 Mar 1997 03:36:24 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: perl: can't handle large lists?
Message-Id: <5hi2no$f30@fridge-nf0.shore.net>

Apple-O (no_junk_mail@my_address.com) wrote:

: Is perl unable to handle this much data? Can I make provisions so that it is 
: "ready" to? 

Yes.  Perl can do what you propose - I've been able to parse datafiles
as large as 1 meg without a problem (I haven't tried anything larger
because I haven't needed to - yet.  :-)

Let's see some code.  From experience, large, field-delimited textfiles
might often have formatting glitches that break your parsing routine(s),
and cause, umm, undesirable results.

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: Fri, 28 Mar 1997 20:08:55 +0000
From: Eric Poindexter <eric@nettown.com>
To: r27975@email.sps.mot.com
Subject: Re: Q: sorting by date
Message-Id: <333C2557.6121E057@nettown.com>

Brad Bosley wrote:
> 
> I have an associative array with the date (mm/dd/yy) as the keys.
> When I do a sort(keys(%ARRAY)), it will of course sort by
> month/day/year.  What I really need is year/month/day.  I was looking
> for a slick way to do this sort, without having build a 2nd array keyed
> with (yy/mm/dd).
> 
> Any Suggestions?
> 
> Thanks,
> Brad Bosley
> Motorola SPS

I am So Very Sorry (again). The last suggestion was wrong. Below has
been tested.

#!/usr/bin/perl

string = '123456789_123456789';
$chunkSize = 4;

#@result = split /(.{$chunkSize}?)/, $string;
# above adds spaces

while ($string =~ /.{$chunkSize}?/g) {
  push @result, $&;
}
$" = "\n";

print "@result\n";
 

Output from program...
1234
5678
9_12
3456  
--
Eric
<mailto:eric@nettown.com>
[http://nettown.com/perl/]
have a good day!


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

Date: 28 Mar 1997 21:10:49 GMT
From: c.c.eiftj@33.usenet.us.com (Rahul Dhesi)
Subject: Re: term 'regular expressions' considered undesirable
Message-Id: <5hhc4p$sni@samba.rahul.net>

In <omohc7v25z.fsf@tees.cs.ualberta.ca> Vladimir Alexiev
<vladimir@cs.ualberta.ca> writes:

>Now an example showing that non-greedy matching may require backtracking:
>"abbc" =~ /a.*?b[^b]c/  The .*? will first match "" but then it will have to
>reconsider and match the first b.

Note that "abbc" will never match /a.*?b[^b]c/.

But anyway:

If you make this anchored, then backtracking is not required.  Let's
implement a state machine for /^a.*?b[^b]c/ .  An implicit fail on EOF
is assumed unless we have already declard success.

start:    if 'a' goto dotstar else fail.
dotstar:  if 'b' goto sawb else remain in dotstar.
sawb:     if 'b' goto sawb else goto wantc.
wantc:    if c declare success else if b goto sawb else goto dotstar.

-- 
Rahul Dhesi <dhesi@spams.r.us.com>
a2i communications, a quality ISP with sophisticated anti-junkmail features
** message body scan immune to fake headers ***   see http://www.rahul.net/
>>> "please ignore Dhesi" -- Mark Crispin <mrc@CAC.Washington.EDU> <<<


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

Date: 28 Mar 1997 15:11:08 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: blm@halcyon.com (Brian L. Matthews)
Subject: Re: TPJ: Nukes
Message-Id: <8chghvhdkz.fsf@gadget.cscaper.com>

>>>>> "Brian" == Brian L Matthews <blm@halcyon.com> writes:

Brian> I just wonder how many times he used the Schwartzian Transform... :-)

As long as it doesn't map() to my house, which'd be the sort() of
thing that could really ruin my day.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 521 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 28 Mar 1997 20:16:50 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Matthew.Healy@yale.edu (Matthew D. Healy)
Subject: Re: Using an "@" in a perl format
Message-Id: <8cvi6b4cbh.fsf@gadget.cscaper.com>

>>>>> "Matthew" == Matthew D Healy <Matthew.Healy@yale.edu> writes:

Matthew> In article <333A8B6E.5A1A@psu.edu>, jqw4@psu.edu wrote:
Matthew> Have you tried replacing the @ with a backwhacked \@ as recommended
Matthew> in the FAQ?

Which FAQ?  I didn't see this anywhere.  Mostly because that would be
the FWATTFAQ.  (Frequent Wrong Answer To This Frequently Asked
Question.)

The only trivial way to get @ into a format is to make a one-character
field whose value is '@'... just like another poster already showed.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 521 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

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

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