[24412] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6600 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 24 06:05:56 2004

Date: Mon, 24 May 2004 03:05:08 -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, 24 May 2004     Volume: 10 Number: 6600

Today's topics:
        ActiveState Perl mangles text files <mothra@mothra.com>
    Re: ActiveState Perl mangles text files <usenet@morrow.me.uk>
    Re: ActiveState Perl mangles text files <mothra@mothra.com>
        Cannot launch simple applications (notepad, java) using (JDS)
    Re: Cannot launch simple applications (notepad, java) u <nospam@bigpond.com>
    Re: Cannot launch simple applications (notepad, java) u <tim@vegeta.ath.cx>
    Re: Cannot launch simple applications (notepad, java) u <tim@vegeta.ath.cx>
    Re: Determine symlink name in required module <usenet@morrow.me.uk>
    Re: Inserting variable within <<EOL <redalert@wakproductions.com>
    Re: Inserting variable within <<EOL <uri@stemsystems.com>
    Re: Number padding... (trailing zeros'.) <thepotplants@yahoo.com>
    Re: output data to audio (Alythh)
    Re: Perl vs PHP <dha@panix2.panix.com>
        questions re "Using the Arrow Operator" in Camel 3ed (Unknown Poster)
    Re: questions re "Using the Arrow Operator" in Camel 3e <ebohlman@earthlink.net>
    Re: quoting in perl command in shell script <this.address@is.invalid>
    Re: quoting in perl command in shell script (Anno Siegel)
    Re: quoting in perl command in shell script <usenet@morrow.me.uk>
    Re: quoting in perl command in shell script <this.address@is.invalid>
    Re: rename files problem <opengeometry@yahoo.ca>
        Sending back 404 error <redalert@wakproductions.com>
        Sequential analysis in perl? <davcamer@interchange.ubc.ca>
    Re: Sequential analysis in perl? (Anno Siegel)
    Re: String search/match question <krahnj@acm.org>
    Re: String search/match question (Anno Siegel)
        Want to kill current process then restart <brm@pobox.com>
    Re: Want to kill current process then restart <krahnj@acm.org>
    Re: What is the difference ? <jurgenex@hotmail.com>
    Re: What is the difference ? <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 24 May 2004 09:07:02 GMT
From: Mothra <mothra@mothra.com>
Subject: ActiveState Perl mangles text files
Message-Id: <VWisc.16121270$Of.2688947@news.easynews.com>

I woudn't normally use this, but it seemed the easiest way to process my 
"Blocked Senders" list in Outlook.

The code below, should be straightforward, but look at the output it 
produces when you run it on a windows text file (created in notepad). 
It seems to put blank spaces (or unprintable characters) in between each 
original character.  If I write it back out to a text file, it's even worse.

Anyone know (or care) why?  I used to write AS Perl scripts a couple of 
years ago, and I'm sure it never did this.

---------code---------

#!/perl
use strict;
use IO::File;

my $input=IO::File->new('blocked_senders.txt', 'r');
my @blocked_senders=<$input>;
$input->close;

foreach(@blocked_senders){
	print $_ . "\n";
}

------output-----------
C:\> .\process_blocked_senders.pl
  ?_ s h e m e k a @ t e l i a . c o m

  c a r l o s _ m o r r i s i f @ b e v . c o m

  d i a m o n d . 8 9 1 8 . 5 4 3 5 2 @ m - t - n . c o m

  d y n e @ y o u a r e i n v i t e d t o . c o m

  f d i d w p @ f l u c h t r e a k t i o n . d e

  f f t y a 0 u d j @ w i d o m a k e r . c o m

  g a n n o n p a l m a @ w a n a d o o . f r

  j o a n b o g a c k i @ w i n t e r h i g h l a n d . c o . u k

  k r y s t a _ h i g g i n s @ t e k m a i l e r . c o m

  k w l r k k f h l p @ 1 6 3 . n e t

  l e o p m z t @ 1 6 3 . n e t

  l z h r @ 2 4 h o r a s . c o m

  m i c h a e l d a r t @ r o j n a m e . c o m

  n o r e p l y @ t i c k l e - i n c . c o m

  p n r w n p e m l @ m s n . c o m

  s m a r t 0 s o l o m o n @ u s w e s t . n e t

  t h a w n n a b o l e k @ a c r o b a t m a i l . c o m

  t i m k l o t t o 2 @ n e t s c a p e . n e t


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

Date: Mon, 24 May 2004 09:30:37 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: ActiveState Perl mangles text files
Message-Id: <c8sfbt$d4f$1@wisteria.csv.warwick.ac.uk>


Quoth Mothra <mothra@mothra.com>:
> I woudn't normally use this, but it seemed the easiest way to process my 
> "Blocked Senders" list in Outlook.
> 
> The code below, should be straightforward, but look at the output it 
> produces when you run it on a windows text file (created in notepad). 
> It seems to put blank spaces (or unprintable characters) in between each 
> original character.  If I write it back out to a text file, it's even worse.
> 
> Anyone know (or care) why?  I used to write AS Perl scripts a couple of 
> years ago, and I'm sure it never did this.
> 
> ---------code---------
> 
> #!/perl

Somehow I doubt you have perl installed as c:/perl.exe. This should
either be

#!c:/perl/bin/perl

or simply

#!perl

> use strict;
> use IO::File;
> 
> my $input=IO::File->new('blocked_senders.txt', 'r');
> my @blocked_senders=<$input>;
> $input->close;
> 
> foreach(@blocked_senders){
> 	print $_ . "\n";
> }
> 
> ------output-----------
> C:\> .\process_blocked_senders.pl
>   ?_ s h e m e k a @ t e l i a . c o m

This is a charset problem: notepad, as of win2k, create files in UTF16
by default. You need Perl 5.8; then you can do:

#!/usr/bin/perl

use strict;
use warnings;

my @blocked_senders = do {
    open my $IN, '<:encoding(utf16)', 'blocked_senders.txt'
        or die "can't open blocked_senders.txt: $!";
    <$IN>;
};

print "$_\n" for @blocked_senders;

Note that if you want to write Notepad-compatible files you will have to
open them with '>:encoding(utf16)' as well.

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: Mon, 24 May 2004 09:42:24 GMT
From: Mothra <mothra@mothra.com>
Subject: Re: ActiveState Perl mangles text files
Message-Id: <4sjsc.5175528$iA2.602959@news.easynews.com>

Ben Morrow wrote:

> Quoth Mothra <mothra@mothra.com>:
> 
>>
>>---------code---------
>>
>>#!/perl
> 
> 
> Somehow I doubt you have perl installed as c:/perl.exe. This should
> either be
> 
> #!c:/perl/bin/perl
> 
> or simply
> 
> #!perl
>
And yet it still works!  But the lines above worked too.  I think AS 
Perl only looks for the word perl in the first line./

> 
> This is a charset problem: notepad, as of win2k, create files in UTF16
> by default. You need Perl 5.8; then you can do:
>
It's Perl 5.8.3 that I have.

> 
> Note that if you want to write Notepad-compatible files you will have to
> open them with '>:encoding(utf16)' as well.
> 
Being awkward now, but is there a way I do this with IO::File?


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

Date: 23 May 2004 20:51:20 -0700
From: jds@iti-oh.com (JDS)
Subject: Cannot launch simple applications (notepad, java) using Apache and PERL(CGI)
Message-Id: <6b2d6822.0405231951.79409c38@posting.google.com>

Hi:

Introduction:
-------------
I need to launch an Xwindows application and a java application from a
web-page running on Apache. The first is an exe file and the second is
a java file. I have a simple perl script to run these. These run fine
and the perl script launches the 2 applications (seperately), but I am
unable to get them to launch from an IE browser running on apache:
----------------------------
#!c:/perl/bin/perl.exe -w
use strict;
use CGI;

my $q = new CGI;
print $q->header( "text/plain" );
system "cmd.exe /c test.bat"; 
#system "xapp ";
----------------------------

test.bat is as follows:
-----test.bat-------
CALL notepad
REM CALL java -jar myapp.jar
--------------------

DETAILS:
--------
1. I can run on windows 2000 from the DOS prompt as follows:
*xwindows application (xapp.exe)
c:> xapp
*Java application. 
c:> test.bat
This brings up the GUI for my java application.
2. The perl script above works and launches the applications in a
seperate window. However, it waits for the application to finish- does
not spawn a thread and forget about them.
QUESTION: How can I do that? e.g. the notepad application is launched
and control returns irrespective of what the user does in the
application. Currently, the DOS prompt freezes till the user exists
the application and retruns.

3. The above script does not run through the web-browser (IE running
apache). I had expected a seperate window to be launched for notepad,
or the xapp or the java application, but that does not happen.
QUESTION: I am lost. It looked like a simple problem and this must
have been experience before by folks. Would appreciate guidance
through this.

Thanks,

Jai.


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

Date: Mon, 24 May 2004 14:19:03 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Cannot launch simple applications (notepad, java) using Apache and PERL(CGI)
Message-Id: <26474730.HLvKajLop4@GMT-hosting-and-pickle-farming>

JDS wrote:

> Hi:
> 
> Introduction:
> -------------
> I need to launch an Xwindows application and a java application from a
> web-page running on Apache.

You want to run programs from a browser? Browsers interpret HTML &
occasionally run Javascript. You may be able to do this from javascript.

gtoomey


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

Date: Mon, 24 May 2004 08:06:32 -0000
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Cannot launch simple applications (notepad, java) using Apache and PERL(CGI)
Message-Id: <slrncb3ava.phj.tim@vegeta.saiyix>

Gregory Toomey <nospam@bigpond.com> wrote:
>  JDS wrote:
> > I need to launch an Xwindows application and a java application from
> > a web-page running on Apache.
>  
> You want to run programs from a browser? Browsers interpret HTML
> & occasionally run Javascript. You may be able to do this from
> javascript.

The CGI calls the programs on the server-side, but it looks like the OP
might be expecting both Apache and IE to be running on the same machine,
so JavaScript may well be a different but equally effective solution *in
this case*.

I'll not discuss how much the concept of a CGI and/or Javascript
application launching user apps offends my sense of program design, not
to mention security.

However, assuming the OP knows what he's doing (difficult as it is), he
may want to look at using the MS Windows "start" keyword in his system()
calls.  I.e.:

    system("start notepad.exe") && print "error launching notepad";

This will allow the notepad process to separate (vaguely similar to
"fork") from the CGI process.

There are myriad complications that this introduces, however.  *IF*
Apache successfully executes this command and a notepad process does
indeed start, the notepad will run with the permissions of the Apache
service, not the logged-in user.  I'm not sure what effect this could
have, and I have no intention of implementing this to find out.

This is an ugly and offensive hack which, if it works at all, will
instantly fail if the Apache server and browser run on separate
machines.  There have been hundreds of posts of people attempting what
you post here and being shocked to find that no Notepad window appears
on the client machine, but the server's sysadmin finds a Notepad session
open on his desktop out of nowhere.

You have been warned, and Google will retain proof of warning
indefinitely.

HTH,
Tim Hammerquist
-- 
Two penguins were walking on an iceberg.  The first penguin
said to the second, "you look like you are wearing a tuxedo."
The second penguin said, "I might be..."
    --David Lynch, Twin Peaks


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

Date: Mon, 24 May 2004 08:08:44 -0000
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Cannot launch simple applications (notepad, java) using Apache and PERL(CGI)
Message-Id: <slrncb3b3f.phj.tim@vegeta.saiyix>

Tim Hammerquist <tim@vegeta.ath.cx> wrote:
>  Gregory Toomey <nospam@bigpond.com> wrote:
> >  JDS wrote:
[ snip ]
>  You have been warned, and Google will retain proof of warning
>  indefinitely.

Apologies for any confusion.  Where I said "you" (in several places)
I was refering to the OP.

Cheers,
Tim Hammerquist
-- 
A supercomputer is a device for converting
a CPU-bound problem into an I/O bound problem.
    -- Ken Batcher


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

Date: Mon, 24 May 2004 07:52:04 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Determine symlink name in required module
Message-Id: <c8s9j3$91i$1@wisteria.csv.warwick.ac.uk>


Quoth vurt <vurt@nospam.example.com>:
> Hi,
> 
> I'm possibly not googling effectively, but I couldn't find an answer to
> this.
> 
> Say I had a scriptanalogous something like:
> 
> require "/foo/bar/S01wibble.pm"
> 
> But the file is actually a symlink, ie:
> 
> /foo/bar/S01wibble.pm -> ../wibble.pm
> 
> How can I, in the required module, find the name of the symlink.  I want to
> be able to have behaviour analogous to rc scripts, and be able to have
> different behaviour determined by the name I was called as.  I hasten to
> add I'm not actually trying to produce real rc scripts here...

AFAIK the only thing you can do is grovel through values %INC looking
for a symlink to the right place. I suppose that if you remove or
replace it every time wibble.pm is loaded this would even be reliable.

Ben

-- 
                Outside of a dog, a book is a man's best friend.
                Inside of a dog, it's too dark to read.
ben@morrow.me.uk                                                  Groucho Marx


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

Date: Mon, 24 May 2004 02:38:28 GMT
From: "Winston Kotzan" <redalert@wakproductions.com>
Subject: Re: Inserting variable within <<EOL
Message-Id: <Eedsc.19952$qQ.9500@newssvr31.news.prodigy.com>

Thanks to everyone who responded.  I can't believe the answer was so simple!


--
Winston Kotzan
http://www.wakproductions.com/


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:2hcertFalt3gU1@uni-berlin.de...
> Winston Kotzan wrote:
> > I am having a perplexing problem inserting a variable in the middle
> > of text without a space.  For example:
> >
> > $myvar = 'some';
> > print <<STOP
> > I want $myvar thing between text.
> > STOP
> >
> > This would output:
> > I want some thing between text.
> >
> > The difficulty arises when I want to insert $myvar without a space
> > between the words; I want the output to look like this:
> > I want something between text.
> >
> > What can I do to join $myvar and the following 'thing' as one word
> > in the above string construct?
>
>      ${myvar}thing
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>




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

Date: Mon, 24 May 2004 04:36:56 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Inserting variable within <<EOL
Message-Id: <x7aczyqw48.fsf@mail.sysarch.com>

>>>>> "WK" == Winston Kotzan <redalert@wakproductions.com> writes:

  WK> Thanks to everyone who responded.  I can't believe the answer was
  WK> so simple!

please don't top post. read the group guidelines (posted regularly)

and note that the answer is the general way to interpolate a variable
when it is followed by a valid token string. the fact that you were
using a here doc make no difference as it works in any doublequotish
string.

<snip of full quote>

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Mon, 24 May 2004 10:19:26 +1200
From: "ThePotPlants" <thepotplants@yahoo.com>
Subject: Re: Number padding... (trailing zeros'.)
Message-Id: <tk9sc.9078$XI4.327987@news.xtra.co.nz>


"Dave Cross" <dave@dave.org.uk> wrote in message
news:pan.2004.05.23.07.32.03.598268@dave.org.uk...
> On Sun, 23 May 2004 19:24:11 +1200, ThePotPlants wrote:
>
> > Hi
> >
> > Is there a nice way of formatting a decimal to have a fixed number of
> > trailing zero's?
> $ perl -le 'printf "%.6f", 0.1029'
> 0.102900
>
> Dave...

Thanks guys :)




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

Date: 24 May 2004 01:02:58 -0700
From: alythh@netscape.net (Alythh)
Subject: Re: output data to audio
Message-Id: <6a25ba72.0405240002.3ae724a6@posting.google.com>

Ben Morrow <usenet@morrow.me.uk> wrote in message news:<c8puai$b$1@wisteria.csv.warwick.ac.uk>...
> Quoth nenamiele@libero.it (Alx):
> > if you had to generate sounds from data with the timber of a given
> 
> (just curious: did you mean 'timbre' or do Americans spell it that way?)

Italians that do not know well english language often use dict:
dict timber
 ...
       5: (music) the distinctive property of a complex sound (a voice
          or noise or musical sound); "the timbre of her soprano was
          rich and lovely"; "the muffled tones of the broken bell
          summoned them to meet" [syn: {timbre}, {quality}, {tone}]

BUT, checking dict timbre I saw that same definition - so we have a
case similar to neighbor/neighbout I guess...

PS thanks for your help on Audio::Data ! Unfortunately I cannot make
it on my Knoppix machine (due to bug
http://rt.cpan.org/NoAuth/Bug.html?id=5384),
I'll see if Audio::Wav works better

Alessandro Magni


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

Date: Mon, 24 May 2004 09:06:41 +0000 (UTC)
From: "David H. Adler" <dha@panix2.panix.com>
Subject: Re: Perl vs PHP
Message-Id: <slrncb3ep1.qnp.dha@panix2.panix.com>

On 2004-05-22, krakle <krakle@visto.com> wrote:
> "David H. Adler" <dha@panix2.panix.com> wrote in message news:<slrncasn5g.980.dha@panix2.panix.com>...
>> On 2004-05-21, krakle <krakle@visto.com> wrote:
>> >
>> > If I had to start all over and select a language to learn from scratch
>> > FOR the web I'd use PHP because 1. It's easier 2. More convienent and
>> > 3. faster than CGI.
>> 
>> For the sake of accuracy, I just want to point out that #3 seems
>> somewhat off, as PHP is a programming language and CGI is an interface.
>> Apples and oranges, you know. :-)
>
> Since we are talking about Perl here I assumed the reader had enough
> brains to figure out CGI in this case was programmed in Perl
> (Obviously since this is PHP vs Perl). In this case yes PHP would be
> faster.

I'd be skeptical of that as a general assumption but, leaving that aside...

If you were to compare a perl program to a php program in terms of
speed, they'd have to do the same thing if you wanted a meaningful
comparison - in which case saying "a PHP CGI program [may be] faster
than a Perl CGI program" would make sense, but to say that PHP is
"faster than CGI" makes no sense whatsoever.


But this is an issue of language and communication, rather than Perl, so
I'll leave it there.

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Naturally, like you, I was incensed, and immediately used my
U.S. Second Amendment rights to buy a duffel bag full of machine guns
for a shooting spree at the office.   - Jon Orwant


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

Date: 23 May 2004 17:48:47 -0700
From: use63net@yahoo.com (Unknown Poster)
Subject: questions re "Using the Arrow Operator" in Camel 3ed
Message-Id: <c62e93ec.0405231648.290d1d2f@posting.google.com>

I've read this section (page 253 of the 3rd edition of Programming Perl) 
enough to confuse myself quite nicely. 

One sentence reads, "If the next thing after the arrow is a bracket or a 
brace, the left operand is treated as a reference to an array or hash, 
respectively ..."

I just don't see how this code, and its explanation, square with that quote:

print $array[3]->{"English"}->[0];

" ... the fourth element of @array is intended to be a hash reference ..."

Isn't it the fourth element of the array referenced by (the poorly named)
$array ? 


When there is more than one arrow operator in an expression, is it true
that only the "initial funny character" is omitted?

When the arrow operator is removed when it would be "between brackets 
or braces, or between a closing bracket or brace and a parenthesis for 
an indirect function call", is the meaning of the expression changed 
in any way?

Anyone know what is meant by "ordinary arrays"?

I'll admit to be so baffled by the final "listref" expressions in this
section that I can't think of a good question.


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

Date: 24 May 2004 01:11:00 GMT
From: Eric Bohlman <ebohlman@earthlink.net>
Subject: Re: questions re "Using the Arrow Operator" in Camel 3ed
Message-Id: <Xns94F2CDFED320Eebohlmanomsdevcom@130.133.1.4>

use63net@yahoo.com (Unknown Poster) wrote in
news:c62e93ec.0405231648.290d1d2f@posting.google.com: 

> I've read this section (page 253 of the 3rd edition of Programming
> Perl) enough to confuse myself quite nicely. 
> 
> One sentence reads, "If the next thing after the arrow is a bracket or
> a brace, the left operand is treated as a reference to an array or
> hash, respectively ..."
> 
> I just don't see how this code, and its explanation, square with that
> quote: 
> 
> print $array[3]->{"English"}->[0];
> 
> " ... the fourth element of @array is intended to be a hash reference
> ..." 
> 
> Isn't it the fourth element of the array referenced by (the poorly
> named) $array ? 

Nope.  "$array" all by itself refers to a scalar variable that has nothing 
to do with @array.  "$array[3]", OTOH, means "the fourth element of 
@array".  It's followed by an arrow, and then an opening brace so, voila! 
it's treated as a reference to a hash.  This means that
"$array[3]->{"English"}" will be whatever value the hash being referenced 
has for the key "English".  And that in turn is followed by an arrow 
followed by a bracket, so the hash value is now treated as a reference to 
an array (which almost certainly isn't @array), and the whole expression 
retrieves the value of the first element of that array.

> When there is more than one arrow operator in an expression, is it
> true that only the "initial funny character" is omitted?
> 
> When the arrow operator is removed when it would be "between brackets 
> or braces, or between a closing bracket or brace and a parenthesis for
> an indirect function call", is the meaning of the expression changed 
> in any way?

No.

> Anyone know what is meant by "ordinary arrays"?

The kind of array that you name "@array" or "@emails" or what have you.

> I'll admit to be so baffled by the final "listref" expressions in this
> section that I can't think of a good question.

perldoc perlreftut might help unconfuse you.


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

Date: Mon, 24 May 2004 09:33:54 +0000
From: Stephane CHAZELAS <this.address@is.invalid>
Subject: Re: quoting in perl command in shell script
Message-Id: <slrncb3cri.1qs.stephane.chazelas@spam.is.invalid>

2004-05-21, 15:26(-04), Barry Margolin:
[...]
>>    cmd="perl -e 'print 1+2'"
>>    $cmd
[...]
> Try: eval $cmd

Please get used to:

eval "$cmd"

-- 
Stephane


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

Date: 24 May 2004 09:19:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: quoting in perl command in shell script
Message-Id: <c8semq$kb0$1@mamenchi.zrz.TU-Berlin.DE>

Stephane CHAZELAS  <this.address@is.invalid> wrote in comp.lang.perl.misc:
> 2004-05-21, 15:26(-04), Barry Margolin:
> [...]
> >>    cmd="perl -e 'print 1+2'"
> >>    $cmd
> [...]
> > Try: eval $cmd
> 
> Please get used to:
> 
> eval "$cmd"

Why?

Anno


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

Date: Mon, 24 May 2004 09:31:23 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: quoting in perl command in shell script
Message-Id: <c8sfdb$d4f$2@wisteria.csv.warwick.ac.uk>


Quoth anno4000@lublin.zrz.tu-berlin.de (Anno Siegel):
> Stephane CHAZELAS  <this.address@is.invalid> wrote in comp.lang.perl.misc:
> > 2004-05-21, 15:26(-04), Barry Margolin:
> > [...]
> > >>    cmd="perl -e 'print 1+2'"
> > >>    $cmd
> > [...]
> > > Try: eval $cmd
> > 
> > Please get used to:
> > 
> > eval "$cmd"
> 
> Why?

Shell, not Perl. Presumably its more portable.

Ben

-- 
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks]         ben@morrow.me.uk


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

Date: Mon, 24 May 2004 10:41:41 +0000
From: Stephane CHAZELAS <this.address@is.invalid>
Subject: Re: quoting in perl command in shell script
Message-Id: <slrncb3gql.1qs.stephane.chazelas@spam.is.invalid>

2004-05-24, 09:19(+00), Anno Siegel:
> Stephane CHAZELAS  <this.address@is.invalid> wrote in comp.lang.perl.misc:
>> 2004-05-21, 15:26(-04), Barry Margolin:
>> [...]
>> >>    cmd="perl -e 'print 1+2'"
>> >>    $cmd
>> [...]
>> > Try: eval $cmd
>> 
>> Please get used to:
>> 
>> eval "$cmd"
>
> Why?

Because, in Bourne like shells, an unquoted variable is a list
of file patterns not a string (it's fixed in zsh).

If a variable is not quoted, upon expansion, it is splitted
according to the value of the IFS special parameter, and any
wildcards are expanded.

For instance,

cmd="echo 'a     b'"
eval $cmd

outputs "a b", because $cmd is splitted into "echo", "'a" and
"b'". eval concatenates those with spaces, so runs:

echo 'a b'

You would think:

cmd='echo "*"'
eval $cmd

harmless?

Try it after:

touch './""; rm -rf "$HOME"'

(DON'T!)

--
Stephane


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

Date: 23 May 2004 23:22:48 GMT
From: William Park <opengeometry@yahoo.ca>
Subject: Re: rename files problem
Message-Id: <2hcq27FbbcgdU1@uni-berlin.de>

In <comp.unix.shell> hpy_awad@yahoo.com <ehab_aziz2001@yahoo.com> wrote:
> I have some files I want to rename them upon parts of their names . 
> For example : files :
> part03_iti_r01_ch03_ver03_conditional_statements_one_if_TV_Rental_bills.c
> part03_iti_r01_ch03_ver04_conditional_statements_one_if_else_TV_Rental_bills.c
> part03_iti_r01_ch03_ver05_conditional_statements_multi_if_else_TV_Rental_bills.c
> part03_iti_r01_ch03_ver06_conditional_statements_switch_TV_Rental_bills.c
> 
> 
> I want to issue unix2dos command for each file :
> as:
> 
> 
> unix2dos part03_iti_r01_ch03_ver03_conditional_statements_one_if_TV_Rental_bills.c
>                ex0303.c
> I will convert 
> part03_iti_r01_ch03_ver03_conditional_statements_one_if_TV_Rental_bills.c
> I chose        ex^^ &  ^^.c
> 
> Which utility I can choose for accomplishing thar task ?
> sed,Perl.... How can I use it in a loop?

Hint:
    sed 's/.*_ch\([0-9][0-9]\)_ver\([0-9][0-9]\).*/ex\1\2/'

    while IFS='_' read part iti r ch ver rest; do
	echo $ch $ver
	echo ${ch#ch} ${ver#ver}
    done

-- 
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Linux solution/training/migration, Thin-client


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

Date: Mon, 24 May 2004 04:38:52 GMT
From: "Winston Kotzan" <redalert@wakproductions.com>
Subject: Sending back 404 error
Message-Id: <w%esc.3613$dz6.2915@newssvr16.news.prodigy.com>

Hi,

I have a Perl script that creates dynamic pages using a passed page
variable.  If someone tries to access a page that does not exist, I want my
script to send back a custom 404 error.  The problem is that I want to make
sure the HTTP 404 status code is sent back to the browser, and not just an
HTTP 200 response with a page displaying an error.  The reason is that I
want to see the 404 status code in my Apache server logs.  What command can
I use to send the correct HTTP status code?

Thanks.

--
Winston Kotzan
http://www.wakproductions.com/




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

Date: Sun, 23 May 2004 18:35:10 -0700
From: D Cameron <davcamer@interchange.ubc.ca>
Subject: Sequential analysis in perl?
Message-Id: <c8rjgb$6rb$1@nntp.itservices.ubc.ca>

I just started writing perl a couple of weeks ago when I walked on to a 
project that was using perl to extract data from a raw data file. It has 
been a dream for text processing, as advertised. But after the data is 
extracted I want to do some statistical tests of the sequential analysis 
variety, and I'm not sure if perl is the best way to go. I was hoping 
some people here could offer some opinions.

The questions I want to answer are along the lines of showing that a 
Markov chain is of order r, and not order r-1; looking at individual 
cells of a contingency table to see which ones are significant; and 
calculating the likelihood ratio chi-square (LRX^2).

The calculations involve a lot of matrix manipulation which I'm 
currently doing with 2D arrays and lots of for(i;i<n;i++) loops. I've 
searched around CPAN a bit but the Statistics and Algorithm namespaces 
didn't offer what I was looking for. After getting great results from 
Algorithm::Cluster I was hoping I'd find something similar for 
sequential analysis.

My perl knowledge is limited, I'm only around chapter 4 of the Camel 
book. The entertaining writing has me reading every page, but I was 
quite impressed to find I could do a 
%results{$picture}{$question}[$prev][$curr] structure without too many 
complaints.

Basically I'm wondering:
-Does the problem sound appropriate for perl, or should I go looking 
somewhere else?
-Am I missing something about perl that would simplify my code 
significantly?
-Can anyone suggest packages that would be useful that I've overlooked?

In case my statistical jargon is unclear, I'll mention my reference here:
Gottman & Roy (1990) Sequential Analysis: A guide for behavioral 
researchers. New York: Cambridge University Press.


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

Date: 24 May 2004 09:38:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Sequential analysis in perl?
Message-Id: <c8sfpo$kb0$2@mamenchi.zrz.TU-Berlin.DE>

D Cameron  <davcamer@interchange.ubc.ca> wrote in comp.lang.perl.misc:
> I just started writing perl a couple of weeks ago when I walked on to a 
> project that was using perl to extract data from a raw data file. It has 
> been a dream for text processing, as advertised. But after the data is 
> extracted I want to do some statistical tests of the sequential analysis 
> variety, and I'm not sure if perl is the best way to go. I was hoping 
> some people here could offer some opinions.
> 
> The questions I want to answer are along the lines of showing that a 
> Markov chain is of order r, and not order r-1; looking at individual 
> cells of a contingency table to see which ones are significant; and 
> calculating the likelihood ratio chi-square (LRX^2).
> 
> The calculations involve a lot of matrix manipulation which I'm 
> currently doing with 2D arrays and lots of for(i;i<n;i++) loops. I've 

[...]

> -Am I missing something about perl that would simplify my code 
> significantly?
> -Can anyone suggest packages that would be useful that I've overlooked?

Take a look at PDL on CPAN.

Anno


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

Date: Mon, 24 May 2004 01:35:05 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: String search/match question
Message-Id: <40B1512E.1DE2939A@acm.org>

Kevin Potter wrote:
> 
> I have a string, that I need to find the first occurance of a
> particular known character in ("index" comes to mind), but with a
> twist.
> 
> The problem is, I need to find the first occurance of this character
> that is not enclosed in brackets "[]" in this string.
> 
> Example string:
> "abcdefg[extra]hijklmn[texas]opqrstuvwxYZabc[tex]defghijklmnopqrstuvwxyz".
> 
> How can I find the POSITION number of the first occurance of the
> letter "x" that is not enclosed in the bracketed text (the one I want
> is the one directly before the capital YZ).
> 
> I've tried numerous versions indexing this and that, comparing this to
> the positions of the first and successive brackets, but cannot come up
> with a realiable method.
> 
> Any thoughts, or pointers would be really appreciated.  Maybe a fancy
> regex would be able to do this?

perl -le'
$_ = "abcdefg[extra]hijklmn[texas]opqrstuvwxYZabc[tex]defghijklmnopqrstuvwxyz";
/x(?=[^]]*\[)/ && print $-[0]
'
37



John
-- 
use Perl;
program
fulfillment


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

Date: 24 May 2004 09:45:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: String search/match question
Message-Id: <c8sg8e$kb0$3@mamenchi.zrz.TU-Berlin.DE>

John W. Krahn <krahnj@acm.org> wrote in comp.lang.perl.misc:
> Kevin Potter wrote:
> > 
> > I have a string, that I need to find the first occurance of a
> > particular known character in ("index" comes to mind), but with a
> > twist.
> > 
> > The problem is, I need to find the first occurance of this character
> > that is not enclosed in brackets "[]" in this string.
> > 
> > Example string:
> > "abcdefg[extra]hijklmn[texas]opqrstuvwxYZabc[tex]defghijklmnopqrstuvwxyz".
> > 
> > How can I find the POSITION number of the first occurance of the
> > letter "x" that is not enclosed in the bracketed text (the one I want
> > is the one directly before the capital YZ).
> > 
> > I've tried numerous versions indexing this and that, comparing this to
> > the positions of the first and successive brackets, but cannot come up
> > with a realiable method.
> > 
> > Any thoughts, or pointers would be really appreciated.  Maybe a fancy
> > regex would be able to do this?
> 
> perl -le'
> $_ = "abcdefg[extra]hijklmn[texas]opqrstuvwxYZabc[tex]defghijklmnopqrstuvwxyz";
> /x(?=[^]]*\[)/ && print $-[0]
> '
> 37

That fails when no "[" follows the valid "x".

Anno


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

Date: Sun, 23 May 2004 21:26:13 -0500
From: Brian <brm@pobox.com>
Subject: Want to kill current process then restart
Message-Id: <a7n2b019qb95sn2ufiifjlbfv87nhognj2@4ax.com>

I have a perl/tk app where I want to supply a button that will kill
the current process and then restart the application.  I was thinking
that I could just fork off a child process at start time and then wait
for the child to finish and then fork off another child.  The quesion
is how to go about doing this?

Thanks,
brian


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

Date: Mon, 24 May 2004 05:16:19 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Want to kill current process then restart
Message-Id: <40B18508.7A16E634@acm.org>

Brian wrote:
> 
> I have a perl/tk app where I want to supply a button that will kill
> the current process and then restart the application.  I was thinking
> that I could just fork off a child process at start time and then wait
> for the child to finish and then fork off another child.  The quesion
> is how to go about doing this?

Assuming that $0 hasn't been modified and is available from the CWD:

exec $0;



John
-- 
use Perl;
program
fulfillment


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

Date: Mon, 24 May 2004 01:55:07 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: What is the difference ?
Message-Id: <%Bcsc.19002$ZQ.18230@nwrddc03.gnilink.net>

Che wrote:
> Hi:
> What is the difference between
> my $str_3 = "c:\windows"; <---- (1)
> my $str_3 = 'c:\windows'; <---- (2)

One backslash.

jue




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

Date: Sun, 23 May 2004 23:00:01 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: What is the difference ?
Message-Id: <slrncb2sq1.mp9.tadmc@magna.augustmail.com>

Che <che@linuxmail.org> wrote:


> What is the difference between


print() the values and see what the difference is for yourself!

You don't really need the help of hundreds of people around the world
to do that you know.


> my $str_3 = "c:\windows"; <---- (1)


   print "[$str_3]\n";


> my $str_3 = 'c:\windows'; <---- (2)


   print "[$str_3]\n";

> 
> If I use (1) the "if" condition fails 


The string contains no backslash character, the pattern requires a
backslash character. The match must fail.


If you had asked perl for some help, then perl would have
happily given you some help, and you would have discovered
the cause of the problem in a few microseconds.

How many microseconds have you spent on it so far?

Don't waste human time on a machine's job, just ask the
machine to do the job for you:


   use warnings;


> and if i use (2) the "if" condition is true.


As it should be.


> (1) or (2) here followe by this code.
> if( $str_3 =~ m!c:\\windows! )
> {
> 	print"\n  matches";
> }
> else
> {
> 	print"\n It doesn't match";
> }



You don't have to use \silly\ slashes unless it is destined for
a Win command interpreter. /sane/ slashes work fine on Windows
and it avoids these kinds of problems...


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


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

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


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