[32623] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3897 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Mar 10 21:09:18 2013

Date: Sun, 10 Mar 2013 18:09:05 -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           Sun, 10 Mar 2013     Volume: 11 Number: 3897

Today's topics:
        classic loop to controlled iterator <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
    Re: classic loop to controlled iterator <peter@makholm.net>
    Re: Existing module for file browser <rvtol+usenet@xs4all.nl>
    Re: Existing module for file browser <klaus03@gmail.com>
    Re: Existing module for file browser <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 10 Mar 2013 02:27:11 +0200
From: "George Mpouras" <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Subject: classic loop to controlled iterator
Message-Id: <khgk11$11g4$1@news.ntua.gr>

I think this is a nice trick.
Lets say we have a loop that will not stop until it finish e.g.

my $i=5;
    for (1..$i) { 
        print "$_\n"
    }
    for (2*$i..4*$i) {
        print "$_\n"
    }
}


it is possible to convert it to a contolable iterator like this


use strict;
use warnings;

my $prog = wrapper(5);

print "first  result : ", $prog->() ,"\n";
print "second result : ", $prog->() ,"\n";
while ( $_ = $prog->() ) {
print "*$_*\n";
}


sub wrapper {
my ($i, $last) = ($_[0], 0);

     sub {
     ++$last;
     my $result;   
     for ($last .. $i)  { $result ||= $_ }
     for ($last .. 4*$i) { $result ||= $_ }
     $result
     }
}



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

Date: Sun, 10 Mar 2013 09:09:04 +0100
From: Peter Makholm <peter@makholm.net>
Subject: Re: classic loop to controlled iterator
Message-Id: <87boarbrrz.fsf@vps1.hacking.dk>

"George Mpouras"
<nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam> writes:

> I think this is a nice trick.
> Lets say we have a loop that will not stop until it finish e.g.
>
> my $i=5;
>    for (1..$i) {      print "$_\n"
>    }
>    for (2*$i..4*$i) {
>        print "$_\n"
>    }
> }

Note that this set of loops performs 3*$i iterations of the loop bodies.

> sub wrapper {
> my ($i, $last) = ($_[0], 0);
>
>     sub {
>     ++$last;
>     my $result;     for ($last .. $i)  { $result ||= $_ }
>     for ($last .. 4*$i) { $result ||= $_ }
>     $result
>     }
> }

This will perform ((3*$i)^2)/2 iterations of the loop body.

In this specific case the difference might be negligible as the constant
number of print operations overshadows the other costs. But when
generalizing this method you need to take very care that the loop bodies
in the wrapper always has the form '$result ||= expr' which turns into
almost a no-op in all iterations except the initial.

You method will also have hard to handle the case where the loop body
might result in a false value.

//Makholm


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

Date: Sat, 09 Mar 2013 16:19:32 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Existing module for file browser
Message-Id: <513b5304$0$6948$e4fe514c@news2.news.xs4all.nl>

On 2013-03-08 22:37, John Black wrote:
> Hi, I have some perl code that processes a file or files and I want an easy Windows familiar
> way for the user to specify the filename.  I.e. my users are not really into "command lines".
>
> I have used Win32::GUI a little but I am looking for an off the shelf solution that someone
> has hopefully done to allow the user to use the windows file browser or something like it to
> traverse the directory tree, find their file and select it.  This module would ideally just
> return a scalar variable containing the filename with path and then my existing code can take
> it from there.  (extra credit to allow the user to select multiple filenames and have them
> returned in an array...)
>
> Does such a thing exist in the public domain?  Thanks!

Or tell them to use a specific extension on the file,
and configure your script to be the default opener for that extension.

Because then they can just doubleclick on the file's name, in their 
favorite file browser, to let your script have it.

You can also implement drag-and-drop, such that if the user drops a 
bunch of files on your icon, your script gets called.

-- 
Ruud



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

Date: Sat, 9 Mar 2013 11:41:22 -0800 (PST)
From: Klaus <klaus03@gmail.com>
Subject: Re: Existing module for file browser
Message-Id: <aaca4f68-074c-4159-8d44-bf5098ac379d@r8g2000vbj.googlegroups.com>

On 8 mar, 22:37, John Black <jbl...@nospam.com> wrote:
> Hi, I have some perl code that processes a file or files and I want an ea=
sy Windows familiar
> way for the user to specify the filename. =A0I.e. my users are not really=
 into "command lines".
>
> I have used Win32::GUI a little but I am looking for an off the shelf sol=
ution that someone
> has hopefully done to allow the user to use the windows file browser or s=
omething like it to
> traverse the directory tree, find their file and select it. =A0This modul=
e would ideally just
> return a scalar variable containing the filename with path and then my ex=
isting code can take
> it from there. =A0(extra credit to allow the user to select multiple file=
names and have them
> returned in an array...)

That's the kind of thing the "Windows-standard-File-Explorer-right-
click-sendto-folder" is made for:

First you write a "hello.bat" file that encapsulates a small perl
prototype as follows:

hello.bat:
----------------------
@rem =3D '--*-Perl-*--
@echo off
perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofperl
@rem ';
#!perl
use strict;
use warnings;
for my $file (@ARGV) {
    print "File '$file' has been selected\n";
    # ... do stuff with $file ...
}
__END__
:endofperl
pause
----------------------

Then you put the "hello.bat" file into your sendto-folder.

(on my Windows 7, the sendto-folder is under C:\Users\zzzz\AppData
\Roaming\Microsoft\Windows\SendTo\, you can use the start-icon on the
lower-left corner of your screen and type "shell:sendto" to find out
where the "sendto" folder is on your system...)

Once the "hello.bat" is in your "sendto" folder, just fire up your
File Explorer, any old directory will do, let's say you go straight to
your C:\ directory, you select 2 or 3 files and you right-click and
select sendto...

Under sendto, you will find (amongst other things) a menu "hello.bat"
-- go straight to that "hello.bat" and voil=E0: the names of the
selected files appear in a dos-box.

I hope this helps.


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

Date: Sun, 10 Mar 2013 02:16:26 +0200
From: "George Mpouras" <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Subject: Re: Existing module for file browser
Message-Id: <khgjcs$t3e$1@news.ntua.gr>

what I do is to use one of the
"zenity" , "kdialog" or "zenity for windows"
some times I write a small vbs script for user input



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

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


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