[22445] in Perl-Users-Digest
Perl-Users Digest, Issue: 4666 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 5 11:10:44 2003
Date: Wed, 5 Mar 2003 08:05:09 -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 Wed, 5 Mar 2003 Volume: 10 Number: 4666
Today's topics:
***Text files*** <xweb@katamail.com>
Re: ***Text files*** <ian@WINDOZEdigiserv.net>
Re: ***Text files*** <garry@ifr.zvolve.net>
Re: ***Text files*** <xweb@katamail.com>
Re: ***Text files*** (Anno Siegel)
Re: ***Text files*** (Helgi Briem)
Re: Carp <member19587@dbforums.com>
Re: Carp (Helgi Briem)
CGI query string help <blnukem@hotmail.com>
Re: CGI query string help <mothra@nowhereatall.com>
Re: CGI query string help <neil.shadrach@corryn.com>
Re: Counting matches in a regular expression <krahnj@acm.org>
Re: Counting matches in a regular expression <krahnj@acm.org>
Re: Greedy regexps <somewhere@nowhere.com>
Re: Greedy regexps <somewhere@nowhere.com>
Re: Greedy regexps <usenet@dwall.fastmail.fm>
Re: How to access proxy server for Perl Soap client news@roaima.freeserve.co.uk
Re: insert meta tags into an existing html file <me@privacy.net>
Re: insert meta tags into an existing html file <noreply@gunnar.cc>
Re: insert meta tags into an existing html file (Helgi Briem)
Re: Moving on a grd. <goldbb2@earthlink.net>
Re: Moving on a grd. ctcgag@hotmail.com
Re: Perl Script to Produce XML <ntnewsNOSPAM@hrz3.hrz.tu-darmstadt.de>
Re: Perl Script to Produce XML <hillmw@charter.net>
Re: Playing a .wav file <goldbb2@earthlink.net>
Re: Playing a .wav file <ian@WINDOZEdigiserv.net>
Re: Problem with Unix pipe within perl script (also pos <ridley@net2000.com.au>
Retrieving a Perl variable from a MySQL database <nospam@nospam.org>
Re: Stolen! <goldbb2@earthlink.net>
Re: using system to run a program and redirect its outp <pilsl_use@goldfisch.at>
Re: Works offline but not online <bart.lateur@pandora.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 05 Mar 2003 14:24:38 +0100
From: xweb <xweb@katamail.com>
Subject: ***Text files***
Message-Id: <BA8BB926.E5EB%xweb@katamail.com>
I've a problem. I have a text variable that must be divided in two parts
(half). Can i divide this text without cut the last word?
Thanks
------------------------------
Date: Wed, 05 Mar 2003 14:09:29 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: ***Text files***
Message-Id: <b51c6v89jhfolk0uctubvt0t94rch6l7c7@4ax.com>
Keywords: Remove WINDOZE to reply
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
In a fit of excitement on Wed, 05 Mar 2003 14:24:38 +0100, xweb
<xweb@katamail.com> managed to scribble:
> I've a problem. I have a text variable that must be divided in two
> parts (half). Can i divide this text without cut the last word?
> Thanks
Now we have a "problem" as we don't know what the hell you're on
about.
What text?
Where's it coming from?
Where's it going to?
What format is it in?
What have _you_ thought about, or tried to resolve your issue?
I have a piece of string, that I need to cut exactly in half, how
long should each half be? ;)
Regards,
Ian
-----BEGIN xxx SIGNATURE-----
Version: PGP 8.0
iQA/AwUBPmYFF2fqtj251CDhEQL+lgCg3yCIUufVULJ3Aq+0JT0BiusjMi0AoI/W
aZq4L+IHHgNwZUsgc7nzPE/i
=sbyO
-----END PGP SIGNATURE-----
--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Scripting, Web design, development & hosting.
------------------------------
Date: Wed, 05 Mar 2003 14:10:36 -0000
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: ***Text files***
Message-Id: <slrnb6c1as.gi0.garry@zfw.zvolve.net>
On Wed, 05 Mar 2003 14:24:38 +0100, xweb <xweb@katamail.com> wrote:
> I've a problem. I have a text variable that must be divided in two
> parts (half). Can i divide this text without cut the last word?
use Text::Wrap;
--
Garry Williams
------------------------------
Date: Wed, 05 Mar 2003 15:16:05 +0100
From: xweb <xweb@katamail.com>
Subject: Re: ***Text files***
Message-Id: <BA8BC535.E643%xweb@katamail.com>
Thanks for help Ian.
Sorry, i have a large text (from Oracle) into a variable $text;i would
divide this text in two similar parts (not properly the half), but if i
divide this text with substr i get two similar parts but substr cut the
words:
First text First text First text First text First text First te <#end of
first text>
Second text
xt Second text Second text Second text Second text Second text Second
text<end of second text>.I must print this text on html page and i must
insert a float between text 1 and text two. If the code cut the words...
Thanks
Sorry for my english!
------------------------------
Date: 5 Mar 2003 14:38:36 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: ***Text files***
Message-Id: <b4525c$1qk$1@mamenchi.zrz.TU-Berlin.DE>
xweb <xweb@katamail.com> wrote in comp.lang.perl.misc:
> I've a problem. I have a text variable that must be divided in two parts
> (half). Can i divide this text without cut the last word?
Your subject doesn't match your question at all.
So apparently you want to break the string at the blank closest
to the middle. Before trying to find your own solution, you should
check the Text::Wrap module if it serves your need. It will easily
allow you to break a line at the last blank before the middle.
If you really need the closest possible break position, here is
a sketch how it can be done (assuming the string in $_):
pos = length()/2; # make \G match the middle
/\S*\G\S*/; # find chunk of non-blanks around middle
my ( $before, $after) = ( $-[ 0], $+[ 0]); # start and end of match
my $close = abs( $before - length()/2) < abs( $after - length()/2) ?
$before : $after; # select closest blank
pos = $close;
my ( $first, $last) = split /\G/; # split string at position
This isn't completely debugged. It doesn't work well with all-blank
strings and may fail in other marginal cases, but you can start with
it. In any case you have a problem when the string doesn't contain
any blanks.
Anno
------------------------------
Date: Wed, 05 Mar 2003 14:39:09 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: ***Text files***
Message-Id: <3e660bfd.2256670280@news.cis.dfn.de>
On Wed, 05 Mar 2003 14:24:38 +0100, xweb <xweb@katamail.com>
wrote:
>I've a problem. I have a text variable that must be divided in two parts
>(half). Can i divide this text without cut the last word?
use Text::Wrap;
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: Wed, 05 Mar 2003 10:05:01 +0000
From: pons <member19587@dbforums.com>
Subject: Re: Carp
Message-Id: <2605822.1046858701@dbforums.com>
perl -wce 'use CGI::Carp qw(warningsToBrowser fatalsToBrowser);'
"warningsToBrowser" is not exported by the CGI::Carp module at -e line 1
Content-type: text/html
<H1>Software error:</H1>
<CODE>Can't continue after import errors at -e line 1
BEGIN failed--compilation aborted at -e line 1.
</CODE>
<P>
For help, please send mail to this site's webmaster, giving this
error message
and the time and date of the error.
[...] -e: Can't continue after import errors at -e line 1
[...] -e: BEGIN failed--compilation aborted at -e line 1.
--
Posted via http://dbforums.com
------------------------------
Date: Wed, 05 Mar 2003 14:38:25 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Carp
Message-Id: <3e660bb9.2256601932@news.cis.dfn.de>
On Wed, 05 Mar 2003 10:05:01 +0000, pons
<member19587@dbforums.com> wrote:
<some error messages snipped>
Please stop spamming this newsgroup with
gibberish. If you have a question, ask it.
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: Wed, 05 Mar 2003 14:33:08 GMT
From: "Blnukem" <blnukem@hotmail.com>
Subject: CGI query string help
Message-Id: <EUn9a.2612$gf7.924287@news4.srv.hcvlny.cv.net>
Hi All
When I use CGI and try to pass variables from a query string like this
"www.mysite.com/script.pl.?name=jon&age= 43" they return empty. What am I
doing wrong?
#!/usr/local/bin/perl
use strict;
use CGI qw(:standard);
$user_name = $query->param('name');
$user_age = $query->param('age');
Thanx in advance
Blnukem
------------------------------
Date: Wed, 5 Mar 2003 07:28:21 -0800
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: CGI query string help
Message-Id: <3e661629$1@usenet.ugs.com>
"Blnukem" <blnukem@hotmail.com> wrote in message
news:EUn9a.2612$gf7.924287@news4.srv.hcvlny.cv.net...
> When I use CGI and try to pass variables from a query string like this
> "www.mysite.com/script.pl.?name=jon&age= 43" they return empty. What am I
> doing wrong?
>
> #!/usr/local/bin/perl
>
> use strict;
> use CGI qw(:standard);
>
> $user_name = $query->param('name');
> $user_age = $query->param('age');
The param() method will always return the contents of the POSTed fill-out
form, ignoring the URL's query string. To retrieve URL parameters, call the
url_param() method.
hope this helps
Mothra
------------------------------
Date: Wed, 05 Mar 2003 15:53:58 +0000
From: Neil Shadrach <neil.shadrach@corryn.com>
Subject: Re: CGI query string help
Message-Id: <3E661D96.6060603@corryn.com>
Blnukem wrote:
> Hi All
>
> When I use CGI and try to pass variables from a query string like this
> "www.mysite.com/script.pl.?name=jon&age= 43" they return empty. What am I
> doing wrong?
>
> #!/usr/local/bin/perl
>
> use strict;
> use CGI qw(:standard);
> $user_name = $query->param('name');
> $user_age = $query->param('age');
>
> Thanx in advance
> Blnukem
>
>
If you are using the Oobject-oriented style you need:
use CGI;
$query = new CGI;
------------------------------
Date: Wed, 05 Mar 2003 12:21:14 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Counting matches in a regular expression
Message-Id: <3E65EBB6.8AAC9A34@acm.org>
Barty wrote:
>
> "John W. Krahn" <krahnj@acm.org> wrote in message
> news:3E605F22.71C3FB02@acm.org...
> > Barty wrote:
> > >
> > > I'm replying to myself, but mean this for those that answered...
> > >
> > > Thanks for your responses.. None ended up faster than my methods.
> > > Speed is
> > > a major concern in this.. I'm trying to find out how many 6/49 number
> > > combinations have never won a prize.. So for all of the 14 million
> > > combinations (or so),
> >
> > Just subtracting 1993 from 14 million (or so) will tell you how many
> > have NOT won.
>
> Actually I'm trying to find out how many combinations haven't even matched
> 3... There are 13,983,816 combinations. so far I'm at 5,160,000 and there
> hasn't been one.
Here is a program that will find all three number combinations. It
takes about 15 minutes to run on my 366 MHz computer.
#!/usr/bin/perl
use warnings;
use strict;
# base 50 to base 10 conversions so that
# $bitarray doesn't get too large
sub base50toint (@) {
my $base = 1;
my $result = 0;
while ( @_ ) {
my $digit = pop;
return -1 if $digit < 1 or $digit > 49;
$result += $digit * 50 ** $base++;
}
return $result;
}
sub inttobase50 ($) {
my $int = $_[0];
my @result;
while ( $int > 0 ) {
my $digit = $int % 50;
unshift @result, $digit if $digit;
$int = ($int - $digit) / 50;
}
return @result;
}
# found on the web
# return all combinations of size $n from array @m
# if native integer size is 32 bits then @m <= 31
sub combinations ($@) {
my ( $n, @m ) = @_;
return () unless $n;
$n = ( 1 << $n ) - 1;
my $m = ( 1 << @m );
my @mix;
while ( $n < $m ) {
my $i = ( $n << 1 );
push @mix, [ grep( ( $i = $i >> 1 ) & 1, @m ) ];
$i = ( ~$n >> 1 ) & $n;
$i = $i & -$i;
$n = $n + $i--;
next unless $i = $i & $n;
$n = $n & ~$i;
$i = $i / ( $i & -$i );
$n = $n + $i;
}
@mix;
}
open my $out, '>', 'output.txt' or die "Cannot open output.txt: $!";
select $out; $|++;
select STDOUT; $|++;
print 'Program Start at: ' . localtime() . "\n";
print $out 'Program Start at: ' . localtime() . "\n";
my $bitarray = '';
my $start = base50toint( 1, 2, 3 );
my $end = base50toint( 47, 48, 49 );
my $total = 0;
for my $num ( $start .. $end ) {
my @pick = inttobase50( $num );
next unless @pick == 3;
@pick = sort { $a <=> $b } @pick;
if ( $pick[0] != $pick[1] and $pick[1] != $pick[2] and $num ==
base50toint( @pick ) ) {
vec( $bitarray, $num, 1 ) = 1;
$total++;
}
}
print localtime() . " Matching three digit combinations:\n";
print $out localtime() . " Matching three digit combinations:\n";
open my $csv, '649.csv' or die "Cannot open 649.csv: $!";
while ( <$csv> ) {
# safety check for csv data
next unless tr/0-9,// > 20;
for ( combinations( 3, (split /,/)[ 3 .. 8 ] ) ) {
print $out "@$_\n";
vec( $bitarray, base50toint( @$_ ), 1 ) = 0;
}
}
close $csv;
print localtime() . " Non-matching three digit combinations:\n";
print $out localtime() . " Non-matching three digit combinations:\n";
my $notfound = 0;
for my $num ( $start .. $end ) {
if ( vec( $bitarray, $num, 1 ) == 1 ) {
print $out "@{[ inttobase50( $num ) ]}\n";
$notfound++;
}
}
print "\nTotal: $total\n\nNot found: $notfound\n\nFound: ", $total -
$notfound, "\n\n";
print 'Program End at: ' . localtime() . "\n";
print $out 'Program End at: ' . localtime() . "\n";
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 05 Mar 2003 13:24:20 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Counting matches in a regular expression
Message-Id: <3E65FA81.FE7A6F04@acm.org>
"John W. Krahn" wrote:
>
> Barty wrote:
> >
> > "John W. Krahn" <krahnj@acm.org> wrote in message
> > news:3E605F22.71C3FB02@acm.org...
> > > Barty wrote:
> > > >
> > > > I'm replying to myself, but mean this for those that answered...
> > > >
> > > > Thanks for your responses.. None ended up faster than my methods.
> > > > Speed is
> > > > a major concern in this.. I'm trying to find out how many 6/49 number
> > > > combinations have never won a prize.. So for all of the 14 million
> > > > combinations (or so),
> > >
> > > Just subtracting 1993 from 14 million (or so) will tell you how many
> > > have NOT won.
> >
> > Actually I'm trying to find out how many combinations haven't even matched
> > 3... There are 13,983,816 combinations. so far I'm at 5,160,000 and there
> > hasn't been one.
>
> Here is a program that will find all three number combinations. It
> takes about 15 minutes to run on my 366 MHz computer.
Also, if I precompute $bitarray and store it on disk then the run time
is about two minutes.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 5 Mar 2003 12:05:58 -0000
From: "Bigus" <somewhere@nowhere.com>
Subject: Re: Greedy regexps
Message-Id: <b44p77$nio@newton.cc.rl.ac.uk>
Asby wrote:
> "Bigus" <somewhere@nowhere.com> wrote in message
> news:b427pu$vf2@newton.cc.rl.ac.uk...
>> Hi
>>
>> I am parsing some HTML code in the following manner:
>>
>> $html =~ s/\n//g;
>> $html =~ s/.*<!--search-begin-->(.*)<!--search-end-->.*/$1/i;
>> $html =~ s/(^\s+|\s+$)//g;
>> $html =~ s/\s+/ /g;
>> $html =~ s/<td.+?class=\"*head1.*?>(.*?)<\/td>/###$1###/gi;
>
> Besides the fact that you "could" use a HTML parser, you also uses to
> much .*
> Don't feed a regexp engine with .* if you don't have to.
That is good advice, thanks to Gunnar I know where I was going wrong, and it
was because of a .+?
> Try something like:
>
> $html =~ s!<td[^>]+class="?head1"?>([^<]+)</td>!###$1###!gi;
That's an interesting way of doing a regexp that I wouldn't of thought of -
ie: [^>]+ - matching anything except a >, thereby ensuring that while it
matches any possible property of an element it doesn't go beyond the element
:-)
Spencer
------------------------------
Date: Wed, 5 Mar 2003 12:32:23 -0000
From: "Bigus" <somewhere@nowhere.com>
Subject: Re: Greedy regexps
Message-Id: <b44qon$11jq@newton.cc.rl.ac.uk>
Abigail wrote:
> The ? modifier doesn't stop the regexp from matching, and it doesn't
> stop the regexp from matching at the earliest point possible.
>
> If you insist on doing this with a regexp, you need to make it much
> tigher, to prevent it from matching too much. But it would be far,
> far better to parse HTML.
>
> People should stop thinking it's easy to parse HTML with a single
> regexp. It's not. Parsing is far, far easier.
I do understand that parsing HTML isn't easy if you are to take into account
all the possible complications as identified in the CPAN FAQ, however, I
think for my purposes half a dozen lines of regexps will work nicely to
preprocess the HTML pages ready for keyword searching. Covering "all likely
possibilities" is enough.. if I do spot something at a later date that I've
not taken into account then I can make the necessary correction.
Spencer
------------------------------
Date: Wed, 05 Mar 2003 15:15:24 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Greedy regexps
Message-Id: <Xns933568569AF6Fdkwwashere@216.168.3.30>
Bigus <somewhere@nowhere.com> wrote on 05 Mar 2003:
> Abigail wrote:
>> People should stop thinking it's easy to parse HTML with a single
>> regexp. It's not. Parsing is far, far easier.
> I do understand that parsing HTML isn't easy if you are to take
> into account all the possible complications as identified in the
> CPAN FAQ, however, I think for my purposes half a dozen lines of
> regexps will work nicely to preprocess the HTML pages ready for
> keyword searching. Covering "all likely possibilities" is enough..
> if I do spot something at a later date that I've not taken into
> account then I can make the necessary correction.
Unless it's HTML you've written yourself, you may be tweaking your
program for a long time, depending on the whim of the person or
program writing the HTML.
On the other hand, I use regexes on HTML myself, but always with HTML
*I* wrote and (usually) pre-processed with HTML Tidy
<http://tidy.sourceforge.net/> to get it into a predictable format.
--
David K. Wall - usenet@dwall.fastmail.fm
"HTML clean enough to eat off" --sarcastic comment from a cow-orker
annoyed with me carping about <font> tags and other misc evil
------------------------------
Date: Wed, 5 Mar 2003 12:34:08 +0000
From: news@roaima.freeserve.co.uk
Subject: Re: How to access proxy server for Perl Soap client
Message-Id: <0sq44b.l78.ln@moldev.cmagroup.co.uk>
news@roaima.freeserve.co.uk wrote in message news:<mn9v3b.q7l.ln@moldev.cmagroup.co.uk>...
> Start at http://cookbook.soaplite.com/#accessing%20service%20with%20basic%20authentication
Sade Bhat Kalasabail <sade_bhat@yahoo.com> replied:
> Am I right in assuming that the uri/proxy setting in the SOAP:LITE call
> (as below)
> print SOAP::Lite
> -> uri('http://www.soaplite.com/Demo')
> -> proxy('http://services.soaplite.com/hibye.cgi')
> is for the soap server
Yes.
> And the HTTP_proxy env value (as per the cookbook) I am
> setting are for my proxyserver thru which i get into internet.
Yes.
This works for me (but bear in mind that I don't need to authenticate
to my local proxy server):
use SOAP::Lite;
print SOAP::Lite
->uri("http://www.soaplite.com/Demo")
->proxy("http://services.soaplite.com/hibye.cgi",
proxy => [ "http" => "http://MY_PROXY/" ])
->hi()
->result;
In my case, the MY_PROXY component also includes a port specification
(i.e. "host:port").
I would expect that specifiying values for the environment variables
HTTP_proxy_user and HTTP_proxy_pass before making the SOAP call should
work for you:
use SOAP::Lite;
$ENV{'HTTP_proxy_user'} = 'your_username';
$ENV{'HTTP_proxy_pass'} = 'your_password';
print SOAP::Lite ...etc...
Chris
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: Wed, 5 Mar 2003 23:16:49 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: insert meta tags into an existing html file
Message-Id: <b44prf$1rf0ko$1@ID-172104.news.dfncis.de>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:eZd9a.68756$ep5.43668@nwrddc02.gnilink.net...
> piet wrote:
> > How do I insert new meta tags into an existing local html file?
>
> Please see my answer in The Other NG.
> I hope you still remember where you posted :-(
Suggest the OP reads http://www.cs.tut.fi/~jkorpela/usenet/xpost.html
------------------------------
Date: Wed, 05 Mar 2003 15:04:50 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: insert meta tags into an existing html file
Message-Id: <b4506q$1qqab7$1@ID-184292.news.dfncis.de>
piet wrote:
> Gunnar Hjalmarsson wrote:
>
>>piet wrote:
>>
>>>How do I insert new meta tags into an existing local html file?
>>
>>How about using a text editor? ;-)
>>
>>If that's not the answer you had expected, you may want to give some
>>more details. For instance: In what way is your question related to
>>Perl?
>
> if it were not related to perl, would I be posting in a perl newsgroup?
> what I need is perl code to insert meta tags.
Then you'd better study the second question in
http://www.perldoc.com/perl5.6/pod/perlfaq5.html
Note that in the FAQ for Perl 5.8, the corresponding answer has been
replaced with a recommendation to use the Tie::File module.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 05 Mar 2003 14:28:45 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: insert meta tags into an existing html file
Message-Id: <3e66092c.2255949363@news.cis.dfn.de>
On Wed, 05 Mar 2003 09:25:04 GMT, piet <pdhze@yahoo.co>
wrote:
>> piet wrote:
>if it were not related to perl, would I be posting in a perl newsgroup?
Most posts to Perl newsgroups are not Perl related.
Your question is about HTML, not Perl. The only
thing related to Perl is the print function. See
perldoc -f print
>what I need is perl code to insert meta tags.
See
perldoc -q insert
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: Wed, 05 Mar 2003 09:58:00 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Moving on a grd.
Message-Id: <3E661078.D95A5A08@earthlink.net>
Joe Creaney wrote:
>
> Again I am trying to write simple programs in perl and getting a
> little fustrated. I am trying to write a little demo program that
> will print out a grid
> *...
> ....
> ....
> ....
> I would like to be able to move the star around the grid. I realize
> that this is a text program and will have to re-print the grid after
> each move.
If there's nothing else on the grid but the star:
my ($star_x, $star_y) = (0, 0);
for my $y (0..3) {
for my $x (0..3) {
my $c = ($x == $star_x && $y == $star_y) ? "*" : ".";
print $x;
}
print "\n";
}
If there're potentially lots of things on your grid, then:
my @grid = map [(".") x 4], 42..46;
$grid[0][0] = "*";
print @$_, "\n" foreach @grid;
To move the star around:
$grid[$old_y][$old_x] = ".";
$grid[$new_y][$new_x] = "*"
> Is there a place I could look up simmilar programs.
>
> I see lots of books on how to write the syntax of a language but very
> few on teaching how write programs.
I'm sure that if you were to sign up for a programming class, you'll be
taught how to write programs.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: 05 Mar 2003 15:59:17 GMT
From: ctcgag@hotmail.com
Subject: Re: Moving on a grd.
Message-Id: <20030305105917.433$rO@newsreader.com>
Joe Creaney <mail@annuna.com> wrote:
>
You appear to be posting in some MIME or html format (although my
reader protects me from it until I try reply. Please don't
do that.
> I did some work on my idea. My problem is that I want to use a foreach
> loop to print out the values of the array @grid. I immagine that I
> could get the program to work if I use nested for i = 1 to 5 to print
> out the arrays.
>
> I have been playing with the program and it is realy buggs. I am still
> working on it.
>
> Here is the code:
You really, really, should 'use strict;' It would point many of your
errors.
<snip>
> while ($l < 5) {
foreach my $l (0..4) {
> while ($l1 < 5 ) {
foreach my $l1 (0..4) {
> if (($l == $xp) and ($l1 == $yp)) {
> print "*"; } else {
> print "$grd[$l],[$l1]"; }
> $l1++;
> }
Your formatting is weird. The else is more than cuddled, it's coddled!
No commas are used between the brackets to access arrays. It's
either $grd[$l][$l1] or $grd[$l]->[$l1]. (But in this case, you could
just hard code in the ".", since it will never change. Unless of course
you plan to add obstacles to grd in the future)
> print "\n";
> $l++;
$l1=0;
You need to reset $l1 also. (if you used the foreach, you wouldn't need to
worry about that.)
<snip>
> sub move {
> my ($mi, $xm, $ym) = @_;
> my %mov = (n => [ 0, -1], s => [ 0, 1], e => [1, 0], w => [-1,
> 0]); $xm += $mov{$mi[0]};
$xm += $mov{$mi}[0];
This is the kind of thing strict tells you about.
There are more problems (is it $xm or is it $mx?), but I'm
bored now. use strict.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Wed, 5 Mar 2003 14:18:19 +0100
From: "alex" <ntnewsNOSPAM@hrz3.hrz.tu-darmstadt.de>
Subject: Re: Perl Script to Produce XML
Message-Id: <b44ter$sjt$04$1@news.t-online.com>
sagt mal - von welchen Browsern wird der XML Kram eigentlich alles
unterstützt?
Alex
------------------------------
Date: Wed, 5 Mar 2003 14:45:57 -0600
From: "Michael Hill" <hillmw@charter.net>
Subject: Re: Perl Script to Produce XML
Message-Id: <v6c3d7tbvuji51@corp.supernews.com>
Internet Explorer
"alex" <ntnewsNOSPAM@hrz3.hrz.tu-darmstadt.de> wrote in message
news:b44ter$sjt$04$1@news.t-online.com...
> sagt mal - von welchen Browsern wird der XML Kram eigentlich alles
> unterstützt?
>
>
> Alex
>
>
------------------------------
Date: Wed, 05 Mar 2003 09:47:33 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Playing a .wav file
Message-Id: <3E660E05.3756D099@earthlink.net>
Ian.H [dS] wrote:
> Benjamin Goldberg wrote:
> > Ian.H [dS] wrote:
> > > Afternoon all =)
> > >
> > > Does anyone know of a method/function that'll enable a wav file
> > > to be played on a certain event?
> >
> > On unix, simply copy the file into /dev/audio.
>
> Well, that was an easy solution... and people say UNIX is complicated
> =)
Of course, that only works with formats that the audio device already
knows how to handle -- .au files and probably .wav files; if you want to
play a .midi or .mp3, you'll probably need a special program for that.
(Also, /dev/audio might have some kind of funky permissions on some *nix
operating systems; if so, there'll be a "play" program, which you invoke
as "play thefile.wav". This has the added bonus of checking that the
sound you want to play is compatible with your device driver (i.e., not
something like a .midi or .mp3), and on *some* platforms, it *might*
even automatically call some other program to convert/decompress the
file to send to the audio device.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Wed, 05 Mar 2003 14:55:13 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Playing a .wav file
Message-Id: <ks3c6vg6ie6gdlkdk835qntgerafvh3u56@4ax.com>
Keywords: Remove WINDOZE to reply
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
In a fit of excitement on Wed, 05 Mar 2003 09:47:33 -0500, Benjamin
Goldberg <goldbb2@earthlink.net> managed to scribble:
> Ian.H [dS] wrote:
> > Benjamin Goldberg wrote:
> > > Ian.H [dS] wrote:
> > > > Afternoon all =)
> > > >
> > > > Does anyone know of a method/function that'll enable a wav
> > > > file to be played on a certain event?
> > >
> > > On unix, simply copy the file into /dev/audio.
> >
> > Well, that was an easy solution... and people say UNIX is
> > complicated =)
>
> Of course, that only works with formats that the audio device
> already knows how to handle -- .au files and probably .wav files;
> if you want to play a .midi or .mp3, you'll probably need a special
> program for that.
>
> (Also, /dev/audio might have some kind of funky permissions on some
> *nix operating systems; if so, there'll be a "play" program, which
> you invoke as "play thefile.wav". This has the added bonus of
> checking that the sound you want to play is compatible with your
> device driver (i.e., not something like a .midi or .mp3), and on
> *some* platforms, it *might* even automatically call some other
> program to convert/decompress the file to send to the audio device.
This all sounds good to me and something I'll definitely have a play
around with.
Thanks for your helpful responses Ben, much appreciated =)
Regards,
Ian
-----BEGIN xxx SIGNATURE-----
Version: PGP 8.0
iQA/AwUBPmYPzGfqtj251CDhEQImmQCgyabKyikssyZJufmY47L7wvTRe9oAoLbb
u4cjoTpgaSqk9U9ornMfDk/l
=01NA
-----END PGP SIGNATURE-----
--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Scripting, Web design, development & hosting.
------------------------------
Date: Wed, 05 Mar 2003 23:03:46 +1100
From: ridley <ridley@net2000.com.au>
Subject: Re: Problem with Unix pipe within perl script (also posted in comp.unix.programmer)
Message-Id: <3E65E7A2.99B02924@net2000.com.au>
Try adding the full path to wc
print `echo "hello" | /usr/bin/wc`;
------------------------------
Date: Wed, 5 Mar 2003 09:59:49 -0500
From: "Christian Caron" <nospam@nospam.org>
Subject: Retrieving a Perl variable from a MySQL database
Message-Id: <b453d5$ham1@nrn2.NRCan.gc.ca>
Hi all,
I have a MySQL database that contains a string like this:
"Hello, $username"
If I define $username in my code and then retrieve the string from the
database, when I print it, it prints:
"Hello, $username"
but I would want:
"Hello, somename" (because $username can be assigned to any names).
I tried to eval the string before printing it, but it still displays
"$username" instead of "somename".
###########
#!/usr/local/bin/perl
use DBI;
use strict;
my $language = "0"; # assign French
my $username = "somename";
my $database_read = DBI->connect("DBI:mysql:CSSdomain", "username",
"password") or die "Can't connect: $DBI::errstr";
my %labels;
my $query_labels = $database_read->prepare("select * from Labels");
$query_labels->execute or die "Problem with query_labels:
$query_labels->errstr\n";
while (my @data = $query_labels->fetchrow_array) {
$labels{$data[0]} = ["$data[1]", "$data[2]"]; # data[1] is French, data[2]
is English
}
$query_labels->finish;
$database_read->disconnect;
print "Content-type: text/html\n\n";
eval ($labels{not_authenticated_warning}->[$language]);
print "$labels{not_authenticated_warning}->[$language]";
exit;
###########
Anyone have an idea?
Thanks!
Christian
------------------------------
Date: Wed, 05 Mar 2003 09:38:58 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Stolen!
Message-Id: <3E660C02.987CA6D0@earthlink.net>
Peter Cooper wrote:
>
> > >The most compelling argument I've seen is one of speed. With all of the
> > >statistics I've seen (even those done by Perl people), PHP with the Zend
> > >optimiser outperforms Perl by a long way on Web applications, and outperforms
> > >mod_perl /slightly/.
> >
> > Are you comparing here Perl run as CGI with PHP run as CGI - or Perl run
> > as CGI with PHP run as a web server module? If the latter, that is then
> > where your speed difference is - CGI versus module execution; not language
> > difference (and actually your mention about PHP outperforming mod_perl only
> > slightly seems to indicate that execution mode difference is the reason
> > for the speed difference - not the language).
>
> Sorry, yeah, replace 'Perl' with CGI in my statement. Ditto to Benjamin. PHP
> still beat Perl, even with mod_perl, however.
>
> I'm the least pro-PHP guy you could find, but I gotta say the benchmarks still
> show it's faster. The main benchmark I recall was in PerlMonth.. which seems to
> have fallen off of the Web, but a cached version is at:
>
> http://tinyurl.com/6uyq
Looking at the stats on that page, the speed is measured in "Hits/sec/MHz"
which is an attempt to normalize the hits/sec based on different CPU speeds.
It's a good idea, but there are other overheads involved; I don't think
that comparing the speed of PHP on a PII-400, running Linux-2.2.10 to
to the speed of mod_perl on a PII-233 running Linux 2.2.7. (Even with
the attempt to normalize by dividing by CPU speed).
You really need to do your comparisons with the same hardware, and same
OS.
The only comparison on that page that qualifies are:
Code Type Hits/sec/MHz Hits/s CPU OS Web Server Application
ModPerl Handler 1.236 288 PII-233 Linux 2.2.7 apache 1.3.6 mod_perl
PHP 1.206 281 PII-233 Linux 2.2.7 apache 1.3.6 mod_php 3.0.11
Here, where we're not comparing the speeds of the hardware and the OS,
mod_perl is 2.4% faster than mod_php.
> PHP was about 20% faster across the board (mod_php 4-alpha versus mod_perl),
> although these are old stats.
>
> Anyone got any really up to date benchmarks?
I'd hope to see a benchmark showing mod_perl 2.0 and mod_php 4, on the
same hardware and OS.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Wed, 5 Mar 2003 13:09:52 +0100
From: peter pilsl <pilsl_use@goldfisch.at>
Subject: Re: using system to run a program and redirect its output
Message-Id: <3e65e949$1@e-post.inode.at>
wendy wrote:
> Hi, I was trying to run a program in perl with system() and then redirect
> its output
> something like
> system("./myprog >testout1");
>
> However, the output still showed up on the screen and testout1 was created
> but empty. Anyone know why?
>
reduce the problem. If it doenst work inside perl, try it manually in the
shell and find out if the problem has anything to do with perl at all or
with 'myprog' or with your settings for STDERR and STDOUT.
./myprog
./myprog >t1
./myprog >t1 2>&1
./myprog >t1 2>t2
best,
peter
--
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Wed, 05 Mar 2003 12:15:32 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Works offline but not online
Message-Id: <3eqb6v8166nqep0qp97fstknrbn6mbbln1@4ax.com>
Steve Grazzini wrote:
>>> $rc = 256 and no HTML output.
>>
>> This indicates that the system() function succeeded,
>> and $java was successfully started, but that it did
>> an exit(0).
>
>You mean exit(1). :)
Yes, but what does it mean? Can we expect the program to have printed
some explanation on STDERR? In that case, shouldn't it have arrived in
the server log?
The OP still could try to replace the system() call with backticks, add
"2>&1" to capture STDERR as well, and check $? for the return value from
system(). If nonzero, the contents of what the backticks returned could
be examined.
--
Bart.
------------------------------
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.
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 4666
***************************************