[28429] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9793 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 3 00:05:59 2006

Date: Mon, 2 Oct 2006 21:05:09 -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           Mon, 2 Oct 2006     Volume: 10 Number: 9793

Today's topics:
    Re: How to delete temporary file after displaying in br <ynl@nsparks.net>
    Re: How to delete temporary file after displaying in br <ynl@nsparks.net>
    Re: Modifying a one-liner <1usa@llenroc.ude.invalid>
    Re: Modifying a one-liner <tadmc@augustmail.com>
    Re: newbie syntax question -> and => <dha@panix.com>
    Re: OS X and perldoc <dha@panix.com>
    Re: Perl Async .10 <DJStunks@gmail.com>
    Re: Perl Async .10 <sisyphus1@nomail.afraid.org>
        perl flawed or my fault <betterdie@gmail.com>
    Re: perl flawed or my fault yankeeinexile@gmail.com
    Re: perl flawed or my fault <DJStunks@gmail.com>
    Re: perl flawed or my fault <someone@example.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 3 Oct 2006 04:45:44 +0200
From: Yohan N Leder <ynl@nsparks.net>
Subject: Re: How to delete temporary file after displaying in browser ?
Message-Id: <MPG.1f8bed42ee3791099898d7@news.tiscali.fr>

In article <1159804489.823095.242200@m73g2000cwd.googlegroups.com>, 
bart@nijlen.com says...
> Normally you can just use unlink without need for extra precautions
> here. The CGI has sent everything before the unlink-command is invoked,
> that is, unlink will "wait" until the output stream is closed.
> 

Sure ? So, you say something like this is enough without any more 
precaution ?

#!/usr/bin/perl
use CGI::Carp qw/fatalsToBrowser/;
use strict;
use warnings;
$|=1;
print "Content-type: text/html; charset=iso-8859-1\n\n";
my $imgpath = "../httpdocs/upload/tmp.gif";
my $imgurl = "/upload/tmp.gif";
my $imghtm = "<img src='".$imgurl."' border=0 width=150 height=150>";
print "<html><head></head><body>".$imghtm."</body></html>";
unlink $imgpath;
exit 0;

Knowing, of course, that tmp.gif has been correctly uploaded previously 
and exists on server now.


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

Date: Tue, 3 Oct 2006 04:48:47 +0200
From: Yohan N Leder <ynl@nsparks.net>
Subject: Re: How to delete temporary file after displaying in browser ?
Message-Id: <MPG.1f8bedf7ab0c4a159898d8@news.tiscali.fr>

In article <4sg2i2l95iv3plmb1hb4e38ejpka228ece@4ax.com>, 
bik.mido@tiscalinet.it says...
> I'm not really sure if I understand. It seems that you create a
> temporary but *static* file to be served directly by the browser. Why
> don't you serve it dinamically instead?
> 

The file I have to display, then delete has been previously uploaded 
from client to server. After this upload stage (done), I have to do 
something like this (shorten at its maximum) :

#!/usr/bin/perl
use CGI::Carp qw/fatalsToBrowser/;
use strict;
use warnings;
$|=1;
print "Content-type: text/html; charset=iso-8859-1\n\n";
my $imgpath = "../httpdocs/upload/tmp.gif";
my $imgurl = "/upload/tmp.gif";
my $imghtm = "<img src='".$imgurl."' border=0 width=150 height=150>";
print "<html><head></head><body>".$imghtm."</body></html>";
#... now I need to unlink this $imgpath ...
exit 0;

So, how to achive the commented step ? Can I just unlink after printing 
?


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

Date: Tue, 03 Oct 2006 02:27:33 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Modifying a one-liner
Message-Id: <Xns9850E4778827Dasu1cornelledu@24.24.2.166>

Tad McClellan <tadmc@augustmail.com> wrote in 
news:slrnehvior.jkv.tadmc@magna.augustmail.com:

> Paul Lalli <mritty@gmail.com> wrote:
>> vjp2.at@at.BioStrategist.dot.dot.com wrote:
>>> Mind if I piggyback a request here?
>> 
>> Yes.  I do.  There is no reason to post this message in an existing
>> thread.  Start a new topic.
> 
> 
> That reply was pretty unAmerican of you!
> 
>    Message-ID: <cnn76h$551$1@reader1.panix.com>

Tad, I am continually impressed with your post classification and instant 
recall system (PCIRS) (Can't think of a better name right now ;-)

Thank you for the entertainment.

Sinan


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

Date: Mon, 2 Oct 2006 22:47:18 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Modifying a one-liner
Message-Id: <slrnei3na6.s2v.tadmc@magna.augustmail.com>

A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
> Tad McClellan <tadmc@augustmail.com> wrote in 
> news:slrnehvior.jkv.tadmc@magna.augustmail.com:
> 
>> Paul Lalli <mritty@gmail.com> wrote:
>>> vjp2.at@at.BioStrategist.dot.dot.com wrote:
>>>> Mind if I piggyback a request here?
>>> 
>>> Yes.  I do.  There is no reason to post this message in an existing
>>> thread.  Start a new topic.
>> 
>> 
>> That reply was pretty unAmerican of you!
>> 
>>    Message-ID: <cnn76h$551$1@reader1.panix.com>
> 
> Tad, I am continually impressed with your post classification and instant 
> recall system (PCIRS) (Can't think of a better name right now ;-)


I just call it "a directory of posts that have earned a negative 
scorefile entry".

   [tadmc]$ ls News/killed/ | wc -l
      775

Yikes!  (and that's only 6 years worth of accumulation, I didn't
         record them for about my first 6 years here.)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 3 Oct 2006 03:20:00 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: newbie syntax question -> and =>
Message-Id: <slrnei3ln1.daj.dha@panix2.panix.com>

On 2006-10-02, David Squire <David.Squire@no.spam.from.here.au> wrote:
> Keith Keller wrote:
>> On 2006-10-02, usenet@DavidFilmer.com <usenet@DavidFilmer.com> wrote:
>>> In the example you gave, "=>" is really like a comma in an array
>>> definition (it's called a 'fat comma').
>> 
>> I've never heard that term, 'fat comma'.  Does anybody know its origin?
>> A quick google search didn't turn up much, nor did perldoc perlop.
>
> It's in Damian Conway's "Perl Best Practices", for one.

But it certainly predates that. Unfortunately, that's about as helpful
as I can be at the moment. :-/

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
I'd redesign my program to something less absurd.
    - Abigail, in comp.lang.perl.misc


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

Date: Tue, 3 Oct 2006 03:26:08 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: OS X and perldoc
Message-Id: <slrnei3m2g.daj.dha@panix2.panix.com>

On 2006-10-02, Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:

> If for some reason your Perl distribution is incomplete or you want to
> have the absolute latest (Mac OS X currently comes with 5.8.6, whereas
> 5.8.8 and 5.9.4 are out), go to <http::www.cpan.org> and download the
> latest source distribution. If you have installed the Mac OS X
> optional developer tools (XCode) that came with your OS distribution
> (or downloaded the latest from <http://www.apple.com/developer>), then
> you should be able to build and install a complete Perl distribution.
> The developer tools include a version of gcc for the Mac. There is a
> README.macosx file in the Perl distribution with some information
> about Mac-flavored Perl.

There is one LARGE caveat about that on OS X. Do NOT install your perl
over the one that comes with OS X. Apple tends to assume that the perl
the system came with is the one it's using for various things, and
changing that can cause subtle (and not so subtle) problems that can be
very annoying.

Fortunately, IIRC, the default for a perl built from source is to
install it into /usr/local/bin, rather than /usr/bin where Apple puts
theirs. Just make sure you're using /usr/local as your prefix and you
should be fine.

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"Last year in Oregon, Summer fell on a *tuesday*.  That was it.  One
day.  Big shiny thing in the sky.  Some people thought it was a UFO."
        - Randal Schwartz in comp.lang.perl.misc


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

Date: 2 Oct 2006 18:37:25 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Perl Async .10
Message-Id: <1159839445.792163.14480@e3g2000cwe.googlegroups.com>

Todd English wrote:
> Todd  English wrote:
> > It was suggested that my initial post was too verbose for the Perl
> > newsgroups. I have rewritten my original example and have posted it
> > bellow.
> >
> > The expected output would be 20 lines printed to the console saying the
> > following:
> > <some number>      I have returned
> > What happens instead is that some of lines fail to print the "I have
> > returned" part of the message.
> >
> > Sorry for the initial verbose posting.

You don't have to be sorry, I only suggested that this could be the
reason you weren't getting any responses.

Also, I should mention that you'll wear out your welcome pretty quickly
if you don't post according to accepted norms - that is:  don't top
post.  instead snip appropriate remarks and relevant content and write
your responses below this information.  that way someone can read from
top to bottom and understand what you're talking about.

Anyway, on to Perl.

> Sample fot using the "force" option in the Async module.
>
> -----------sample code--------------
> #!/usr/bin/perl -w
>
> use strict;
> use Async;
>
> sub long_running_computation {
>      system qq{find ./ -type f 2>&1 >/dev/null};
>      return "I have returned";
>   }
>
> my %proc_result;
> my %build_result;
>
> for (my $counter=0; $counter < 10; $counter++)
> {
>     $proc_result{$counter} = Async->new( sub{
> long_running_computation() } );
> }
>
> while( 0 < scalar(keys %proc_result) )
> {
>     my @host_list_to_delete;
>     while( (my $name) = each %proc_result)
>     {
>         if($proc_result{$name}->ready)
>         {
>             my $error;
>             if($error = $proc_result{$name}->error)
>             {
>                 $build_result{$name} = "Async indicates a failure error
> occured: $error !";
>             }
>             else
>             {
>                 $build_result{$name} = $proc_result{$name}->result;
>             }
>             push(@host_list_to_delete, $name);
>         }
>     }
>
>     foreach my $item (@host_list_to_delete)
>     {
>         delete ( $proc_result{$item} );
>     }
>
>     sleep 10;
> }
>
>
> while (my($host_name, $result) = each %build_result)
> {
>     printf "%s\t%s\n", $host_name, $result;
> }
>

my hunch was that your problem occurred because you're deleting items
from the hash while iterating over it, but on second thought I'm not so
sure.

anyway, I changed up your script a bit (no more deleting) and it seems
to run ok for me.  give it a try.

-jp

  #!/usr/bin/perl

  use strict;
  use warnings;

  use Async;
  use List::MoreUtils qw{ any };

  my @hosts = (
  	{ architecture => 'rhel3-ia32',
  	  name         => 'gray',
  	},
  	{ architecture => 'rhel4-ia32',
  	  name         => 'x.x.x.x',
  	},
  	{ architecture => 'sles9-ia32',
  	  name         => 'y.y.y.y',
  	},
  	{ architecture => 'sles10-ia32',
  	  name         => 'maroon',
  	},
	{ architecture => 'rhel3-x64',
	  name         => 'white',
	},
  	{ architecture => 'sles9-ia64',
  	  name         => 'goldenrod',
  	},
  	{ architecture => 'rhel4-s390',
  	  name         => 'rh4as',
  	},
  	{ architecture => 'sles9-s390',
  	  name         => 'mambo',
  	},
  	{ architecture => 'sol10-x64',
  	  name         => 'brown',
  	},
	{ architecture => 'sol10-sparc',
	  name         => 'green',
	},
  );

  for my $hashref (@hosts) {
  	$hashref->{process} = Async->new(
  		sub { long_running_computation($hashref->{name}) }
  	);
  }

  sleep 10 while ( any { not $_->{process}->ready() } @hosts);

  print "\n";
  for my $hashref (@hosts) {
  	printf "Host %-10s ", "$hashref->{name}:";

  	if( my $error = $hashref->{process}->error() ) {
  		print "Failure: '$error'";
  	}
  	else {
  		print $hashref->{process}->result();
  	}

  	print "\n";
  }

  sub long_running_computation {
  	my ($host_name) = @_;

  	#print "Process for host $host_name spawned...\n";
  	sleep 10 + rand 35;
  	#print "Process for host $host_name returning...\n";
  	
  	return "$host_name result";
  }
  
  __END__



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

Date: Tue, 3 Oct 2006 11:35:15 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Perl Async .10
Message-Id: <4521bf63$0$17864$afc38c87@news.optusnet.com.au>


"Todd English" <toddenglish@gmail.com> wrote in message
 .
 .
>
> The expected output would be 20 lines printed to the console saying the
> following:
> <some number>      I have returned
> What happens instead is that some of lines fail to print the "I have
> returned" part of the message.
 .
 .
> ----------------sample code------------------
> #!/usr/bin/perl -w
>
> use strict;
> use Async;
>
> sub long_running_computation {
>      system qq{find ./ -type f 2>&1 >/dev/null};
>      return "I have returned";
>   }
>
> my %proc_result;
> my %build_result;
>
> for (my $counter=0; $counter < 20; $counter++)
> {
>     $proc_result{$counter} = Async->new( sub{
> long_running_computation() } );
> }
>
> while ( my ($name, $proc) = each %proc_result)
> {
>     $build_result{$name} = $proc->result('1');
> }
>
> while (my($host_name, $result) = each %build_result)
> {
>     printf "%s\t%s\n", $host_name, $result;
> }
>

Is the problem dependent upon that system() command, or do you get the same
problem even if you replace the system call with something else ?

I replaced the system call with sleep(2) as I didn't want to mess around
with system(). I get 20 lines of "<some number>    I have returned".

That's on Win32 (2000), perl 5.8.8, Async-0.10.

Cheers,
Rob








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

Date: 2 Oct 2006 19:59:52 -0700
From: "paul" <betterdie@gmail.com>
Subject: perl flawed or my fault
Message-Id: <1159844392.588911.96110@m73g2000cwd.googlegroups.com>

Hello all,

please help me the check the following code

use strict;

my $something = 'phal';
my $otherthing = 'paul';

my $note_whom = 'szmuzu\'mi';

defined($something) ? $note_whom = $something : $otherthing =
'singapore';

print "$note_whom \n $otherthing \n";

The result is: singapore
                   singapore

I don't know why the scalar $note_whom get the value that is assigned
to $otherthing.

Please give me the explaination, and thank you.



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

Date: 02 Oct 2006 22:05:23 -0500
From: yankeeinexile@gmail.com
Subject: Re: perl flawed or my fault
Message-Id: <878xjy14lo.fsf@gmail.com>

"paul" <betterdie@gmail.com> writes:

> Hello all,
> 
> please help me the check the following code
> 
> use strict;
> 
> my $something = 'phal';
> my $otherthing = 'paul';
> 
> my $note_whom = 'szmuzu\'mi';
> 
> defined($something) ? $note_whom = $something : $otherthing =
> 'singapore';
> 
> print "$note_whom \n $otherthing \n";
> 
> The result is: singapore
>                    singapore
> 

Really?  

lawrence@hummer - /tmp % cat clpm 
#!/usr/bin/perl
use strict;
use warnings;

my $something = 'phal';
my $otherthing = 'paul';

my $note_whom = 'szmuzu\'mi';

defined($something) ? $note_whom = $something : $otherthing =
'singapore';

print "$note_whom \n $otherthing \n";
lawrence@hummer - /tmp % perl clpm
singapore 
 paul 

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
	Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.


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

Date: 2 Oct 2006 20:27:11 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: perl flawed or my fault
Message-Id: <1159846031.081481.264120@e3g2000cwe.googlegroups.com>

paul wrote:
> Hello all,
>
> please help me the check the following code
>
> use strict;
>
> my $something = 'phal';
> my $otherthing = 'paul';
>
> my $note_whom = 'szmuzu\'mi';
>
> defined($something) ? $note_whom = $something : $otherthing =
> 'singapore';
>
> print "$note_whom \n $otherthing \n";
>
> The result is: singapore
>                    singapore
>
> I don't know why the scalar $note_whom get the value that is assigned
> to $otherthing.
>
> Please give me the explaination, and thank you.

note precendence...

  C:\tmp>perl -MO=Deparse,-p tmp.pl
  use warnings;
  use strict 'refs';
  (my $something = 'phal');
  (my $otherthing = 'paul');
  (my $note_whom = q[szmuzu'mi]);
  ((defined($something) ? ($note_whom = $something) : $otherthing) =
'singapore');
  print("$note_whom \n $otherthing \n");

HTH,
-jp



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

Date: Tue, 03 Oct 2006 03:44:34 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: perl flawed or my fault
Message-Id: <C0lUg.49660$E67.41742@clgrps13>

paul wrote:
> 
> please help me the check the following code
> 
> use strict;
> 
> my $something = 'phal';
> my $otherthing = 'paul';
> 
> my $note_whom = 'szmuzu\'mi';
> 
> defined($something) ? $note_whom = $something : $otherthing =
> 'singapore';
> 
> print "$note_whom \n $otherthing \n";
> 
> The result is: singapore
>                    singapore
> 
> I don't know why the scalar $note_whom get the value that is assigned
> to $otherthing.
> 
> Please give me the explaination, and thank you.

Because of precedence you have:

(defined($something) ? $note_whom = $something : $otherthing) = 'singapore';

You need to add parentheses:

defined($something) ? ($note_whom = $something) : ($otherthing = 'singapore');



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


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