[24962] in Perl-Users-Digest
Perl-Users Digest, Issue: 7212 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 5 18:06:48 2004
Date: Tue, 5 Oct 2004 15:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 5 Oct 2004 Volume: 10 Number: 7212
Today's topics:
Re: How do I print from the cgi to which I am posting u <abigail@abigail.nl>
Re: Is PHP still slower than Perl? <dformosa@zeta.org.au>
Re: Is PHP still slower than Perl? <postmaster@castleamber.com>
Re: Perl books on tape (wana)
Perl HTTP (non-java) IRC client jason@cyberpine.com
Re: Using a string as a variable name. <abigail@abigail.nl>
Re: Using a string as a variable name. <matternc@comcast.net>
Re: Using a string as a variable name. <matternc@comcast.net>
Re: Using a string as a variable name. <dwall@fastmail.fm>
Using an Array in a Class (AJ)
Re: Using an Array in a Class <mritty@gmail.com>
Re: What is @ <sbryce@scottbryce.com>
Re: What is @ <shawn.corey@sympatico.ca>
Re: What is @ <asdf@see.below.com.net.org.invalid>
Re: What is @ <sbryce@scottbryce.com>
Re: Which Counter is Perfect? <abigail@abigail.nl>
Re: Which Counter is Perfect? <noreply@gunnar.cc>
Win2k CMD shell variables and backtick execution (buildmorelines)
Re: Win2k CMD shell variables and backtick execution <mothra@nowhereatall.com>
Re: Win2k CMD shell variables and backtick execution <mothra@nowhereatall.com>
Re: Win2k CMD shell variables and backtick execution <1usa@llenroc.ude.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 05 Oct 2004 18:33:24 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: How do I print from the cgi to which I am posting using post_https?
Message-Id: <slrncm5q7k.1f3.abigail@alexandra.abigail.nl>
Diane (diane@dmswebsupport.com) wrote on MMMMLIII September MCMXCIII in
<URL:news:44d292cb.0410050808.560e0f40@posting.google.com>:
== I am posting information from one perl cgi to another using
== post_https, and would like to print from the second cgi, the one to
== which I am posting. When I use a print statement in the second cgi,
== rather than displaying the information in the browser, it prints to
== the first cgi. I know I can then display that information in the
== browser by using
==
== print "$reply_data";
==
== in the first cgi, but it there a way to actually get the second cgi to
== send the information to the browser?
No.
Abigail
--
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'
------------------------------
Date: 06 Oct 2004 06:55:45 +1000
From: ? the Platypus {aka David Formosa} <dformosa@zeta.org.au>
Subject: Re: Is PHP still slower than Perl?
Message-Id: <m3acv0x4tq.fsf@dformosa.zeta.org.au>
Simon Stienen <simon.stienen@news.slashlife.de> writes:
> Tim Tyler <tim@tt1lock.org> wrote:
> > In comp.lang.php @ <asdf@asdfsadf.com> wrote or quoted:
> >
> >> C. I don't know why it is not popular. It should be. [...]
> >
> > Safety. Security. Imports as includes. Header files.
> > Lack of binary portability. The preprocessor. The fact that C++ sucks.
>
> Please explain the difference between safety and security.
C's unsafe because there is a good chance that C programs will crash
in spectacular ways. C's insecure because it encourages programing
practices that lead to buffer overruns.
> If you've done this:
> *What* is bad about header files and the preprocessor?
The preprocessors Macro system is badly thourt out. The way it
expands means that what looks like a quite resonable programing
construct can infact have supprisingly diffrent results.
[...]
> Why do you expect binary portability from C, while there is binary
> portability for neither PHP, nor Perl, nor Java.
Scripting lanages are portable to where ever there interpreter has
been ported to.
--
Please excuse my spelling as I suffer from agraphia. See
http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more.
Free the Memes.
------------------------------
Date: 5 Oct 2004 21:47:14 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Is PHP still slower than Perl?
Message-Id: <Xns9579AAC4C59F6castleamber@130.133.1.4>
"Tony Marston" <tony@NOSPAM.demon.co.uk> wrote in
news:cjofs2$sa9$1$830fa795@news.demon.co.uk:
[ prepared statements ]
>> How can I use it from PHP?
>
> http://dev.mysql.com/tech-resources/articles/4.1/prepared-
statements.ht
> ml
That's mySQL, not PHP.
I mean something like:
$query = "INSERT INTO table VALUES(?, ?, ?)";
mysql_bla( $query, $a, $b, $c );
Hence without the quote_she_bang_garbage
> I don't waste my time posting to a Microsoft newsgroup saying that all
> MS products suck (otherwise I'd never get anything done), so what
> makes you (or anyone else) think that you can post such comments to
> this group without getting an animated response.
Look at the headers in this posting, and then define "this group"
> You may think that Perl is better than PHP (what is your
> justification?
A solid background in computer science, including some courses in
compiler and language design?
> ) and as it is still a free country (that is until
> President Blair finishes screwing up the constitution) it is your
> God-given right to hold that opinion. I think you are wrong, but it is
> still your right.
I think you have not much experience with Perl ;-) Or any other decent
programming language for that matter either.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 5 Oct 2004 11:26:35 -0700
From: ioneabu@yahoo.com (wana)
Subject: Re: Perl books on tape
Message-Id: <bf0b47ca.0410051026.db4458@posting.google.com>
merlyn@stonehenge.com (Randal L. Schwartz) wrote in message news:<1096987704.CUwTY/B1+6nGRuluLpFv1w@teranews>...
> >>>>> "wana" == wana <ioneabu@yahoo.com> writes:
>
> wana> How much could it cost to produce really? Sit at your computer and
> wana> record yourself spewing out Perl pearls for an hour at a time, package
> wana> into an mp3 and put up on your website for sale. If you're good,
> wana> people will buy.
>
> I'd consider that sort of tape rather useless without the associated
> graphics, unless it was Perl Poetry. :)
>
> And I wouldn't want someone driving beside me listening to a tape on
> Perl (even of me :-), and then flipping down to look at the graphics.
>
> print "Just another Perl hacker,"; # the original
You're probably right. I have a tape series on American history and I
find myself rewinding over and over to get names and dates. I am more
of a visual learner, but I like to have cool stuff to listen to and I
am really hooked on Perl now.
I bought that AT&T natural voice thing for text-to-speech which is as
clear as it gets. Maybe I'll try putting some usenet text through it
to see how it sounds. I'll avoid as much code as possible since it
will sound funny.
How about a 'The Making Of My Perl Book' type program? or 'The
History Of My Hacking On Ancient Unix Systems'. I'm not implying that
you are old. You don't have to be that old to be able to write that
one.
The book, 'The Unix Philosophy' would work well on tape.
wana
------------------------------
Date: 5 Oct 2004 13:19:24 -0700
From: jason@cyberpine.com
Subject: Perl HTTP (non-java) IRC client
Message-Id: <ef0a04d7.0410051219.1d3ed403@posting.google.com>
By any chance anybody done any work with
http://cgiirc.sourceforge.net/
Im looking for somebody that might be hosting the the non-javascript
version.
I understand with this web code, simple cell phone browsers (like
Tmobiles Sidekick) might be able to do IRC.
Thanks.
------------------------------
Date: 05 Oct 2004 18:38:34 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Using a string as a variable name.
Message-Id: <slrncm5qha.1f3.abigail@alexandra.abigail.nl>
Jeff (Jeff@aetherweb.co.uk) wrote on MMMMLIII September MCMXCIII in
<URL:news:525192b4.0410050834.25c2ee5f@posting.google.com>:
`' Hi,
`'
`' I want to do things like this:
`'
`' my $v1 = "varname";
`' my $varname = "it worked!";
`' print ${$v1};
`'
`' And have the final statement know that it should print the content of
`' $varname.
Oh, I got to ask: why do you want this? Would you want to do such a
thing in C or in Java as well?
`' Is it possible?
Yes, but not with my-ed variables. But it's generally considered
bad programming style. See perlref, and look up symbolic references.
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
------------------------------
Date: Tue, 05 Oct 2004 16:58:52 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Using a string as a variable name.
Message-Id: <rLOdnR2DQ-mQlv7cRVn-vQ@comcast.com>
Jeff wrote:
> Hi,
>
> I want to do things like this:
>
> my $v1 = "varname";
> my $varname = "it worked!";
> print ${$v1};
>
> And have the final statement know that it should print the content of
> $varname.
>
> Is it possible?
>
You want to use a hash.
my %hashname;
$hashname{'keyname'}="it worked!";
my $v1="keyname";
print $hashname{$v1};
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Tue, 05 Oct 2004 17:07:14 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Using a string as a variable name.
Message-Id: <rv6dnRbkRP2ZkP7cRVn-hQ@comcast.com>
Abigail wrote:
> Jeff (Jeff@aetherweb.co.uk) wrote on MMMMLIII September MCMXCIII in
> <URL:news:525192b4.0410050834.25c2ee5f@posting.google.com>:
> `' Hi,
> `'
> `' I want to do things like this:
> `'
> `' my $v1 = "varname";
> `' my $varname = "it worked!";
> `' print ${$v1};
> `'
> `' And have the final statement know that it should print the content of
> `' $varname.
>
> Oh, I got to ask: why do you want this? Would you want to do such a
> thing in C or in Java as well?
>
No, but a lot of people come to Perl from shell scripting, and doing
this sort of thing in shell scripts is very common when what you
really want is a Perl-type hash. Since you generally don't have
hashes in shell scripting, you use this kind of hack instead, and
some people try to continue doing it in Perl even though there's
something 254.32 times better.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Tue, 05 Oct 2004 21:18:42 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Using a string as a variable name.
Message-Id: <Xns9579B01A9304Ddkwwashere@216.168.3.30>
Chris Mattern <matternc@comcast.net> wrote:
> Abigail wrote:
>
>> Jeff (Jeff@aetherweb.co.uk) wrote on MMMMLIII September MCMXCIII
>> in <URL:news:525192b4.0410050834.25c2ee5f@posting.google.com>:
>> `' Hi,
>> `'
>> `' I want to do things like this:
>> `'
>> `' my $v1 = "varname";
>> `' my $varname = "it worked!";
>> `' print ${$v1};
>> `'
>> `' And have the final statement know that it should print the
>> content of `' $varname.
>>
>> Oh, I got to ask: why do you want this? Would you want to do such
>> a thing in C or in Java as well?
>>
> No, but a lot of people come to Perl from shell scripting, and
> doing this sort of thing in shell scripts is very common when what
> you really want is a Perl-type hash. Since you generally don't
> have hashes in shell scripting, you use this kind of hack instead,
> and some people try to continue doing it in Perl even though
> there's something 254.32 times better.
I used to do the same sort of thing when writing SAS macros. (For
those unfamiliar with it, SAS is a statistical package, or at least
started as one.) SAS macro language has string variables only, so
even arrays have to be simulated using symbolic references.
When I started programming in Perl I applied some of the same
techniques I had used to get around the shortcomings of the SAS macro
language. When it was pointed out to me that symbolic references were
a bad idea, and more importantly, WHY they were a bad idea, I never
used them again. (at least in Perl)
But when I use SAS, I have no choice: it's symbolic references or
nothing.
------------------------------
Date: 5 Oct 2004 11:52:33 -0700
From: vardig@comcast.net (AJ)
Subject: Using an Array in a Class
Message-Id: <e2d2162a.0410051052.2ed6d3e8@posting.google.com>
I want to have an array in a class I am making. I was testing out the
constructor by passing values to it, let it do its thing. Then call a
function that prints each class member out. Everything goes smooth
until I get to printing the array. It only prints the first member of
the array. I don't even think the constructor is setting the array
correctly the first time. I am new to perl, can someone help me.
Here is my class file:
package Router;
sub new {
my $Router = shift;
my ($name, $hCoord, $vCoord, $weight, @bob) = @_;
my $ref = {Name => $name, hCoord => $hCoord, vCoord => $vCoord,
weight => $weight, @{links} => @bob};
bless ($ref, $Router);
return $ref;
};
sub printShit{
my $ref = shift;
print "name: $ref->{'Name'}\n";
print "weight: $ref->{'weight'}\n";
print "hCoord: $ref->{'hCoord'}\n";
print "vCoord: $ref->{'vCoord'}\n";
print "LinkList: $ref->{'links'}\n";
}
1;
Here is my testFile that has a main:
use Router;
@names = ("hello", "1", "man");
$bob = new Router("wow", 1, 2, 3, @names);
$bob->printShit();
------------------------------
Date: Tue, 05 Oct 2004 19:56:49 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Using an Array in a Class
Message-Id: <50D8d.260$Va.129@trndny08>
"AJ" <vardig@comcast.net> wrote in message
news:e2d2162a.0410051052.2ed6d3e8@posting.google.com...
> I want to have an array in a class I am making. I was testing out the
> constructor by passing values to it, let it do its thing. Then call a
> function that prints each class member out. Everything goes smooth
> until I get to printing the array. It only prints the first member of
> the array.
No it doesn't. It prints nothing about the array at all. At least, the
code you printed below doesn't. Please post the code you're actually
using.
> I don't even think the constructor is setting the array
> correctly the first time. I am new to perl, can someone help me.
>
> Here is my class file:
>
> package Router;
>
> sub new {
> my $Router = shift;
> my ($name, $hCoord, $vCoord, $weight, @bob) = @_;
>
> my $ref = {Name => $name, hCoord => $hCoord, vCoord => $vCoord,
> weight => $weight, @{links} => @bob};
This is not what you want to do. What this is doing is adding an array
of elements, called @links, to the hash reference. The first element of
@links is the hash key for the 2nd element, the third a key for the
fourth, etc. Then it's adding @bob in the same manner.
An array cannot be a member of a hash. An array reference, however,
can:
my $ref = {
Name => $name,
hCoord => $hCoord,
vCoord => $vCoord,
weight => $weight,
links => \@bob,
};
>
> bless ($ref, $Router);
> return $ref;
> };
>
> sub printShit{
> my $ref = shift;
> print "name: $ref->{'Name'}\n";
> print "weight: $ref->{'weight'}\n";
> print "hCoord: $ref->{'hCoord'}\n";
> print "vCoord: $ref->{'vCoord'}\n";
> print "LinkList: $ref->{'links'}\n";
This will now have to be changed. You need to dereference the array:
print "LinkList: @{$ref->{'links'}}\n";
>
> }
> 1;
>
>
> Here is my testFile that has a main:
>
> use Router;
>
> @names = ("hello", "1", "man");
>
> $bob = new Router("wow", 1, 2, 3, @names);
>
> $bob->printShit();
For more information, read up on references. I reccomend starting with
perldoc perlreftut
and moving on eventually to
perldoc perllol
and
perldoc perldsc
Paul Lalli
------------------------------
Date: Tue, 05 Oct 2004 12:15:10 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: What is @
Message-Id: <10m5p58s5ss49c8@corp.supernews.com>
asdf wrote:
> I have been told since perl 5 came out I should
> escape all @ with a \.
Only for strings inside of double quotes within a Perl script.
When a string is inside of double quotes like this:
my $var = "some string of characters";
Perl will look for variables in the string and replace them with the
value stored in the variable.
my $string = 'world';
my $var = "Hello $string";
would set $var to 'Hello world';
Perl uses @ to indicate variables that are arrays. So when Perl encounters:
$var = "username@isp.com";
It will try to replace @isp with the contents of an array named @isp.
If the files are just lists of email addresses, you do not need to
escape the @s inside the files.
------------------------------
Date: Tue, 05 Oct 2004 14:12:05 -0400
From: Shawn Corey <shawn.corey@sympatico.ca>
Subject: Re: What is @
Message-Id: <RsB8d.9466$HO1.544087@news20.bellglobal.com>
asdf wrote:
> Hi,
>
> I have a perl script for filtering spam. Did not write it, don't
> know perl. The white list and black list files it looks to are just
> lists of email addresses. I have been told since perl 5 came out I should
> escape all @ with a \. What if I don't? Is is just another form of
> wildcard? The chances of something other than the intended email
> address having the same start and ending seems remote.
>
> vic@some.com
> vic\@some.com
>
> Thanks,
>
> Vic
>
>
>
>
"... seems remote" is the operative phrase. It is possible for the
improbable to happen.
You should escape the '@' if it appears in a double-quoted Perl string.
If the addresses are in a data file, leave them alone. Perl knows not to
touch them. However, if you see something like these in a Perl program,
escape the '@':
print "me\@my.domain.com";
my $my_address = qq(me\@my.domain.com);
These you leave alone:
print 'me@my.domain.com';
print q/me@my.domain.com/;
my @my_addresses = qw( me@my.domain.com );
See perldoc perlop as to why.
--- Shawn
------------------------------
Date: 5 Oct 2004 19:18:00 GMT
From: asdf <asdf@see.below.com.net.org.invalid>
Subject: Re: What is @
Message-Id: <cjus18$ol3$0@pita.alt.net>
I will escape it. I looked at the script and cannot figure it out.
Should only take, I don't know how long to edit the file.
Thanks,
Vic
------------------------------
Date: Tue, 05 Oct 2004 13:58:30 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: What is @
Message-Id: <10m5v70kfi94r44@corp.supernews.com>
asdf wrote:
> I will escape it. I looked at the script and cannot figure it out.
> Should only take, I don't know how long to edit the file.
If you escape it when you don't need to, it could create problems. Ask
the person who wrote the script whether the @ should be escaped.
------------------------------
Date: 05 Oct 2004 18:30:40 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Which Counter is Perfect?
Message-Id: <slrncm5q2g.1f3.abigail@alexandra.abigail.nl>
nntp (nntp@rogers.com) wrote on MMMMLIII September MCMXCIII in
<URL:news:9MydnS0BYoelxP_cRVn-qQ@rogers.com>:
\\ > :)
\\ > :) You need to read http://www.perlguy.com/articles/locking.html
\\ > :) to understand why the second one is perfect, as far as it stated. I am
\\ not
\\ > :) an expert, but his statement makes sense.
\\ >
\\ > That article never claims the counter found in perldoc is wrong.
\\ >
\\ > The second isn't perfect at all. It fails to work if the flock fails
\\ > (and that's possible!). Furthermore, it only patches one of the silly
\\ > things of the base program he starts with, instead of removing it all
\\ > together. His basic program opens the data file twice - once for reading,
\\ > once for writing. That's not necessary at all, and instead of fixing it
\\ > by not doing it, he just patches around it.
\\ >
\\ >
\\ > Abigail
\\
\\ Do you claim that the counter in Perldoc is Perfect?
No, I never did.
\\ Do you see it covers
\\ all cases?
\\
\\ sysopen(FH, "numfile", O_RDWR|O_CREAT);
\\ flock(FH, LOCK_EX);
\\ $num = <FH> || 0;
\\ seek(FH, 0, 0) ;
\\ truncate(FH, 0);
\\ (print FH $num+1, "\n");
\\ close FH;
\\
\\ I can not see how it can write and read at the same time. I don't understand
\\ why it use sysopen, not open +<;
So, you don't understand the program, yet you claim it is wrong? That's
something I can't fanthom. As for understanding why it can read and
write at the same time, looking up the 'sysopen' function in the Perl
documentation would have told you so.
Abigail
--
perl -wlne '}{print$.' file # Count the number of lines.
------------------------------
Date: Wed, 06 Oct 2004 00:02:20 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Which Counter is Perfect?
Message-Id: <2sgk12F1l1am3U1@uni-berlin.de>
The spontaneous answer to the question in the subject line that comes
up in my mind is: None.
As regards counters that are used for e.g. displaying visits at web
pages, it's important to understand that caching etc. makes the result
not exactly reflect the real visits. But something I personally find
more important is that the value of a counter, that just accumulates
visits, is limited. To me, it's more relevant to focus on the
*current* traffic. This is an example of a Perl counter written with
that view in mind:
http://www.gunnar.cc/programs/counter.pl.txt
For obvious reasons, that code is a little longer than the two
examples you posted, but OTOH it results in more meaningful (IMO)
info. For an example of what it outputs, see the bottom left of
http://www.gunnar.cc/quotes.html
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 5 Oct 2004 11:23:03 -0700
From: bulk88@hotmail.com (buildmorelines)
Subject: Win2k CMD shell variables and backtick execution
Message-Id: <ee659c69.0410051023.776d03f1@posting.google.com>
I want to do backtick execution (to capture STDOUT to a variable for
matching/error handling) with a shell variable in it. If I type it
into a C prompt
C:\>"%PROGRAMFILES%\Windows Media Player\mplayer2.exe" #works fine
When I do
C:\>%PROGRAMFILES%\Windows Media Player\mplayer2.exe
I get
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
Now if I do it in Perl as (heres a list of everything I tried)
system('%PROGRAMFILES%\\Windows Media Player\\mplayer2.exe');
system("%PROGRAMFILES%\\Windows Media Player\\mplayer2.exe");
system("\%PROGRAMFILES%\\Windows Media Player\\mplayer2.exe");
system'"%PROGRAMFILES%\\Windows Media Player\\mplayer2.exe"';
`"%PROGRAMFILES%\\Windows Media Player\\mplayer2.exe"`;
`\"%PROGRAMFILES%\\Windows Media Player\\mplayer2.exe\"`;
qx/"%PROGRAMFILES%\\Windows Media Player\\mplayer2.exe"/;
qx!"%PROGRAMFILES%\\Windows Media Player\\mplayer2.exe"!;
qx#"%PROGRAMFILES%\\Windows Media Player\\mplayer2.exe"#;
qx("%PROGRAMFILES%\\Windows Media Player\\mplayer2.exe");
$run = '"%PROGRAMFILES%\Windows Media Player\mplayer2.exe"';
`$run`;
$run = '%PROGRAMFILES%\Windows Media Player\mplayer2.exe';
`$run`;
I get
'C:\Program' is not recognized as an internal or external command,
operable program or batch file
I've spent 3 hours trying to do this.
The only code I found that does it (written by myself), is this
totally crazy, and there has to be a better, more efficent way. It is
below.
#!/usr/bin/perl
$data = `echo %PROGRAMFILES%\\Windows Media Player\\mplayer2.exe`;
chop $data;
$data = '"' . $data . '"';
print "\n data is \n\n $data \n\n";
`$data`;
Idealy I would like this to work.
$run_result = `%PROGRAMFILES%\\Windows Media Player\\mplayer2.exe`;
Also I know that I need to manually close Windows Media Player for all
of these to work but thats not the point and I have a solution for
that (cmd /c or start).
------------------------------
Date: Tue, 5 Oct 2004 12:46:51 -0700
From: "mothra" <mothra@nowhereatall.com>
Subject: Re: Win2k CMD shell variables and backtick execution
Message-Id: <4162f907@usenet.ugs.com>
"buildmorelines" <bulk88@hotmail.com> wrote in message
news:ee659c69.0410051023.776d03f1@posting.google.com...
> Idealy I would like this to work.
>
> $run_result = `%PROGRAMFILES%\\Windows Media Player\\mplayer2.exe`;
>
Try this:
#!/app/perl5.8.0/bin/perl
use strict;
use warnings;
my $cmd = "\"$ENV{ProgramFiles}\""."\\". "\"Windows Media
Player\"\\mplayer2.exe";
system ("$cmd");
Should do what you want
Mothra
------------------------------
Date: Tue, 5 Oct 2004 12:55:38 -0700
From: "mothra" <mothra@nowhereatall.com>
Subject: Re: Win2k CMD shell variables and backtick execution
Message-Id: <4162fb16$1@usenet.ugs.com>
"mothra" <mothra@nowhereatall.com> wrote in message
news:4162f907@usenet.ugs.com...
> system ("$cmd");
>
ops!!! shame on me for not checking the return status of a system call
should be
system ("$cmd") == 0 || die "Error in system call: $?\n";
Mothra
------------------------------
Date: 5 Oct 2004 20:12:54 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Win2k CMD shell variables and backtick execution
Message-Id: <Xns9579A4F2AE283asu1cornelledu@132.236.56.8>
bulk88@hotmail.com (buildmorelines) wrote in
news:ee659c69.0410051023.776d03f1@posting.google.com:
> I want to do backtick execution (to capture STDOUT to a variable for
> matching/error handling) with a shell variable in it. If I type it
> into a C prompt
>
> C:\>"%PROGRAMFILES%\Windows Media Player\mplayer2.exe" #works fine
>
> When I do
>
> C:\>%PROGRAMFILES%\Windows Media Player\mplayer2.exe
>
> I get
>
> 'C:\Program' is not recognized as an internal or external command,
> operable program or batch file.
>
> Now if I do it in Perl as (heres a list of everything I tried)
>
> system('%PROGRAMFILES%\\Windows Media Player\\mplayer2.exe');
It would help you to actually print each string to see what you are
trying to execute.
Here's what works on my system:
#! perl
use strict;
use warnings;
use File::Spec::Functions;
my $prog = catfile($ENV{ProgramFiles},
'Windows Media Player', 'wmplayer.exe');
print "[ $prog ]\n";
system($prog) == 0
or die "System failed: $?";
__END__
> I've spent 3 hours trying to do this.
> The only code I found that does it (written by myself), is this
> totally crazy, and there has to be a better, more efficent way. It is
> below.
>
> #!/usr/bin/perl
> $data = `echo %PROGRAMFILES%\\Windows Media Player\\mplayer2.exe`;
> chop $data;
> $data = '"' . $data . '"';
> print "\n data is \n\n $data \n\n";
> `$data`;
>
> Idealy I would like this to work.
But it can't. Perl is not your shell. So, how do you expect it to know
what to do with the % signs? On the other hand, you do have acess to
%ENV. Use it.
Sinan.
------------------------------
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 7212
***************************************