[29338] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 582 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 26 14:24:47 2007

Date: Tue, 26 Jun 2007 11:24:34 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 26 Jun 2007     Volume: 11 Number: 582

Today's topics:
        problem of copying individual worksheets in separate wo <ra10kumar@gmail.com>
    Re: problem of copying individual worksheets in separat <bik.mido@tiscalinet.it>
    Re: problem of copying individual worksheets in separat <ra10kumar@gmail.com>
    Re: problem of copying individual worksheets in separat <bik.mido@tiscalinet.it>
        Problem with autoincrement and strings with spaces <stoopot@hotmail.com>
    Re: Problem with autoincrement and strings with spaces <peter@makholm.net>
    Re: Problem with autoincrement and strings with spaces <noreply@gunnar.cc>
        Professional opinions on development frameworks wanted <flo.thiel@googlemail.com>
        sort function, in non-standard cases <alexxx.magni@gmail.com>
    Re: sort function, in non-standard cases <joe@inwap.com>
    Re: sort function, in non-standard cases <joe@inwap.com>
    Re: sort function, in non-standard cases anno4000@radom.zrz.tu-berlin.de
    Re: sort function, in non-standard cases anno4000@radom.zrz.tu-berlin.de
    Re: sort function, in non-standard cases <bik.mido@tiscalinet.it>
    Re: sort function, in non-standard cases <tadmc@seesig.invalid>
    Re: sort function, in non-standard cases <bik.mido@tiscalinet.it>
    Re: sort function, in non-standard cases <dummy@example.com>
    Re: sort function, in non-standard cases <dummy@example.com>
    Re: sort function, in non-standard cases <dummy@example.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 26 Jun 2007 04:26:30 -0700
From:  Ratan <ra10kumar@gmail.com>
Subject: problem of copying individual worksheets in separate workbook
Message-Id: <1182857190.586460.233840@e9g2000prf.googlegroups.com>

Hi All,

I have to write a script which does following task...

- Open a workbook.
- Read a worksheet and save it in a new workbook.
- Repeat step 2 for all worksheets of the original workbook.


Please help on solution of this.

Thanks in advance.



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

Date: Tue, 26 Jun 2007 14:15:00 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: problem of copying individual worksheets in separate workbook
Message-Id: <af02835n5rsq64kkuv1d99vf4c4dtd5tkd@4ax.com>

On Tue, 26 Jun 2007 04:26:30 -0700, Ratan <ra10kumar@gmail.com> wrote:

>Hi All,

Hi!

>I have to write a script which does following task...

I have to write a script which will earn me a pony. Now, where's my
pony?!?

>- Open a workbook.

*What* is a workbook? Too generic a term for me to think of anything
specific.

>- Read a worksheet and save it in a new workbook.

*What* is a workbook? Too generic a term for me to think of anything
specific.

>- Repeat step 2 for all worksheets of the original workbook.

Ditto.

>Thanks in advance.

You welcome!


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Tue, 26 Jun 2007 06:16:48 -0700
From:  Ratan <ra10kumar@gmail.com>
Subject: Re: problem of copying individual worksheets in separate workbook
Message-Id: <1182863808.772193.64020@j4g2000prf.googlegroups.com>

Sorry for the incomplete info...

Actually i am talking here about a Microsoft excel workbook.

- Open a workbook. [This is Microsoft Excel workbook]
- Read a worksheet and save it in a new workbook. [ By worksheet i
mean to say each of the worksheets in Excel]
- Repeat step 2 for all worksheets of the original workbook [ Save
each of the worksheets in new Excel file i.e. workbook]

Hope that this clarifies the question.



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

Date: Tue, 26 Jun 2007 18:11:30 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: problem of copying individual worksheets in separate workbook
Message-Id: <sge2839omrukuu77mkdr321rhp0t77i6lj@4ax.com>

On Tue, 26 Jun 2007 06:16:48 -0700, Ratan <ra10kumar@gmail.com> wrote:

>Actually i am talking here about a Microsoft excel workbook.
[snip]
>Hope that this clarifies the question.

It clarifies it in way that makes me sure I can't help you but
possibly pointing you to modules like Spreadsheet::ParseExcel,
Spreadsheet::WriteExcel or perhaps on a more general basis Win32::OLE.
None of which I really know anything about.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Tue, 26 Jun 2007 17:08:30 GMT
From: <stoopot@hotmail.com>
Subject: Problem with autoincrement and strings with spaces
Message-Id: <iKbgi.105712$hj5.36549@fe2.news.blueyonder.co.uk>

Hello,

I am learning perl and have noticed a problem with using the ++ and -- operators when used with 
strings containing spaces.  I would expect the last character of the string to be incremented but this
is not the case...

use strict;
use warnings;

my $char = 'a';
my $string = 'astring';
my $problem = 'A string with spaces';

print "\$char is " , $char , " \$string is ",
$string, " and problem is ", $problem , "\n";

$char++;
$string++;
$problem++;

print "\$char is now " , $char , " \$string is now ",
$string, " and problem is now ", $problem , "\n";

This gives the following output:

$char is a $string is astring and problem is A string with spaces
$char is now b $string is now astrinh and problem is now 1

A '1' is returned instead of the string.  Is there a way round this?

TIA.




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

Date: Tue, 26 Jun 2007 17:15:29 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: Problem with autoincrement and strings with spaces
Message-Id: <873b0ey6vi.fsf@makholm.net>

<stoopot@hotmail.com> writes:

> I am learning perl and have noticed a problem with using the ++ and --
> operators when used with strings containing spaces.  I would expect
> the last character of the string to be incremented but this is not the
> case...

perldoc perlop says clearly:

 The auto-increment operator has a little extra builtin magic to it.  If
 you increment a variable that is numeric, or that has ever been used in
 a numeric context, you get a normal increment.  If, however, the vari-
 able has been used in only string contexts since it was set, and has a
 value that is not the empty string and matches the pattern
 "/^[a-zA-Z]*[0-9]*\z/", the increment is done as a string, preserving
 each character within its range, with carry:

So the magic is documented not to work on strings containing spaces. I
guess they are just converted to numeric context and then incremented.

> A '1' is returned instead of the string.  Is there a way round this?

Probaly not (an easy way).

//Makholm


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

Date: Tue, 26 Jun 2007 19:20:58 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Problem with autoincrement and strings with spaces
Message-Id: <5ed0dcF37bt4iU1@mid.individual.net>

stoopot@hotmail.com wrote:
> I am learning perl and have noticed a problem with using the ++ and -- operators

So you started to read about "Auto-increment" etc. in "perldoc perlop", 
right?

> when used with strings containing spaces.

Then you didn't use the docs. :(

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


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

Date: Tue, 26 Jun 2007 17:25:33 -0000
From:  Florian Thiel <flo.thiel@googlemail.com>
Subject: Professional opinions on development frameworks wanted
Message-Id: <1182878733.373784.198950@g4g2000hsf.googlegroups.com>

Dear Perl web developers,

We at the Free University of Berlin are currently researching the ways
in which the major web development platforms differ and in addition to
our work with the Plat_Forms contest, we're now looking for actual
professional opinions.

If you have practical experience in the development of non-trivial web
applications with two or more web development languages then we would
like you to participate in a short survey. Three Perl teams
participated in this year's Plat_Forms contest but we would like to
get a broader perspective.

The questionnaire asks you about your experiences and opinions on two
of the web development languages you have used, and should take about
10-15 minutes to complete. To thank you for your participation, you
will be able to provide an email address and we will send you our
final report when we are finished compiling it.

    http://www.plat-forms.org/survey/

We look forward to your answers and experiences, let me know via email
if you have any questions.

Florian Thiel
thiel@inf.fu-berlin.de
Plat_Forms survey team



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

Date: Tue, 26 Jun 2007 01:00:06 -0700
From:  "alexxx.magni@gmail.com" <alexxx.magni@gmail.com>
Subject: sort function, in non-standard cases
Message-Id: <1182844806.504014.31080@p77g2000hsh.googlegroups.com>

Hi everybody,
I need some hints on how to setup the sort function in a couple of
cases that happened to me recently

<disclaimer>I already did perldoc -f sort, yet I found mainly
discussed numerical/alphabetical cases</disclaimer>

The two sort problems I had - neither of which I was able to solve -
are the following:

1) given in @a a list of files/directories (e.g. returned by
File::Find), sort it directories first, then symlinks, then common
files.
The nearer I came was:

                        @a=sort {my $x= -d $a; my $y= -d $b; return $x
<=> $y} @a;

but it doesnt work.

2) sort @a, based on the existence/non-existence of the hash value
$c{$a}, where $a's are the elements of @a.

Both the problems are related to my difficulty of translating them in
some kind of comparison between two generic elements $a vs $b, as in
the typical $a<=>$b

Any hint is welcome!

Alessandro Magni



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

Date: Tue, 26 Jun 2007 01:39:30 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: sort function, in non-standard cases
Message-Id: <i9qdnSzwWu9ZTR3bnZ2dnUVZ_vyunZ2d@comcast.com>

alexxx.magni@gmail.com wrote:
> Hi everybody,
> I need some hints on how to setup the sort function in a couple of
> cases that happened to me recently
> 
> <disclaimer>I already did perldoc -f sort, yet I found mainly
> discussed numerical/alphabetical cases</disclaimer>

It is unfortunate that `perldoc -f sort` does not mention "Schwartzian Transform".
http://en.wikipedia.org/wiki/Schwartzian_transform

> sort it directories first, then symlinks, then common files.

#!/usr/bin/perl
# Purpose: Outputs directory listing, dirs first, then symlinks, then rest
use strict; use warnings;

push @ARGV,(glob '*') unless @ARGV;
my @typed_names =
         map {substr $_,1}
         sort
         map { -l $_ ? "l$_" : -d $_ ? "d$_" : "r$_"}
         @ARGV;
print join("\n",@typed_names),"\n";

	-Joe


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

Date: Tue, 26 Jun 2007 01:53:49 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: sort function, in non-standard cases
Message-Id: <Uqadnd4nOK6CSR3bnZ2dnUVZ_ubinZ2d@comcast.com>

Joe Smith wrote:

> #!/usr/bin/perl
> # Purpose: Outputs directory listing, dirs first, then symlinks, then rest
> use strict; use warnings;
> 
> push @ARGV,(glob '*') unless @ARGV;
> my @typed_names =
>         map {substr $_,1}
>         sort
>         map { -l $_ ? "l$_" : -d $_ ? "d$_" : "r$_"}
>         @ARGV;
> print join("\n",@typed_names),"\n";

Another way:

sub sort_dir3 {
   my %dir;
   my @res;
   foreach my $ent (@_) {
     my $key = -l $ent ? 'Link' : -d $ent ? 'Directory' : 'Regular';
     push @{$dir{$key}},$ent;
   }
   push @res, "\t\t$_\n",join("\n",sort @{$dir{$_}}),"\n\n" for sort keys %dir;
   @res;
}

	-Joe

P.S. The test for -l() before testing for -d() is deliberate.  Unless you
want symlinks to directories to show up as directories instead of as symlinks.


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

Date: 26 Jun 2007 09:29:05 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: sort function, in non-standard cases
Message-Id: <5ec4j1F3792reU1@mid.dfncis.de>

alexxx.magni@gmail.com <alexxx.magni@gmail.com> wrote in comp.lang.perl.misc:
> Hi everybody,
> I need some hints on how to setup the sort function in a couple of
> cases that happened to me recently
> 
> <disclaimer>I already did perldoc -f sort, yet I found mainly
> discussed numerical/alphabetical cases</disclaimer>
> 
> The two sort problems I had - neither of which I was able to solve -
> are the following:
> 
> 1) given in @a a list of files/directories (e.g. returned by
> File::Find), sort it directories first, then symlinks, then common
> files.
> The nearer I came was:
> 
>                         @a=sort {my $x= -d $a; my $y= -d $b; return $x
> <=> $y} @a;
> 
> but it doesnt work.

That is a typical candidate for a Schwartz transform.  To each file,
assign a rank of 0, 1, or 2 according as it is a directory, a symlink
or anything else.  Then sort according to rank, breaking ties by
comparing the file names:

    my @sorted_files = map $_->[ 0] =>
        sort { $a->[ 1] <=> $b->[ 1] || $a->[ 0] cmp $b->[ 0] }
        map {
            my $rank = 2;
            $rank = 0 if -d;
            $rank = 1 if -l;
            [ $_, $rank];
        }
        @files;

Anno


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

Date: 26 Jun 2007 09:36:48 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: sort function, in non-standard cases
Message-Id: <5ec51gF3792reU2@mid.dfncis.de>

Joe Smith  <joe@inwap.com> wrote in comp.lang.perl.misc:
> alexxx.magni@gmail.com wrote:
> > Hi everybody,
> > I need some hints on how to setup the sort function in a couple of
> > cases that happened to me recently
> > 
> > <disclaimer>I already did perldoc -f sort, yet I found mainly
> > discussed numerical/alphabetical cases</disclaimer>
> 
> It is unfortunate that `perldoc -f sort` does not mention "Schwartzian
> Transform".
> http://en.wikipedia.org/wiki/Schwartzian_transform
> 
> > sort it directories first, then symlinks, then common files.
> 
> #!/usr/bin/perl
> # Purpose: Outputs directory listing, dirs first, then symlinks, then rest
> use strict; use warnings;
> 
> push @ARGV,(glob '*') unless @ARGV;
> my @typed_names =
>          map {substr $_,1}
>          sort
>          map { -l $_ ? "l$_" : -d $_ ? "d$_" : "r$_"}
>          @ARGV;
> print join("\n",@typed_names),"\n";

That's not strictly a Schwartz transform but a Guttman-Roesler
transform (GRT).  A Schwartz transform builds a list of anonymous
arrays that hold the sort key(s) and the original elements and
uses a sort block to access the keys.  A GRT (like your solution)
prepends a single sort key in string form and uses the default sort.

Anno


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

Date: Tue, 26 Jun 2007 12:12:01 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: sort function, in non-standard cases
Message-Id: <6dp183ho4ksm7qaleshielb69hlj0u74hp@4ax.com>

On Tue, 26 Jun 2007 01:39:30 -0700, Joe Smith <joe@inwap.com> wrote:

>my @typed_names =
>         map {substr $_,1}
>         sort
>         map { -l $_ ? "l$_" : -d $_ ? "d$_" : "r$_"}
>         @ARGV;

++ x 10**3! Strictly speaking this is not an ST, which you mention,
but even a GRT, which is better in many respcts. I would have gone ST,
but your solution is more compact, elegant, and most probably fast.
Best code contribution I've seen in some time! FYI, I'm reporting it
elsewhere...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Tue, 26 Jun 2007 06:09:38 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: sort function, in non-standard cases
Message-Id: <slrnf81svi.bmd.tadmc@tadmc30.sbcglobal.net>

Joe Smith <joe@inwap.com> wrote:

> It is unfortunate that `perldoc -f sort` does not mention "Schwartzian Transform".


But `perldoc -q sort` does.  :-)


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Tue, 26 Jun 2007 13:23:15 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: sort function, in non-standard cases
Message-Id: <0ot183poqqh3rrghuq5du3ak680umutcke@4ax.com>

On Tue, 26 Jun 2007 12:12:01 +0200, Michele Dondi
<bik.mido@tiscalinet.it> wrote:

>Best code contribution I've seen in some time! FYI, I'm reporting it
>elsewhere...

Done: <http://perlmonks.org/?node_id=623356>.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Tue, 26 Jun 2007 13:25:14 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: sort function, in non-standard cases
Message-Id: <_s8gi.11319$tB5.3233@edtnps90>

Joe Smith wrote:
> alexxx.magni@gmail.com wrote:
>> I need some hints on how to setup the sort function in a couple of
>> cases that happened to me recently
>>
>> sort it directories first, then symlinks, then common files.
> 
> #!/usr/bin/perl
> # Purpose: Outputs directory listing, dirs first, then symlinks, then rest
> use strict; use warnings;
> 
> push @ARGV,(glob '*') unless @ARGV;
> my @typed_names =
>         map {substr $_,1}
>         sort
>         map { -l $_ ? "l$_" : -d $_ ? "d$_" : "r$_"}
>         @ARGV;
> print join("\n",@typed_names),"\n";

You only need to stat the files once:

my @typed_names =
         map {substr $_,1}
         sort
         map { -l $_ ? "l$_" : -d _ ? "d$_" : "r$_"}
         @ARGV;



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Tue, 26 Jun 2007 13:27:49 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: sort function, in non-standard cases
Message-Id: <pv8gi.11321$tB5.8469@edtnps90>

anno4000@radom.zrz.tu-berlin.de wrote:
> 
> That is a typical candidate for a Schwartz transform.  To each file,
> assign a rank of 0, 1, or 2 according as it is a directory, a symlink
> or anything else.  Then sort according to rank, breaking ties by
> comparing the file names:
> 
>     my @sorted_files = map $_->[ 0] =>
>         sort { $a->[ 1] <=> $b->[ 1] || $a->[ 0] cmp $b->[ 0] }
>         map {
>             my $rank = 2;
>             $rank = 0 if -d;
>             $rank = 1 if -l;
>             [ $_, $rank];
>         }
>         @files;

You only need to stat the files once:

     my @sorted_files = map $_->[ 0] =>
         sort { $a->[ 1] <=> $b->[ 1] || $a->[ 0] cmp $b->[ 0] }
         map {
             my $rank = 2;
             $rank = 0 if -d;
             $rank = 1 if -l _;
             [ $_, $rank];
         }
         @files;



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Tue, 26 Jun 2007 13:36:58 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: sort function, in non-standard cases
Message-Id: <_D8gi.12580$xk5.614@edtnps82>

anno4000@radom.zrz.tu-berlin.de wrote:
> 
> That's not strictly a Schwartz transform

"Schwartzian Transform"

> but a Guttman-Roesler transform (GRT).

That should be Guttman-Rosler.

http://www.sysarch.com/Perl/sort_paper.html



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 582
**************************************


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