[25124] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7374 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 7 18:05:18 2004

Date: Sun, 7 Nov 2004 15:05:07 -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           Sun, 7 Nov 2004     Volume: 10 Number: 7374

Today's topics:
    Re: an original perldoc viewer <usenet@morrow.me.uk>
    Re: Binary files in PERL? <benkhoo@copperblue.per.sg>
    Re: Binary files in PERL? <usenet@morrow.me.uk>
    Re: casting question <lawshouse.public@btconnect.com>
    Re: casting question <usenet_05_08_2004@stuartmoore.org.uk>
    Re: casting question <nospam@nospam.com>
    Re: casting question <usenet_05_08_2004@stuartmoore.org.uk>
    Re: casting question <nospam@nospam.com>
    Re: casting question <go@away.spam.invalid>
    Re: Common file operations (Seymour J.)
    Re: Converting multiple spaces for 3 col text? <usenet_05_08_2004@stuartmoore.org.uk>
        FAQ 4.75: How do I verify a credit card checksum? <comdog@panix.com>
        FAQ 8.32: How can I write expect in Perl? <comdog@panix.com>
    Re: map()'s BLOCK <bik.mido@tiscalinet.it>
        Problem with cp in system call running Mac OS X (Tom McDonough)
    Re: Problem with cp in system call running Mac OS X <todd@tdegruyl.com>
    Re: Problem with cp in system call running Mac OS X <tintin@invalid.invalid>
    Re: Simplifying by refactoring 'array ref' and glob fro <usenet@morrow.me.uk>
    Re: The most perfect beginning (J. Romano)
        Upload meter for a CGI perl script <sean@buildingonline.com>
    Re: Upload meter for a CGI perl script <usenet_05_08_2004@stuartmoore.org.uk>
        Using $SIG{"ALRM"}  assignment inside a subroutine ... torahul@gmail.com
    Re: Win32::OLE msxml collection problem <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 7 Nov 2004 16:00:17 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: an original perldoc viewer
Message-Id: <hdt162-ee4.ln1@osiris.mauzo.dyndns.org>


Quoth ioneabu@yahoo.com:
> Ben Morrow wrote:
> 
> > 
> > Quoth ioneabu@yahoo.com:
> >> I have been reprimanded for my lack of knowledge of perldoc material so I
> >> have decided to do more reading.  I realized that I am often (%50 of the
> >> time) working on a machine that does not have Perl but is connected to
> >> the
> >> internet.  My first thought was to go to perldoc.com, but it seemed  to
> >> be
> >> down tonight, so I wrote a simple home-made solution to get by for now. 
> >> I was hoping pod2html would format my perldocs but it did not work when I
> >> tried: pod2html perltoc (maybe perldoc pod2html says how to do it).  Here
> >> it is.  Improvements, especially in output formatting, would be welcome.
> >> 
> >> #!/usr/bin/perl
> > 
> > USE TAINT MODE.
> > 
> > #!/usr/bin/perl -T
> > 
> > This would have caught the error you noticed for yourself.
> > 
> > Ben
> > 
> 
> ok, I read perlsec and did a little testing...
> ------------------
> #!/usr/bin/perl -T
> 
> my $a = 'perl';
> `perldoc $a`;
> ------------------
> me>     perl -c test.pl
> Perl>   Too late for "-T" option at test.pl line 1.
> (what does that mean?)

This has been answered already...

> me>     ./test.pl
> Perl>   Insecure $ENV{PATH} while running with -T switch at ./test.pl line 4.
> (ok, this is useful and expected)
> 
> now test the CGI program with -T...with the protective regex
> screening removed...
> ------------------------------------------
> #!/usr/bin/perl -T
> 
> use CGI qw(:standard);
> if (param('display'))
> {
>         if (my $doc = param('docname'))
>         {
>                 $a = `perldoc $doc`; #this is the dangerous line
>                 $a = 'not found' if not $a;
>         }
>         else
>         {
>                 $a = 'invalid perldoc name';
>         }
> }
> print header(), start_html();
> print start_form(), p('Type name of perldoc'),
>         p(textfield(-name=>'docname')),
>         p(submit(-name=>'display')),
>         end_form();
> print pre($a), end_html();
> -------------------------------------------
> me>     ./testcgi.pl

Right... you are not passing any value for docname, so the undef that
CGI.pm gives you is not tainted. With

#!/usr/bin/perl -T

use strict;
use warnings;

use CGI qw/:standard/;

$ENV{PATH} = "/usr/bin:/bin";

my $doc = param 'docname';
my $pod = `perldoc $doc`;
print $pod;

__END__

I get

~% ./cgitaint docname=open
Insecure dependency in `` while running with -T switch at ./cgitaint
line 11.

as expected. If I add

$doc =~ /^([\w:]+)$/ ? $doc = $1 : die "Invalid perldoc name";

in the obvious place I get instead the docs for open.pm.

> Is that correct that Perl will not pick up a taint problem in this
> case?

No, it is not correct... do you have an example where this happens?

Ben

-- 
Musica Dei donum optimi, trahit homines, trahit deos.    |
Musica truces molit animos, tristesque mentes erigit.    |   ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras.        |


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

Date: Mon, 08 Nov 2004 02:15:46 +0800
From: Benjamin Khoo <benkhoo@copperblue.per.sg>
Subject: Re: Binary files in PERL?
Message-Id: <pan.2004.11.07.18.15.46.97063@copperblue.per.sg>

On Sun, 07 Nov 2004 05:58:41 +0000, Jürgen Exner wrote:

> Benjamin Khoo wrote:
>> i would like to find out how to write a binary file in PERL
>>
>> most of the readme and tutorial online only deal with writing ASCII
>> files.
> 
> Are you really on an OS that differentiates between binary and text
> files? Then you may want to check
>     perldoc -q binary: "How do I handle binary data correctly?" perldoc
>     -f binmode
> 
> jue

Hi jue

thanks much for your reply..
i took a look at the documentation,
does it mean that all i have to do is

open(FILE,">file.bin");
binmode (FILE);

?

and then use a print FILE "text\n";
to write into my file?

would reading it be jsut the reverse?

your advice is highly appreciated

-- 
bENJAMIN kHOO
qIU wENDA
http://www.copperblue.per.sg



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

Date: Sun, 7 Nov 2004 16:08:19 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Binary files in PERL?
Message-Id: <jst162-ee4.ln1@osiris.mauzo.dyndns.org>


Quoth "Jürgen Exner" <jurgenex@hotmail.com>:
> Benjamin Khoo wrote:
> > i would like to find out how to write a binary file in PERL
> >
> > most of the readme and tutorial online only deal with writing ASCII
> > files.
> 
> Are you really on an OS that differentiates between binary and text files? 

As of 5.8 Perl makes that difference regardless of OS. However, on some
OSen it defaults to binary and on some to a sort-of mixed text and
binary mode that is almost certainly completely useless... :)

Ben

-- 
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based 
on the strictest morality.  [Samuel Butler, paraphrased]       ben@morrow.me.uk


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

Date: Sun, 07 Nov 2004 17:24:21 +0000
From: Henry Law <lawshouse.public@btconnect.com>
Subject: Re: casting question
Message-Id: <q1mso0dicifnlctl3rg5aca2torp3up69m@4ax.com>

On Sat, 6 Nov 2004 14:55:10 -0500, "daniel kaplan" <nospam@nospam.com>
wrote:

>these are the only two line that matter, to post 2 pages of code is a waste,
>especially since the code works, i have to go and change passwords and
>URLs...

You have missed the point.  The point is that you create a *new*
*short* program that contains just the things you're having trouble
with; a program that can be copied-and-pasted and run by anyone who's
trying to help you.  Nobody said you should post two pages and include
passwords (you're hard-coding passwords, hmmm....). Get it down to ten
lines or less (and don't forget strict and warnings!!), make it
compile and fail in the way the big program does, then post it.

OK so you have to do some more work to create the little test program.
Well firstly that work will enable someone else to help you; and
secondly the very process of creating it will often -- more often than
not in my experience -- fix your problem.

Daniel, I have watched you thrashing about here over the last few
weeks: trying to force other people to help you; trying to pollute
their deduction by telling them where your problem is and refusing to
contemplate anything else; calling people names and refusing to fit in
with the way the group works.   Believe me, you're wasting your time.
Do not try to teach a pig to sing: it doesn't work, and it annoys the
pig.

Many of the people in here are intolerant and touchy; maybe you're
not.  But they are knowledgeable and you and I are not, and you want
what they have and not the other way around.  Want to get help with
your problems?  Play nice.  Have some sense, man.

Henry Law       <><     Manchester, England 


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

Date: Sun, 07 Nov 2004 17:49:48 +0000
From: Stuart Moore <usenet_05_08_2004@stuartmoore.org.uk>
Subject: Re: casting question
Message-Id: <cmln7o$m3u$1@gemini.csx.cam.ac.uk>

daniel kaplan wrote:

> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
> news:Xns9599A35C16407asu1cornelledu@132.236.56.8...
> 
> 
>>>it's declarted, otherwie the error would be a little more obvious...i
>>>do all my declares at the top of a subroutine (habit)
>>
>>Bad habit.
> 
> 
> may i, in all seriousness,  ask why?  to me it just seems to make for neater
> code..

If you declare a variable using my, it disappears when it goes out of 
scope (which usually means out of the innermost { } pair when it's 
created). Thus you use less memory, as the memory can be reused later 
e.g. if you end up using several different loop variables.

It also helps prevent other bugs, for example if you had a left over 
value in a temp variable from earlier in the sub which you'd forgotten 
about and somehow made things behave differently from how you expected.

Re your original question (which now seems to have been solved) - in 
general as long as you try to read the relevant parts of the 
documentation (i.e. whatever module(s) you're trying to use at the time) 
people here don't mind clarifying stuff. But if you're relying on stuff 
that's not in the documentation (e.g. poking around, finding 'foo' is an 
arrayref that's probably the one you want) may well lead to code that 
won't work if the module design changes for some reason. There's no 
reason for module writers to keep the internals the same, however 
they'll (almost certainly) keep the public interface the same. So you're 
(more or less) guaranteed the $IMobj->body() method will always work, 
but $IMobj->{mail_inet_body} may not one day for some reason.


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

Date: Sun, 7 Nov 2004 13:19:58 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: casting question
Message-Id: <1099851661.867007@nntp.acecape.com>

"Stuart Moore" <usenet_05_08_2004@stuartmoore.org.uk> wrote in message
news:cmln7o$m3u$1@gemini.csx.cam.ac.uk...

i said i would stop reading this thread so it would die (i.e. no tit for tat
replies) but decided to read this one post for whatever reason....so perhaps
you'll allow to pick your brain for some clarification?

> If you declare a variable using my, it disappears when it goes out of
> scope (which usually means out of the innermost { } pair when it's
> created). Thus you use less memory, as the memory can be reused later
> e.g. if you end up using several different loop variables.

what i mean is that i am doing the MY's at the top of the subroutine, like
this:

sub QuikRoutine
{
    my $each_line;
    ...
    ...
    foreach $each_line
    ...
    ...
}

rather than:

sub QuikRoutine
{
    ...
    ...
    foreach my $each_line
    ...
    ...
}

now if a "my" declared at the topic of a routine is like "static" in C, then
i am way wrong, but i undestood it's not.so, in the end, as far as i
understand the reading, as soon as i leave the subroutine the memory for
$each_line is freed.  if both are the same, is there another "functionality"
reason not to do it my way?  for me it's a preference thing.   but please,
if a = b, let me know.  if it is a matter of a = a, i'll keep doing it my
way...oh one another reason i ended up liking it my way, is that when
debuggng, the moment i left the very line using the "my" in the code itself,
the debugger seemed to lose the old variable, with the new one ready....

and also, this is sort of OT, since a "my" translates to discarding the old,
and making new, wouldn't this just be more processing time when you right it
as      "foreach my $each_line", than the other?

>So you're  (more or less) guaranteed the $IMobj->body() method will always
work,
> but $IMobj->{mail_inet_body} may not one day for some reason.

this was the "doh!" realization i had yesterday and thanks anyway





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

Date: Sun, 07 Nov 2004 19:23:24 +0000
From: Stuart Moore <usenet_05_08_2004@stuartmoore.org.uk>
Subject: Re: casting question
Message-Id: <cmlsn8$3ie$1@gemini.csx.cam.ac.uk>

daniel kaplan wrote:

> 
> what i mean is that i am doing the MY's at the top of the subroutine, like
> this:
> 
> sub QuikRoutine
> {
>     my $each_line;
>     ...
>     ...
>     foreach $each_line
>     ...
>     ...
> }
> 
> rather than:
> 
> sub QuikRoutine
> {
>     ...
>     ...
>     foreach my $each_line
>     ...
>     ...
> }

My apologies, I should've made this clear. In the second construction, 
the "$each_line" variable ceases to exist after the end of the foreach 
block. This makes sense if you think about it, since you don't (in most 
cases) need the variable after the end of the loop.

If for some reason you wanted to keep the last value from the loop (e.g. 
you're jumping out of the loop on a certain condition) then your way 
would make sense. Otherwise you're holding $each_line around until the 
end of the sub when you probably don't need to.

> and also, this is sort of OT, since a "my" translates to discarding the old,
> and making new, wouldn't this just be more processing time when you right it
> as      "foreach my $each_line", than the other?

I suppose it might (although I don't know enough about inner workings of 
Perl to comment) but if you're that concerned about processing time 
you're using the wrong language. I can't imagine it being significant, 
it may be that the optimiser is clever enough to reuse the same location 
each time.


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

Date: Sun, 7 Nov 2004 15:49:15 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: casting question
Message-Id: <1099860620.808950@nntp.acecape.com>

"Stuart Moore" <usenet_05_08_2004@stuartmoore.org.uk> wrote in message
news:cmlsn8$3ie$1@gemini.csx.cam.ac.uk...

 ...snipped....

thanks




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

Date: Sun, 07 Nov 2004 21:29:58 GMT
From: LaDainian Tomlinson <go@away.spam.invalid>
Subject: Re: casting question
Message-Id: <6td262-skj.ln1@news.bclennox.com>

On 2004-11-07, 'daniel kaplan' <nospam@nospam.com> wrote in
comp.lang.perl.misc:

<Daniel's examples>
sub x {
  my $foo;
  for $foo ( ... ){}
}

sub y {
  for my $foo ( ... ){}
}
</examples>

> now if a "my" declared at the topic of a routine is like
> "static" in C, then i am way wrong, but i undestood it's
> not.so, in the end, as far as i understand the reading, as soon
> as i leave the subroutine the memory for $each_line is freed.
> if both are the same, is there another "functionality" reason
> not to do it my way?

It's not easy to see with the foreach block, but in the second
example above, $foo is scoped _inside_ the foreach, not outside.
As soon as the foreach block ends, $foo is out of scope.  "my" is
definitely not "static"-for-Perl, at least as per my
understanding of "static" for C.

<snip>

> and also, this is sort of OT, since a "my" translates to
> discarding the old, and making new, wouldn't this just be more
> processing time when you right it as "foreach my $each_line",
> than the other?

I'm not sure what you mean here.  "my" generally doesn't discard
anything, even if you declare a variable in one block which
shadows a variable with the same name in an enclosing block.  As
soon as you exit the inner block, the old variable is back in
scope, untouched (assuming you didn't touch it).  In a for loop,
every iteration writes a new value to the loop variable (which
you must know).  It doesn't have anything to do with the scoping
of the variable.  Are you thinking that $each_line goes out of
scope each time through the loop, and that it must be reallocated?

>> So you're (more or less) guaranteed the $IMobj->body() method
>> will always work, but $IMobj->{mail_inet_body} may not one day
>> for some reason.
> 
> this was the "doh!" realization i had yesterday and thanks
> anyway

No offense to the Perl gurus here, but Perl is not the easiest
language for learning OOP.  You might consider Java (or C++,
coming from a C background) for learning OOP and Perl for
learning scripting.  And Java programmers get paid better :-)

Brandan L.
-- 
bclennox \at eos \dot ncsu \dot edu


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

Date: Sat, 06 Nov 2004 23:15:26 -0500
From: "Shmuel (Seymour J.) Metz" <spamtrap@library.lspace.org.invalid>
Subject: Re: Common file operations
Message-Id: <418da15e$1$fuzhry+tra$mr2ice@news.patriot.net>

In <70keo011k00rvdigeim4mculkp9aab2j1u@4ax.com>, on 11/02/2004
   at 10:57 AM, Michele Dondi <bik.mido@tiscalinet.it> said:

>Not that I despise join(), but IMHO it would be more terse having it
>take place under the curtain, a la (e.g.)
>  {
>      local $,=',';
>      print "@ARGV\n";
>  }

But would it be as clear?

>Huh?!? Are you running Perl6?

You're right; I need parentheses around the comparisons.

>Is there any good reason you are mixing print() and die()
>statements? Are you aware you will be printing to two different
>fd's?

You're right; I need to use a single die().

>Also, the last line has an error: join() wants comma separated args,
>but in that case you must also add parenthesis to avoid the last
>"\n" being considered as another argument to join().

Yes.

>Moreover, out of curiosity: why "  \n" instead of "\n"?

Typo. I meant

 elsif (@dirs>1) {
    die   "$dir matches multiple directory names:\n",
        '  ', join("\n  ",@dirs),"\n";

Which indents for readability.

>All in all I'd rewrite the whole fragment as:
>  @dirs or die "`$dir' doesn't match any directory name\n";
>  die "`$dir' matches multiple directory names:\n",
>    map "$_\n", @dirs if @dirs>1;

What is the reason for mixing styles here, as opposed to putting the
tests on the same ends?

   @dirs or die "`$dir' doesn't match any directory name\n";
   @dirs>1 or die "`$dir' matches multiple directory names:\n",
                  map " $_\n", @dirs if @dirs>1;

>No, I suggested you to search 'WARNING' in perldoc perlre. 

That's how I got the text I quoted, in

    =head1 DESCRIPTION
    =head2 Warning on \1 vs $1

It seemed more relevant than the text in 

    =head1 DESCRIPTION
    =head2 Regular Expressions

since I wasn't using $&, $' or  $`.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



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

Date: Sun, 07 Nov 2004 17:15:12 +0000
From: Stuart Moore <usenet_05_08_2004@stuartmoore.org.uk>
Subject: Re: Converting multiple spaces for 3 col text?
Message-Id: <cmll6s$i7n$1@gemini.csx.cam.ac.uk>

JCunington wrote:

> I'm looking for a substitution phrase to convert only multiple spaces to an
> HTML <TD></TD> tag. I'm scanning magazines in my model railroad collection to
> convert them to web pages and want to keep the text as close to its original
> format as possible. My 2 books are a little sketchy on substitution strings.

If those are Perl books, I'm worried.

 From what you've said, your text will come out something like:

One column going             on the right hand
down the left                side of the page with
hand side of the             multiple spaces in between
page and then                them
the text continuing

(or similar with multiple columns)

If you want exactly the same layout as the original, then

s#\n#</td></tr><tr><td>#g;
s#\s{2,}#</td><td>#g;

might be what you want, but it does depend on the OCR software getting 
the number of spaces right.

If I were you I'd play around with the OCR software first, see how it 
outputs columns and if you can persuade it to do continuous text, then 
tableise them yourself.


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

Date: Sun, 7 Nov 2004 17:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 4.75: How do I verify a credit card checksum?
Message-Id: <cmlkg5$28e$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

4.75: How do I verify a credit card checksum?

    Get the Business::CreditCard module from CPAN.



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Sun, 7 Nov 2004 23:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 8.32: How can I write expect in Perl?
Message-Id: <cmm9j5$8vq$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

8.32: How can I write expect in Perl?

    Once upon a time, there was a library called chat2.pl (part of the
    standard perl distribution), which never really got finished. If you
    find it somewhere, *don't use it*. These days, your best bet is to look
    at the Expect module available from CPAN, which also requires two other
    modules from CPAN, IO::Pty and IO::Stty.



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Sun, 07 Nov 2004 20:42:54 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: map()'s BLOCK
Message-Id: <fo6so0l0mctsd4u87l4am8t62pbn8hgm2b@4ax.com>

On Sun, 07 Nov 2004 04:35:09 GMT, Uri Guttman <uri@stemsystems.com>
wrote:

>  MD> On Wed, 03 Nov 2004 00:23:13 +0100, Michele Dondi
>  MD> <bik.mido@tiscalinet.it> wrote:
[snip]
>  MD> Of course I can do
>
>  MD>   {
>  MD>       no strict 'refs';
>  MD>       cmpthese 500, { map { $_ => \&{$_} } 
>  MD>   	qw/sol1 sol2 etc/ };
>  MD>   }
>
>or use a do{} block inside the map block. that should handle any stuff
>you want to put in there.

Dear Uri,


On Fri, 05 Nov 2004 00:11:27 +0100, Michele Dondi (i.e. *I*)
<bik.mido@tiscalinet.it> wrote:

>Of course I can do
>
>  {
>      no strict 'refs';
>      cmpthese 500, { map { $_ => \&{$_} } 
>  	qw/sol1 sol2 etc/ };
>  }
>
>instead, but IMHO the no-strict-'refs'-ization logically best applies
>to the map()'s code block. Now I know that there are easy workarounds,
>e.g. using the "EXPR-form" of map() with a do(); still I wonder why
                                            ^^^^
                                            ^^^^
>the block of the "BLOCK-form" of map() doesn't behave like a "normal"
>block.


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: 7 Nov 2004 09:50:36 -0800
From: tam3x3@yahoo.com (Tom McDonough)
Subject: Problem with cp in system call running Mac OS X
Message-Id: <fac56ba1.0411070950.5799e603@posting.google.com>

I'm writing a back up script and want to put all files in directory
(MRIS) which are not a directory in their own right into a temporary
directory (TEMP).

I'm operating in Mac OS X 10.2.8 with the perl 5.6 that came with the
distro and the cp is  4th Berkeley Distribution       April 18, 1994

From the shell my cp is working as I expect but when I use cp in a
perl script in a system call I get odd - to my mind - results.

When the script is run from the parent directory, this:

$copy = `cp mris/$thisone mris/temp/$thisone`;   

Elicits this:
usage: cp [-R [-H | -L | -P]] [-f | -i] [-p] src target
       cp [-R [-H | -L | -P]] [-f | -i] [-p] src1 ... srcN directory
sh: mris/temp/test.pl: No such file or directory

And this:

$copy = `cp mris/$thisone mris/temp`; 

Results in this:
usage: cp [-R [-H | -L | -P]] [-f | -i] [-p] src target
       cp [-R [-H | -L | -P]] [-f | -i] [-p] src1 ... srcN directory
sh: mris/temp: is a directory

When I go down to the mris directory and run the script, this

$copy = `cp $thisone temp`;

Results in this:
usage: cp [-R [-H | -L | -P]] [-f | -i] [-p] src target
       cp [-R [-H | -L | -P]] [-f | -i] [-p] src1 ... srcN directory
sh: temp: command not found

BTW: cd doesn't seem to work in a system call either.  Script is
copied below.

Stymied in Stanton
*******************
#!/usr/bin/perl

# this script is located in mris  
      
@ls = `ls -l`;
foreach $file (@ls) {
   if ($file =~ /^d/) {
      @file = split / /, $file;
      $thisone = pop @file;
      print "$thisone";
   }
   else {
      @file = split / /, $file;
      if (!($file =~ 'total')) {
         $thisone = pop @file;
         $copy = `cp $thisone temp/$thisone`;
      }  
   }   
}


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

Date: Sun, 07 Nov 2004 13:13:14 -0500
From: Todd de Gruyl <todd@tdegruyl.com>
Subject: Re: Problem with cp in system call running Mac OS X
Message-Id: <i7OdnWUzpesn-BPcRVn-vw@comcast.com>

On 11/7/04 12:50, Tom McDonough wrote:
> #!/usr/bin/perl

use warnings;
use strict;

(and fix the warnings that shows - have a look at the posting guidelines 
that are posted here regularly)

> # this script is located in mris  
>       
> @ls = `ls -l`;
> foreach $file (@ls) {
>    if ($file =~ /^d/) {
>       @file = split / /, $file;
>       $thisone = pop @file;
>       print "$thisone";
>    }
>    else {
>       @file = split / /, $file;
>       if (!($file =~ 'total')) {
>          $thisone = pop @file;

$thisone includes the final \n of the original input, try adding:

chomp $thisone;

>          $copy = `cp $thisone temp/$thisone`;
>       }  
>    }   
> }

You also might want to check out readdir and opendir (e.g. perldoc -f 
readdir...), that might make the code you are looking at easier to read 
(of course, the ls command isn't all that hard to deal with, YMMV)

HTH
-- 
Todd de Gruyl
todd@tdegruyl.com


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

Date: Mon, 8 Nov 2004 07:42:01 +1300
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Problem with cp in system call running Mac OS X
Message-Id: <2v78haF2g452fU1@uni-berlin.de>


"Tom McDonough" <tam3x3@yahoo.com> wrote in message 
news:fac56ba1.0411070950.5799e603@posting.google.com...
> *******************
> #!/usr/bin/perl
>
> # this script is located in mris
>
> @ls = `ls -l`;
> foreach $file (@ls) {
>   if ($file =~ /^d/) {
>      @file = split / /, $file;
>      $thisone = pop @file;
>      print "$thisone";
>   }
>   else {
>      @file = split / /, $file;
>      if (!($file =~ 'total')) {
>         $thisone = pop @file;
>         $copy = `cp $thisone temp/$thisone`;
>      }
>   }
> }


Ugg!  Either write a shell script or a Perl script.

Here's a Perl version.

#!/usr/bin/perl
use strict;
use File::Copy;

foreach my $file (<*>) {
   next unless -f $file;
   copy $file ,"temp/$file" or warn "Can not copy $file $!\n";
}




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

Date: Sun, 7 Nov 2004 16:14:02 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Simplifying by refactoring 'array ref' and glob from 'map'
Message-Id: <a7u162-ee4.ln1@osiris.mauzo.dyndns.org>


Quoth Matija Papec <perl@my-header.org>:
> 
> local ($/,*F);
> return map { 
>   $_ => do { open F, $_ or die "Error reading '$_': $!"; <F> }
> } @array;
> 
> You can pull this "local ($/,*F);" out of the map,

Or, much better in general, use lexical FHs:

local $/;
return map {
    $_ => do { 
        open my $F, '<', $_ or die "error reading '$_': $!"; 
        <$F>;
    }
} @array;

, or, better in this case, use File::Slurp:

use File::Slurp qw/read_file/;

return map { $_ => scalar read_file $_  } @array;

Ben

-- 
               We do not stop playing because we grow old; 
                  we grow old because we stop playing.
                            ben@morrow.me.uk


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

Date: 7 Nov 2004 11:31:37 -0800
From: jl_post@hotmail.com (J. Romano)
Subject: Re: The most perfect beginning
Message-Id: <b893f5d4.0411071131.1e040872@posting.google.com>

ioneabu@yahoo.com (wana) wrote in message news:<bf0b47ca.0411030827.68ff80de@posting.google.com>...
 
> I was wondering what people think is the most perfect general
> beginning to a Perl program that could be used in most or all
> programs.  This would include whatever flags, pragmas and modules
> might be useful and important.


   I don't do this very often on my own scripts, but when I end up
having to maintain a script that someone else wrote, I sometimes add
the line:

      use Fatal qw(:void open opendir chdir rename);

near the top of the script.

   This line will terminate the program with a useful error message if
any of the commands mentions (that is, open(), opendir(), chdir(), or
rename()) fail and the return value is not handled.  The ":void"
keyword prevents the script from exiting as long as the return value
is handled, such as:

      open(FILE, ">/blah.txt")  or die "Cannot write to blah.txt: $!";

   Any decent Perl programmer should ALWAYS check the return values of
these functions.  I can't stress this enough.  I have seen several
times where a programmer thinks that some Perl code like:

      open(OUT, "> path/data.txt");
      my ($key, $value);
      while (($key, $value) = each %hash)
      {
         print OUT "$key:$value\n";
      }

"won't work" because the each() function doesn't work the way I told
him it would.  In reality, it is because the open() function failed.

   I look at the other programmer's code and say, "You should ALWAYS
check the return value of an open() statement."  The other programmer
will counter, saying something like:  "There is NO reason for it not
to work."

   Nevertheless, I force him add "or die "Cannot write to data.txt:
$!" and then, when we re-run the script, we find that the open()
command failed (due to an incorrect path or possibly for some other
reason that we didn't think of before).

   Unfortunately, this "there is NO reason for it not to work"
attitude that too many programmers have make them think that the bug
lies in another part of the program, like in the call to each().  As a
result, I'm often told that another part of the Perl script won't work
they way I explained it would simply because the other programmer
never even stops to consider that their call to open(), opendir(),
chdir(), or rename() could ever fail.

   And because some programmers STILL won't check the return value, it
is a pain to inherit and maintain their code.  That is why I will
sometimes add the line:

      use Fatal qw(:void open opendir chdir rename);

near the top of a script, especially if the script is so long that it
is difficult to change every call to the listed functions.  If they do
check all the return values of the listed functions (as every
programmer should), then including the Fatal module should have no
effect.  But if they don't (which happens all too often,
unfortunately), this line will catch their errors (and report a useful
error message) despite the fact that they don't.

   You may even consider putting this line in the scripts you write
yourself, just in case you ever forget to handle the return value. 
Hopefully this would never happen, but mistakes do happen
occasionally.

   I hope this helps, wana.

   -- Jean-Luc


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

Date: Sun, 7 Nov 2004 14:41:54 -0800
From: "Sean Berry" <sean@buildingonline.com>
Subject: Upload meter for a CGI perl script
Message-Id: <bwxjd.120416$hj.27962@fed1read07>

I was toying with the idea of making an upload progress meter for a perl 
script I have that usually takes somewhere in the neigborhood of 20M files. 
I figured I could have a popup that takes as an argument the four digit 
sequence number CGI.pm creates when uploading a file, then check the file 
size and report it.  Then, this window could update periodically, say every 
2 seconds.

But, how can I get access to the $sequence variable used in creating files 
in the tmp dir like /tmp/CGItemp3323 ????

I don't want to go screwing around with CGI.pm, but see no other way of 
getting this number.

Any help here is appreciated.





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

Date: Sun, 07 Nov 2004 22:47:02 +0000
From: Stuart Moore <usenet_05_08_2004@stuartmoore.org.uk>
Subject: Re: Upload meter for a CGI perl script
Message-Id: <cmm8l1$n2a$1@gemini.csx.cam.ac.uk>

Sean Berry wrote:
> I was toying with the idea of making an upload progress meter for a perl 
> script I have that usually takes somewhere in the neigborhood of 20M files. 
> I figured I could have a popup that takes as an argument the four digit 
> sequence number CGI.pm creates when uploading a file, then check the file 
> size and report it.  Then, this window could update periodically, say every 
> 2 seconds.
> 
> But, how can I get access to the $sequence variable used in creating files 
> in the tmp dir like /tmp/CGItemp3323 ????
> 
> I don't want to go screwing around with CGI.pm, but see no other way of 
> getting this number.
> 
> Any help here is appreciated.
> 

I am not an expert, but I was under the impression that the webserver 
(apache or whatever) waits until the transfer has been completed before 
then running the CGI script. A way to test this would be to be to record 
when the script was started.


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

Date: 7 Nov 2004 13:38:47 -0800
From: torahul@gmail.com
Subject: Using $SIG{"ALRM"}  assignment inside a subroutine ...
Message-Id: <e713d286.0411071338.6fc628f4@posting.google.com>

Hi,

Wondering what's happening here -- is it a bug or an expected behavior
from perl ? I am trying to set SIGALRM handle from within a
subroutine; surprisingly it executes the handler rotine soon I assign
to SIG{"ALRM"}, even I haven't set any alarm! If I move SIG{"ALRM"}
assignment outside the subroutine, it's working as I would expect.

Following perl code :
----------------- Start of Script -----------------
#!/usr/local/bin/perl

$pid = 0;

sub s_alarm_handler {
       print ("$$ : *** KILLING process(pid=$pid) after timeout\n");
       kill ("KILL", $pid);
}

sub s_sub1 {
   local (@args) = @_;

   print ("Setting alarm routine to s_alarm_handler\n");
   $SIG{"ALRM"} = s_alarm_handler;
   print ("Alarm routine set to s_alarm_handler\n");
}

&s_sub1 ("something");
--------------- End of Script ---------------

Running above script generates this output :
---------- Output ---------
Setting alarm routine to s_alarm_handler
18411 : *** KILLING process(pid=0) after timeout
Killed
------ End of Output ------

$ /usr/local/bin/perl -v
This is perl, version 5.004_04 built for sun4-solaris
Copyright 1987-1997, Larry Wall


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

Date: Sun, 7 Nov 2004 15:41:36 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Win32::OLE msxml collection problem
Message-Id: <gas162-ee4.ln1@osiris.mauzo.dyndns.org>


Quoth Simon Taylor <simon@unisolve.com.au>:
> Ben Morrow wrote:
> > Quoth Simon Taylor <simon@unisolve.com.au>:
> >> 
> >>Quite right, unless of course one dereferences the method call
> >>and then creates a scalar reference to that with the ${ } construct,
> > 
> > You've got \ and ${} the wrong way round... :)
> 
> No, it's quite correct, run it and see...

I wasn't talking about your code, but your prose. You said 'deref the
method call and then create a scalar ref with ${}'; what you meant was
'create a scalar ref to (the result of) the method call (with \), and
then deref that with ${}'.

:)

Ben

-- 
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
     -Assyrian stone tablet, c.2800 BC                         ben@morrow.me.uk


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

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 V10 Issue 7374
***************************************


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