[32285] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3552 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 27 00:09:20 2011

Date: Sat, 26 Nov 2011 21:09:04 -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           Sat, 26 Nov 2011     Volume: 11 Number: 3552

Today's topics:
    Re: access a 2D array column by column <justin.1111@purestblue.com>
    Re: access a 2D array column by column <jwkrahn@example.com>
    Re: access a 2D array column by column <willem@toad.stack.nl>
    Re: access a 2D array column by column <tadmc@seesig.invalid>
    Re: Convert Wiki to HTML <ben@morrow.me.uk>
    Re: Convert Wiki to HTML <*@eli.users.panix.com>
        XML::XPath Question <elwood@agouros.de>
    Re: XML::XPath Question <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 25 Nov 2011 09:55:38 +0000
From: Justin C <justin.1111@purestblue.com>
Subject: Re: access a 2D array column by column
Message-Id: <q954q8-nra.ln1@zem.masonsmusic.co.uk>

On 2011-11-25, ela <ela@yantai.org> wrote:
> To access a spreadsheet file column by column, I use the 2D array @AoA to 
> store the contents. However, I don't know how to state in the for loop 
> because common perl tutorials assume access row by row. What should I 
> replace $#AoA with?


This spreadsheet you have, if it's Excel then Spreadsheet::ParseExcel is
useful:


#!/usr/bin/perl

use warnings;
use strict;

use Spreadsheet::ParseExcel;

my $parser = Spreadsheet::ParseExcel->new();
my $wb = $parser->parse($ENV{HOME} . '/some.xls');

die unless defined $wb;

for my $ws ( $wb->worksheets() ) {
	my ($row_min, $row_max) = $ws->row_range();
	my ($col_min, $col_max) = $ws->col_range();
	
	for my $col ($col_min .. $col_max) {
		for my $row ($row_min .. $row_max) {
			my $cell = $ws->get_cell($row, $col);
			print $cell->value(), "\n";
		}
	}
}

__END__

But please read and understand the comments others have posted.


   Justin.

-- 
Justin C, by the sea.


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

Date: Fri, 25 Nov 2011 02:34:27 -0800
From: "John W. Krahn" <jwkrahn@example.com>
Subject: Re: access a 2D array column by column
Message-Id: <WaKzq.4671$g35.4298@newsfe09.iad>

Tad McClellan wrote:
> ela<ela@yantai.org>  wrote:
>>
> Since you do not use @cells outside of the while loop, you should
> scope @cells to the while loop's block rather than scoping it
> to the whole file like that.
>
>
>> while ($line=<FP>) { chomp $line; @cells = split /\t/, $line;
>
>      while (my $line =<$FP>) {
>          chomp $line;
>          my @cells = split /\t/, $line;
>
>
>>   push @AoA, [ @cells ];
>
>
> Now that @cells is properly scoped, you can take a reference to
> it directly rather than having to copy it to an anonymous array:
>
>      push @AoA, \@cells;

Or just copy the list directly:

     while (my $line = <$FP>) {
         chomp $line;
         push @AoA, [ split /\t/, $line ];



John
-- 
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein


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

Date: Fri, 25 Nov 2011 13:24:31 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: access a 2D array column by column
Message-Id: <slrnjcv5of.fip.willem@toad.stack.nl>

John W. Krahn wrote:
) Or just copy the list directly:
)
)      while (my $line = <$FP>) {
)          chomp $line;
)          push @AoA, [ split /\t/, $line ];

Or just do it all at once:

  my @AoA = map { chomp; [ split /\t/ ] } <$FP>;

Anyone want to go for an eagle?


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


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

Date: Fri, 25 Nov 2011 09:41:26 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: access a 2D array column by column
Message-Id: <slrnjcvds6.epp.tadmc@tadbox.sbcglobal.net>

Justin C <justin.1111@purestblue.com> wrote:

> But please read and understand 


That is extremely unlikely.  :-(


> the comments others have posted.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Fri, 25 Nov 2011 04:57:44 -0600
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Convert Wiki to HTML
Message-Id: <l4-dnTwbcuA16VLTnZ2dnUVZ7sGdnZ2d@bt.com>


Quoth Horst Lemminger <damjensen@gmail.com>:
> > If you do not want to integrate this with any tool or DocuWiki itself
> > - why not use LWP kind of modules to scrape/crawl the sites as html
> > pages. that will be quick solution and get all App into static html
> > page.
> 
> This could be my last resort, but since I would like to do the
> following
>    * edit text in my own application (simple notepad-like edit window
>         - text format ideally Wiki
>    * files are saved as text files OR in a database backend
>    * now files can be compiled with a script to static HTML
>    * the static HTML is the "help window" for a Windows application
> 
> So I do not need a webserver for this project, unless I have to.
> 
> But as you say, I could be forced to have one.

It sounds to me like you want Text::Markup, or one of the modules it
depends on.

Or you could just use pod.

Ben



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

Date: Fri, 25 Nov 2011 20:39:17 +0000 (UTC)
From: Eli the Bearded <*@eli.users.panix.com>
Subject: Re: Convert Wiki to HTML
Message-Id: <eli$1111251532@qz.little-neck.ny.us>

In comp.lang.perl.misc, Horst Lemminger  <damjensen@gmail.com> wrote:
> I would like to convert the raw source of a local Wiki to HTML (static
> files), preferably DokuWiki.
 ...
> What are my choices here ?

No one has mentioned this yet, so why not. Find an installed wiki
of whatever flavor you want. Get an account on it. For each of your
documents start a new page on that wiki (they can all be the same
same name), post the document and preview the results. Save the
HTML from the preview, and edit out the the extraneous bits. For
a huge project or more than a one off task, I'd install the wiki
locally.

I'd probably do it once by hand observing with a logging proxy or
Live HTTP Headers or similar, then build the script to do it,
testing a few files very carefully, then run them all.

The beauty of this, is you get perfect wiki rendering, without needing
to know the details of that particular wiki syntax. All you need to
know is how to do HTTP requests and html editing.

Elijah
------
some wikis have pretty complicated syntax available


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

Date: Sat, 26 Nov 2011 09:31:47 +0000 (UTC)
From: Konstantinos Agouros <elwood@agouros.de>
Subject: XML::XPath Question
Message-Id: <1322299927.863330@rumba>

Hi,

I would like to do a relative search on a subtree.

Say I got a NodeCollection doing something like:

$list = $xmlpath->find("/a/b")

Now I iterate about all instances of <b> in the document and for each one
I want to find the c's that have attribute foo.

so I do a foreach my $bar ($list->get_nodelist)
{
 ...
}

can I do a $bar->find("c[@foo]") or how can I do this relative to the
subtree of each b?

Regards,

Konstantin
-- 
Dipl-Inf. Konstantin Agouros aka Elwood Blues. Internet: elwood@agouros.de
Altersheimerstr. 1, 81545 Muenchen, Germany. Tel +49 89 69370185
----------------------------------------------------------------------------
"Captain, this ship will not survive the forming of the cosmos." B'Elana Torres


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

Date: Sat, 26 Nov 2011 05:30:55 -0600
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: XML::XPath Question
Message-Id: <_oOdnVtxo4RyUE3TnZ2dnUVZ7qGdnZ2d@bt.com>


Quoth Konstantinos Agouros <elwood@agouros.de>:
> 
> I would like to do a relative search on a subtree.
> 
> Say I got a NodeCollection doing something like:
> 
> $list = $xmlpath->find("/a/b")
> 
> Now I iterate about all instances of <b> in the document and for each one
> I want to find the c's that have attribute foo.
> 
> so I do a foreach my $bar ($list->get_nodelist)
> {
> ...
> }
> 
> can I do a $bar->find("c[@foo]") or how can I do this relative to the
                        ^  ^ 
                        careful...
> subtree of each b?

You want

    my $clist = $xmlpath->find('./c[@foo]', $bar);

or './/c[@foo]' if you want indirect as well as direct descendents.

Ben



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

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:

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

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 3552
***************************************


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