[22485] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4706 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 13 18:05:48 2003

Date: Thu, 13 Mar 2003 15:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 13 Mar 2003     Volume: 10 Number: 4706

Today's topics:
        fax with efax and an external modem (Craig Dean)
        Find and Replace in PERL <kunal.patel@motorola.com>
    Re: Find and Replace in PERL <noreply@gunnar.cc>
    Re: Find and Replace in PERL hsalgado@dcc.uchile.cl
    Re: HoH vs. more memory efficient way to sum log entrie (Anno Siegel)
    Re: http cgi and perl <member17678@dbforums.com>
    Re: http cgi and perl <ben_altman@deadspam.com>
    Re: Interpolation problem? <tzz@lifelogs.com>
    Re: Interpolation problem? <stevenm@bogus.blackwater-pacific.com>
    Re: Interpolation problem? <usenet@dwall.fastmail.fm>
    Re: Interpolation problem? (Paul)
    Re: Letting users change their password via web form... <Mandrake@dream-server.com>
        OFFER Re: What's wrong with the Perl docs <penny1482@attbi.com>
    Re: OFFER Re: What's wrong with the Perl docs <ddunham@redwood.taos.com>
    Re: OFFER Re: What's wrong with the Perl docs <kkeller-mmmspam@wombat.san-francisco.ca.us>
    Re: OFFER Re: What's wrong with the Perl docs <mgjv@tradingpost.com.au>
        Parser::RecDescent - dynamic repetition specifier? <user2048@yahoo.removethis.com>
        Printing a 2d array <mail@annuna.com>
    Re: Printing a 2d array <usenet@dwall.fastmail.fm>
    Re: Printing a 2d array (Jay Tilton)
    Re: Simple Traversing Many-Dimensional Array Question (Anno Siegel)
    Re: Simple Traversing Many-Dimensional Array Question (Jay Tilton)
    Re: Uninitialised variable - no it isn't! <s.patterson@freeuk.com>
    Re: What's wrong with the Perl docs <abigail@abigail.nl>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 13 Mar 2003 13:42:28 -0800
From: craigd@bellsouth.net (Craig Dean)
Subject: fax with efax and an external modem
Message-Id: <e251e50d.0303131342.5603f15@posting.google.com>

OR my solution to sending a fax response from a web site

$fax = "5551212";  # or whatever the user enters/form field
$fax_program = "/usr/bin/efax -d /dev/ttyS0 ";
$file = "1047587401";  # I am using time as a filename
                       # this should include everything
                       # you want in the fax
&send_fax($fax, $file);

sub send_fax {
local($faxno, $filename) = @_;
open (FAXPRG, "|$fax_program -t 9,$faxno,,5120 $filename\n") ||
&web_error("Could Not Open Fax Program");

close (FAXPRG);
}

sub web_error {
    local ($error) = @_;
    $error = "Error Occured: $error";
    print "$error<p>\n";
    die $error;

}

my serial port would not work as /dev/modem that's why i used
/dev/ttyS0
the | (pipe) in front of $fax_program is important


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

Date: Thu, 13 Mar 2003 14:12:49 -0600
From: "KP" <kunal.patel@motorola.com>
Subject: Find and Replace in PERL
Message-Id: <b4qopq$hnh$1@newshost.mot.com>

I would like to find a string like "xyz abc 234" in my text file and replace
it with " mmm nnn 999".  How do I do that in PERL ?

Also I would like to display 2 lines before the line that matches my string
and 2 lines after the match .....

If you can point me to any useful resources, would be much appreciated.
Thanks
-k





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

Date: Thu, 13 Mar 2003 21:43:44 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Find and Replace in PERL
Message-Id: <b4qqhb$220gmp$1@ID-184292.news.dfncis.de>

KP wrote:
> I would like to find a string like "xyz abc 234" in my text file and replace
> it with " mmm nnn 999".  How do I do that in PERL ?
> 
> Also I would like to display 2 lines before the line that matches my string
> and 2 lines after the match .....
> 
> If you can point me to any useful resources, would be much appreciated.

The Perl documentation might be worth a try. Wouldn't you think so, too?

/ Gunnar

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



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

Date: Thu, 13 Mar 2003 20:58:55 +0000 (UTC)
From: hsalgado@dcc.uchile.cl
Subject: Re: Find and Replace in PERL
Message-Id: <b4qref$dhn$3@helcaraxe.dcc.uchile.cl>

KP <kunal.patel@motorola.com> wrote:
> I would like to find a string like "xyz abc 234" in my text file and replace
> it with " mmm nnn 999".  How do I do that in PERL ?

perl -pi.bak -e 's/xyz abc 234/mmm nnn 999/;' file

hugo



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

Date: 13 Mar 2003 19:43:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: HoH vs. more memory efficient way to sum log entries?
Message-Id: <b4qn1j$6r4$1@mamenchi.zrz.TU-Berlin.DE>

Steve Grazzini  <grazz@nyc.rr.com> wrote in comp.lang.perl.misc:
> Ben Kennedy <bkennedy@hmsonline.com> wrote:
> > 
> > <adam@pls.posthere.com> wrote in message
> > news:bk817vgm8d2lqojd6ofatrj9fi843hglnj@4ax.com...
> > 
> >> But since I am running it on the squid logs for the entire month of
> >> February (and our cache is big/busy), it is running out of memory
> >>
> >> ...
> >>
> >> open(LOG,"$squidlog") || die "cannot open $squidlog: $!";
> >>
> >> foreach $match (<LOG>)
> >>  {
> > 
> > What this is doing is reading the entire log file into memory, and is
> > probably the culprit rather than your data structure.  Try:
> 
> Rrr.. didn't even see that.
> 
> Just ignore my suggestion downthread. :)

Ah, yes.  Unintentional slurping -- innocent sinners are the hardest
to spot.

For file-reading use while-loops, for everything else use for-loops.
Exceptions granted.

Anno


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

Date: Thu, 13 Mar 2003 18:42:18 +0000
From: Mario542 <member17678@dbforums.com>
Subject: Re: http cgi and perl
Message-Id: <2640880.1047580938@dbforums.com>


Thanks for all the Help

--
Posted via http://dbforums.com


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

Date: Thu, 13 Mar 2003 14:28:24 -0500
From: Ben <ben_altman@deadspam.com>
Subject: Re: http cgi and perl
Message-Id: <b4qm4o$20iv9a$1@ID-121117.news.dfncis.de>

Jay Tilton wrote:
> Mario542 <member17678@dbforums.com> wrote:
>  
> : I have a web page the references a perl scripts, but when I try to run
> : it tries to download the perl file instead of running it. Any ideas??
> 
> This is a web server configuration issue, not a Perl one.

And now that people know what's going on in the scripts it is probably a 
security issue too :-)

regards,
Ben



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

Date: Thu, 13 Mar 2003 15:30:13 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Interpolation problem?
Message-Id: <4n7kb3ovqi.fsf@lockgroove.bwh.harvard.edu>

On 13 Mar 2003, ppopour@coastalnow.net wrote:
> I've tried every combination I could think of in this regex and read
> the perlre and perlop material and search for post on the problem
> but I must be missing the obvious.
> 
> I'm traversing an IIS server directory structure comparing file
>  sizes.  I want to strip my root path off of a fully qualified file
>  name that is being compiled as the structure is traversed.
> 
> $root  = '//server4/k\$/inetpub';
> $entry = '//server4/k\$/inetpub/Wwwroot/sub1/filename.ext';
> $entry =~ s/$root//;
> print "$entry\n";

Besides the File::Basename already suggested, you should look at the
File::Find module (comes with Perl).  It's built for directory
traversing, and gives you the current filename with and without the
path ($File::Find::name and $_).

Ted


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

Date: Thu, 13 Mar 2003 14:04:43 -0800
From: Steve May <stevenm@bogus.blackwater-pacific.com>
Subject: Re: Interpolation problem?
Message-Id: <b4qunn$6fi$1@quark.scn.rain.com>

Paul wrote:
> I've tried every combination I could think of in this regex and read
> the perlre and perlop material and search for post on the problem but
> I must be missing the obvious.
> 
> I'm traversing an IIS server directory structure comparing file sizes.
>  I want to strip my root path off of a fully qualified file name that
> is being compiled as the structure is traversed.
> 
> $root  = '//server4/k\$/inetpub';
                         ^ escape not needed w/single quotes

> $entry = '//server4/k\$/inetpub/Wwwroot/sub1/filename.ext';
> $entry =~ s/$root//;
> print "$entry\n";
> 
> I've changed $root to the server name and the results are as expected.
>  I've tried double quoting with double backslashes and that didn't
> seem to make any difference.  I've changed the delimiter to | and #
> that didn't seem to make any difference.  Any help would be
> appreciated.
> 
> Paul

The other suggestions given are good ones (modules to use) but maybe 
you're annoyed because you can't make the substitution above work?

You might try to 'quote' the pattern scalar:

my $root = '/some/path/to/foo';
my $entry = '/some/path/to/foo/foo.txt';

$entry =~ s/\Q$root\E//;
              ^      ^ trailing \E is not mandatory (in this case)

print "$entry\n";

Didn't test this, but it's so brain dead simple that I don't *think* I 
screwed it up. :-)

s.



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

Date: Thu, 13 Mar 2003 22:06:45 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Interpolation problem?
Message-Id: <Xns933DAE146C78dkwwashere@216.168.3.30>

Ted Zlatanov <tzz@lifelogs.com> wrote on 13 Mar 2003:

> On 13 Mar 2003, ppopour@coastalnow.net wrote:
>> 
>> I'm traversing an IIS server directory structure comparing file
>>  sizes.  I want to strip my root path off of a fully qualified
>>  file name that is being compiled as the structure is traversed.
> 
> Besides the File::Basename already suggested, you should look at
> the File::Find module (comes with Perl).  It's built for directory
> traversing, and gives you the current filename with and without
> the path ($File::Find::name and $_).

Thanks for catching that.  

/me reminds himself once again to slow down and read more carefully

-- 
David K. Wall - usenet@dwall.fastmail.fm
WWJD? JWRTFM.


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

Date: 13 Mar 2003 14:28:35 -0800
From: ppopour@coastalnow.net (Paul)
Subject: Re: Interpolation problem?
Message-Id: <8ba68739.0303131428.500331e8@posting.google.com>

If I wanted the file name that would be suitable, however, I need to
get the full path minus the root path, ie. $entry needs to equal
/Wwwroot/sub1/filename.ext

"David K. Wall" <usenet@dwall.fastmail.fm> wrote in message news:<Xns933D88174EA61dkwwashere@216.168.3.30>...
> Paul <ppopour@coastalnow.net> wrote on 13 Mar 2003:
> 
> > I'm traversing an IIS server directory structure comparing file
> > sizes. 
> >  I want to strip my root path off of a fully qualified file name
> >  that 
> > is being compiled as the structure is traversed.
> > 
> > $root  = '//server4/k\$/inetpub';
> > $entry = '//server4/k\$/inetpub/Wwwroot/sub1/filename.ext';
> > $entry =~ s/$root//;
> > print "$entry\n";
> 
> Don't use a regex.  Use File::Basename.
> 
>     use File::Basename;
>     my $entry = '//server4/k\$/inetpub/Wwwroot/sub1/filename.ext';
>     my $filename = basename $entry;
>     print $filename;


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

Date: Thu, 13 Mar 2003 15:09:07 -0600
From: Mandrake <Mandrake@dream-server.com>
Subject: Re: Letting users change their password via web form...
Message-Id: <v71srjj0ngiic5@news.supernews.com>

See, now THAT'S what I'm talking about. I wasn't looking in the right place 
for the answers (obviously), and now Ted shows me someplace to look. I 
wasn't asking to be told HOW to do it specifically, so anything would have 
been nice. Thanks for that Ted - now I have somewhere else to read up on 
it.

As far as answering questions, I do answer a few every now and then (when I 
can be of help). Unfortunately I'm still no perl guru, but I'm trying to 
learn.

Thanks again for the link.

-- 
Take care,
Randall

Ted Zlatanov wrote:

> On Wed, 12 Mar 2003, Mandrake@dream-server.com wrote:
>> For what it's worth, I found the answer on my own, and now I guess
>> when I have a perl related question it will be better to just
>> research it until I find the answer, rather than ask a question, as
>> that seems to really bother people...
> 
> If you did any sort of search (newsgroup/web) on this topic you would
> find many, many answers to your original question.  Did you find them
> so unsatisfactory that you wanted to try asking the question again?
> 
> Here, so you can refer to this next time:
> 
> 
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=change+password+unix+web+form+perl&btnG=Google+Search
> 
> 4600 items, just now.
> 
>> and if someone comes to ME and asks how to do it, I'll tell them,
>> instead of feeding them a line and telling them to get lost.
> 
> Stick around and answer people's questions, then.
> 
> Ted



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

Date: Thu, 13 Mar 2003 20:10:32 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: OFFER Re: What's wrong with the Perl docs
Message-Id: <YA5ca.80889$sf5.52492@rwcrnsc52.ops.asp.att.net>

I agree w most of the points, AND I have offered on this and Tk group to
write ammendements to thoses portions of "docs" that I trip over. I'm a sort
of newbie, and I trip a LOT.

I only insist that my efforts be used and published.

Lots of short examples would be a hallmark of my style.

Not a single taker, nor positive response, particularily from AS (since I'm
really only interested in Windoz platforms).

Dick Penny




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

Date: Thu, 13 Mar 2003 20:20:08 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: OFFER Re: What's wrong with the Perl docs
Message-Id: <YJ5ca.164$JO1.10400967@newssvr14.news.prodigy.com>

Dick Penny <penny1482@attbi.com> wrote:
> Not a single taker, nor positive response, particularily from AS (since I'm
> really only interested in Windoz platforms).

Have you posted your items (preferably in diff format) to the p5p list?

Was there any comment from the list about the contents?

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >


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

Date: Thu, 13 Mar 2003 13:20:42 -0800
From: Keith Keller <kkeller-mmmspam@wombat.san-francisco.ca.us>
Subject: Re: OFFER Re: What's wrong with the Perl docs
Message-Id: <ansq4b.0vi.ln@goaway.wombat.san-francisco.ca.us>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

In article <YA5ca.80889$sf5.52492@rwcrnsc52.ops.asp.att.net>, Dick Penny wrote:
> I agree w most of the points, AND I have offered on this and Tk group to
> write ammendements to thoses portions of "docs" that I trip over. I'm a sort
> of newbie, and I trip a LOT.
> 
> I only insist that my efforts be used and published.

You ''insist''?  It seems unlikely that anyone would agree to publish
your work before they've seen it.

Write the patches, and if they're not accepted, host them and
tell people about them instead.  But it seems your demands are a
little unfair to those who maintain the docs you wish to change.

- --keith

- -- 
kkeller-mmmspam@wombat.san-francisco.ca.us
(try just my userid to email me)
public key:  http://wombat.san-francisco.ca.us/kkeller/kkeller.asc
alt.os.linux.slackware FAQ:  http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj5w9ikACgkQhVcNCxZ5ID+7dQCfdaAGRPBXrowuQ8goYdixxFQc
KjQAoIm/Yi2gqXLFWJoVnXR2Q2726mdl
=fnUl
-----END PGP SIGNATURE-----


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

Date: Thu, 13 Mar 2003 22:01:03 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: OFFER Re: What's wrong with the Perl docs
Message-Id: <slrnb71vsv.bkm.mgjv@verbruggen.comdyn.com.au>

On Thu, 13 Mar 2003 20:10:32 GMT,
	Dick Penny <penny1482@attbi.com> wrote:
> I agree w most of the points, AND I have offered on this and Tk group to
> write ammendements to thoses portions of "docs" that I trip over. I'm a sort
> of newbie, and I trip a LOT.

Then you should probably send patches to the documentation to the p5p.
You can use perlbug to do that, for example.

> I only insist that my efforts be used and published.

I don't think you are ever going to get that guarantee. If people
think your patch is worthwhile, it'll be included. If not, then it
won't. 

> Lots of short examples would be a hallmark of my style.
> 
> Not a single taker, nor positive response, particularily from AS (since I'm
> really only interested in Windoz platforms).

There has been a lot of effort over the last two years to converge the
ActiveState effort and the p5p effort, to make sure that Perl is
maintained in a single spot again. I doubt that ActiveState has much
interest in diverging too much from the main Perl source tree, and
that tree includes the documentation. 

While ActiveState has docuemntation that isn't part of Perl proper,
they do keep that separate from the main documentation set, and they
are pretty careful to only document in their own set the bits that are
independent from mainstream Perl


If you want the standard documentation changed, you need to go through
the p5p. if you want ActiveState's documentation changed, you'll have
to go through them, and make sure you are not trying to document
things there that should be part of mainstream Perl documentation. If
you have other information that you'd like to document, you can always
create a separate document, and see whether the p5p want to include it
(this is how, for example, perltoot, perlboot, perlio, and perlrequick
started), or ActiveState might like it. Otherwise, you can publish it
yourself.

Insisting that other people use anything you come up with is a bit..
well.. forceful, isn't it?

Martien
-- 
                        | 
Martien Verbruggen      | 
Trading Post Australia  | "Mr Kaplan. Paging Mr Kaplan..."
                        | 


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

Date: 13 Mar 2003 19:18:50 GMT
From: user2048 <user2048@yahoo.removethis.com>
Subject: Parser::RecDescent - dynamic repetition specifier?
Message-Id: <Xns933D9228E74CFmytokxyzzy@129.250.170.100>

I'm trying to use PRD to parse a file which is divided into sections,
where each section contains a line count, followed by that many lines.
My approach is to pass the line count as a subrule argument,
and then use it in a repetition specifier in the subrule. As in:

  file:  sections /^\z/

  sections: section(s?)

  section: line_count lines[$item{line_count}]

  line_count: /(\d+)/

  lines: line($arg[0])  # problem here

  line: /.*/

But this grammer causes the error message:

  Untranslatable item encountered: "$arg[0]"

What's the right way to solve this, using PRD?
Maybe rulevar & local, or the Replace method?

I'd like to use PRD for this, since more detailed parsing will be 
required, and I think the file format belongs all together in the 
grammer.


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

Date: Thu, 13 Mar 2003 15:27:48 -0600
From: Joe Creaney <mail@annuna.com>
Subject: Printing a 2d array
Message-Id: <3E70F7D4.9090505@annuna.com>

I am having trouble writing a function that will print out a 2d array.
I figure the logic goes something like this but I can't get the syntax 
right.

@array
for each loop (@array) {
	for each loop1 (@array [loop]{
			print $array [loop][loop1]
			}
		print new line
		}

Is this possible in perl?
		



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

Date: Thu, 13 Mar 2003 21:57:21 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Printing a 2d array
Message-Id: <Xns933DAC7C5C781dkwwashere@216.168.3.30>

Joe Creaney <mail@annuna.com> wrote on 13 Mar 2003:

> I am having trouble writing a function that will print out a 2d
> array. I figure the logic goes something like this but I can't get
> the syntax right.

perldoc perllol
perldoc perldsc

-- 
David K. Wall - usenet@dwall.fastmail.fm
WWJD? JWRTFM.


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

Date: Thu, 13 Mar 2003 22:40:16 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Printing a 2d array
Message-Id: <3e710245.77815711@news.erols.com>

Joe Creaney <mail@annuna.com> wrote:

: I am having trouble writing a function that will print out a 2d array.
: I figure the logic goes something like this but I can't get the syntax 
: right.

    print "@$_\n" for @array;

Set $" to suit your taste of interstitial string.



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

Date: 13 Mar 2003 20:49:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Simple Traversing Many-Dimensional Array Question
Message-Id: <b4qqs4$afo$1@mamenchi.zrz.TU-Berlin.DE>

JR <jrolandumuc@yahoo.com> wrote in comp.lang.perl.misc:
> Hi.  I was playing around with different data structures, and forgot
> the best means by which to traverse an array with more than two
> dimensions.

[...]

> Can someone help me with my brain freeze, and give me some sample code
> to solve this simple little problem (unless this is the only way to do
> it, which I doubt)?

No, it isn't the only way, but the problem you touch on is that of
traversing an arbitrary Perl data-structure, which isn't all that easy.

The standard solution is the module Data::Dumper, which unrolls any
data structure in a readable form.  It doesn't give the explicit array
indexing, however.


> #
> # Creating and traversing a many-dimensional array
> # 
> 
> #!/usr/bin/perl -w
> use diagnostics;
> use strict;

Laudible intro!

> my @AoA = (
>    [ 0, 0, 0 ],
>    [ 1, 1, 1 ],
>    [
>       [ 2, 2, 2 ],
>       [ 3, 3, 3 ],
>       [ 
>          [ 4, 4, 4 ],
>          [ 5, 5, 5 ],
>       ],
>    ],
> );
> 
> for my $a ( 0 .. $#AoA ) {
>    my $dim1 = $AoA[$a];

[code and output snipped]

You are approaching this in index-think, which is unperlish.  Use the
arrays perl gives you, and calculate indexes on the side if you need them.
Also, a non-recursive approach will have problems adapting to arrays
that nest deeper than the depth the program happens to cater for.  Here
is a better way of doing it:

    sub print_array {
        print_deep( [], @_);
    }

    sub print_deep {
        my $i_pack = shift;
        for ( @_ ) {
            unless ( ref $_ ) {
                print "Element @$i_pack is: $_\n";
            } else {
                push @$i_pack, 0;
                print_deep( $i_pack, @$_);
                pop @$i_pack;
            }
            $i_pack->[ -1]++ if @$i_pack;
        }
    }

    print_array( \ @AoA);

print_array() is only there to get the recursion going.  It sets up an
(initially empty) array of indexes to keep count of the position.

print_deep() does the job.  If it meets something that isn't an (array-)
ref, it prints it along with the current array of indexes.  If something
is an array-ref, print_deep adds a temporary index level and re-starts
itself with the content of the array-ref. In both cases, the last element
of the index stack is incremented for each item absolved.

I haven't tested this code thoroughly, but with your data it produces
the same output as yours.

Anno


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

Date: Thu, 13 Mar 2003 22:47:57 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Simple Traversing Many-Dimensional Array Question
Message-Id: <3e7108e4.79511272@news.erols.com>

jrolandumuc@yahoo.com (JR) wrote:

: Hi.  I was playing around with different data structures, and forgot
: the best means by which to traverse an array with more than two
: dimensions.

Recursion.

: I used the below code to traverse my many-dimensional array, but I
: think that I may be doing something wrong, 

The only thing wrong is that it's purpose-built with a certain data
structure in mind, so it's limited to structures no deeper than three
levels.  More ideally (and simply), it would handle a structure of
arbitrary depth.

: I need the next if and if statements (I use the next if to avoid 
: illegally using symbolic references, under use strict, and the if 
: statement to avoid printing out a given array reference number), just 
: to traverse the data structure, under the use strict pragma.

IOW, the code mimics an if/else structure, testing whether the element
in question is an array reference or a plain scalar value.  A real
if/else structure is easier to write and to understand.

The ref() function is useful.
    
    do_something() if ref( $dim1->[$b] ) eq 'ARRAY';

is more robust than

    do_something() if $dim1->[$b] =~ /ARRAY/;

since the stringy representation of $dim1->[$b] might contain 'ARRAY'
without necessarily being an array reference.

: #!/usr/bin/perl -w
: use diagnostics;
: use strict;
: 
: my @AoA = (
:    [ 0, 0, 0 ],
:    [ 1, 1, 1 ],
:    [
:       [ 2, 2, 2 ],
:       [ 3, 3, 3 ],
:       [ 
:          [ 4, 4, 4 ],
:          [ 5, 5, 5 ],
:       ],
:    ],
: );

# original code snipped

    sub traverse_AoA {
        my $name = shift;
        for( 0 .. $#_ ) {
            my $elem = $_[$_];
            if( ref $elem eq 'ARRAY' ) {
                traverse_AoA( "$name $_", @$elem );
            } else {
                print "$name $_ is: $elem\n";
            }
        }
    }
    traverse_AoA( 'Element', @AoA );



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

Date: 13 Mar 2003 21:58:35 GMT
From: Stephen Patterson <s.patterson@freeuk.com>
Subject: Re: Uninitialised variable - no it isn't!
Message-Id: <slrnb71vob.m1.s.patterson@bloodnok.localdomain>

On Thu, 13 Mar 2003 12:43:43 +0100, Janek Schleicher wrote:
> I would guess the used $uri is relative.

Well, its actually an absolute unix file path, but I guess URI doesn't
handle those too well.

-- 
Stephen Patterson http://www.lexx.uklinux.net http://patter.mine.nu
steve@SPAM.lexx.uklinux.net  remove SPAM to reply        
Linux Counter No: 142831 GPG Public key: 252B8B37        
Last one down the pub's an MCSE


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

Date: 13 Mar 2003 22:34:45 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: What's wrong with the Perl docs
Message-Id: <slrnb721s4.k0s.abigail@alexandra.abigail.nl>

Tintin (me@privacy.net) wrote on MMMCDLXXXI September MCMXCIII in
<URL:news:b4pini$21mr4q$1@ID-172104.news.dfncis.de>:
 ..  Anyone seen http://clueless.justsomeguy.com/
 ..  
 ..  Anyone agree with any of his points?


If you want to start a discussion on Usenet, it's more helpful
to actually post the points you want to discuss, instead of
expecting people to fire up a webwowser.

Anyway, here are some comments.

++ What's wrong with the Perl docs
++ 
++    * Nowhere to easily get ones hands on the latest version

What is meant by that? Just download the newest version of Perl,
and you got it.

++    * References and tutorials are still mixed up

Mixed up in which sense? If I type 'man perl', I find a list of
tutorials on the first page.

++    * Index should be improved

No argument here.

++    * Foreign Language variations are unlikely to be kept up to date

Do we even have docs in foreign languages? It's a major effort to
translate them, and a hard job to keep up. 

++    * Code examples should follow the Perl style guide

Why? It's a style *GUIDE*, describing Larry's personal taste, and
for most points mentioned, it's said his preferences aren't even
so strong. If you want a language that comes with a drill sergeant
telling you how to walk the one way, visit www.python.org. 

++    * Lack of central quality control

p5p for the majority of the documentation, the documentation mailing list
for the FAQ. That's as much central control as for Perl itself.

++    * Hard to understand for beginners

For some beginners. For others, it isn't. *All* documentation will be
hard to understand for some beginners.

++    * Some functions documented by saying "works like it does in C"

Yes, and? Some functions are delegated to the C library. They will work
the same way as in C. Consult your systems manual page; it will be your
best resort, as such functions may not behave the same on all platforms
Perl runs on. Perl is at the mercy of your system, not only for the
working of the function, but also for its documenation.

++    * Not all functions have examples

So? Does that have to?

++    * One has to use perlbug to report bugs

Yes. What's the problem with that? It greatly increases your chances
your report will be filed correctly, and that the bug will eventually
be solved.

++    * Hard to get patched versions of the docs for old versions of perl

Patched versions of the docs are released together with maintainance
releases of Perl.

++    * Some not intuitively arranged (regexes in perlop)

In some cases, yes. But not in the example you give. Regular expressions
themselves are discussed in perlre, perlrequick and perlretut. But
regular expressions themselves are operators as well - just like strings -
and the operator aspects of regular expressions are discusses as well
in perlop.

++    * Perldoc tool should be improved

Improved to do what? Should it use chocolate flavoured fonts? Should
it sing and dance? Should it make coffee? Should it perform sexual
favours? 

++    * No effective search engine

Documentation is just text baby, nothing more. You want to search,
use 'grep'.

++    * Some FAQ entries are too complicated, leading to 'cargo cult code'

It's documentation for programmers. Some things ARE complicated. 
The FAQ isn't targetting toddlers. If you can't stand the heat,
stay out of the kitchen.

How this leads to 'cargo cult code' is unclear to me. Care to explain
that to us.


I've just one question for you:

    What's your contribution going to be to fix the points brought up?


Abigail
-- 
perl -wle\$_=\<\<EOT\;y/\\n/\ /\;print\; -eJust -eanother -ePerl -eHacker -eEOT


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 4706
***************************************


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