[19031] in Perl-Users-Digest
Perl-Users Digest, Issue: 1226 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 1 11:05:32 2001
Date: Sun, 1 Jul 2001 08: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)
Message-Id: <993999906-v10-i1226@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 1 Jul 2001 Volume: 10 Number: 1226
Today's topics:
Re: cant modify $_[x] ???? <tinamue@zedat.fu-berlin.de>
Re: command line news posting tools <pne-news-20010701@newton.digitalspace.net>
Re: converting shell "sort" command to perl.. <goldbb2@earthlink.net>
Re: Create unique file in dir? <goldbb2@earthlink.net>
Re: Faster yet way to count lines in a file (or at leas <goldbb2@earthlink.net>
Re: getting a defined value from a html page <goldbb2@earthlink.net>
Re: how to dynamic append row in table with perl CGI m <goldbb2@earthlink.net>
Re: inline average <bigrich318@yahoo.com>
Re: limiting cgi input from specific IP's <laszlo.gerencser@portologic.com>
Re: Merging two hash tables <bart.lateur@skynet.be>
NNTP->Web software (Alex McLintock)
Re: Open or Die - is die the only choice? <goldbb2@earthlink.net>
Re: Perl *is* strongly typed (was Re: Perl description) <pne-news-20010701@newton.digitalspace.net>
Re: PlRPC causing trouble with STDIN/OUT <goldbb2@earthlink.net>
String question <marinus@nwsoft.net>
Re: String question <wolfram.pfeiffer@bigfoot.com>
Re: String question <bigrich318@yahoo.com>
Re: String question <marinus@nwsoft.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 1 Jul 2001 12:33:43 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: cant modify $_[x] ????
Message-Id: <9hn5b7$e55u7$1@fu-berlin.de>
Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "TM" == Tina Mueller <tinamue@zedat.fu-berlin.de> writes:
> >>> does that help?
> >> I'd guess on ballence your explaination did more harm than good.
> TM> well, i'm sorry. isn't this a discussion group? i'm thankful for
> TM> your corrections and clarifications. and yes, i'll read perlsub
> TM> more carefully now.
> well, even in a discussion, one can be corrected and comments can made
> about a post that was off target so others won't be misled.
sure, that's why i asked, if this is a discussion group. i'm always
glad about corrections because i'm still learning perl (i guess
no one ever really stops learning). and i said that in my post:
> TM> i'm thankful for
> TM> your corrections and clarifications.
the only thing which made me say "isn't this a discussion group?"
was "your explanation did more harm than good".
okay, maybe i took it too seriously, and you misunderstood my
answer.
regards,
tina
f'up2poster
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx
------------------------------
Date: Sun, 01 Jul 2001 15:42:29 +0200
From: Philip Newton <pne-news-20010701@newton.digitalspace.net>
Subject: Re: command line news posting tools
Message-Id: <mq9ujtcsuamvq5dajegfnt6co9m9g73heb@4ax.com>
On 27 Jun 2001 22:39:20 -0300, * Tong * <sun_tong@users.sourceforge.net>
wrote:
> Philip Newton <pne-news-20010627@newton.digitalspace.net> writes:
>
> > > - I test with a pipe command but it didn't work
> > >
> > > cat file | nntppost
> > >
> > > and neither is:
> > >
> > > cat file | nntppost -
> >
> > b) My PSI::ESP module is not working. Showing us the code of the
> > 'nntppost' that you are using would help.
>
> simple:
>
> perl -Mstrict -MNet::NNTP <<'__END__' ${1+"$@"}
> my $n = Net::NNTP->new("news");
> my @article = <>;
> $n->post(\@article) or die "Post error: $!";
> $n->quit;
> __END__
So nntppost is a shell script which calls perl? (I don't see a shebang
line identifying it as such -- say, "#!/bin/sh" or similar -- so I have
to guess here.)
If so, I suggest re-writing it as a proper Perl script so you save one
program call:
#!/usr/bin/perl
use strict;
use Net::NNTP;
my $n = Net::NNTP->new('news') or die "Can't connect!";
my @article = <>;
$n->post(\@article) or die "Post error";
$n->quit;
I don't think the post method sets $! to anything sensible (the docs I
read do not imply anything like that) so I left it out of the error
message.
This script, if called 'nntppost' and marked executable, should be
callable either as "cat file | nntppost" or "cat file | nntppost -" as
you wrote, or without the UUOC as "nntppost file" or "nntppost <file".
(If you call it as 'nntppost file1 file2 file3', then it will probably
post one article containing the three files concatenated to each other.)
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Sun, 01 Jul 2001 08:41:14 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: converting shell "sort" command to perl..
Message-Id: <3B3F1A6A.761A63FE@earthlink.net>
Patrick Erler wrote:
>
> Benjamin Goldberg <goldbb2@earthlink.net> wrote in
> news:3B3C1A30.54DC5E6@earthlink.net:
>
> > Patrick Erler wrote:
> >> now i want to convert the script to perl, no big problem, but this
> >> command i just don't get converted:
> >>
> >> sort -k 4.9b,4.13n -k 4.5b,4.7M -k 4.2b,4.3n -k4.14b,4.15n
> >> -k 4.17b,4.18n -k 4.20b,4.21n
> >>
> >> what it sorts is a simple apache log like this:
> >> 213.83.52.132 - - [28/Jun/2001:20:29:43 +0200] "GET / HTTP/1.0" 200
> >> 3392 "-" "check_http/1.32.2.6 (netsaint-plugins 1.2.9-4)"
> >>
> >> ok, i could call the shell but i really would like to do it in
> >> perl...
> [Benjamins code deleted]
> > I could have used Time::Local rather than packing the date
> > components as bytes, but there is no need to bring it in, since it
> > isn't really needed.
> >
> > Note that this code is untested.
> thanks benjamin.. i corrected some bugs in the code.. here is a tested
> version:
>
> #!/usr/bin/perl -w
> use strict;
>
> #$#ARGV >= 1 or die "Usage:\n\t$0 [logfile]\n";
Why comment this line out? You don't checking arguments?
>
> my %mon;
> @mon{qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)} = (0..11);
>
> my $stabilizer = 0;
>
> open my $ifh, "<", $ARGV[0] # my $ifh closed at end of do-block.
> or die "Could not open $ARGV[0] for r: $!\n";
> rename( $ARGV[0], $ARGV[0] . ".bak" )
> or die "Could not rename $ARGV[0] to $ARGV[0].bak: $!\n";
> open my $ofh, ">", $ARGV[0] # note there is no "my" here.
> or die "Could not open $ARGV[0] for w: $!\n";
There was a purpose of putting this inside the do {} block in my
version. Moving it up here wasn't the right thing to do.
> print $ofh substr $_, 11 for
> sort
> map {
> # 213.83.52.132 - - [28/Jun/2001:20:29:43 stuff
> m/^\S* \S* \S* (\S*)/;
> my @date = unpack "xa2xa3xa4xa2xa2xa2", $1;
> pack "ncccccNa*",
> $date[2], $mon{$date[1]}, @date[0,3,4,5],
> ++$stabilizer, $_;
> } do {{ # double leftbrace to make a block
> ($ifh, $ofh) = (*STDIN, *STDOUT), last if @ARGV == 0;
> } # end of block; "last" from above skips to here.
> <$ifh>;
> };
What you have inside of the do block is incorrect. Consider what
happens if the script is called with no arguments. Originally, I'd had
the open for $ifh and $ofh inside the do block, after the test for if
@ARGV == 0, so that if no arguments were passed, no file was opened.
> close $ofh or die "Couldn't close $ARGV[0]: $!\n" if @ARGV == 1;
Since you moved $ifh to toplevel, you ought to have included a close for
it, too, here.
> __END__
>
> only the simplest thing with this code i don't get solved right now..
> how should this line look like correctly?
>
> $#ARGV >= 1 or die "Usage:\n\t$0 [logfile]\n";
>
> thanks benjamin, you've been a great help!
Well, if you want to write the script to allow only one argument, no
more no less, I would do:
die "Usage:\n\t$0 logfile\n" unless @ARGV == 1;
If you want it to accept either 0 or 1 arguments, then:
die "Usage:\n\t$0 [logfile]\n" unless @ARGV <= 1;
Rewriting the script to accept exactly one argument, this becomes:
#!/usr/bin/perl -w
use strict;
die "Usage:\n\t$0 logfile\n" unless @ARGV == 1;
my %mon;
@mon{qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)} = (0..11);
my ($stabilizer, $ofh) = 0;
print $ofh substr $_, 11 for
sort
map {
# 213.83.52.132 - - [28/Jun/2001:20:29:43 stuff
m/^\S* \S* \S* (\S*)/;
my @date = unpack "xa2xa3xa4xa2xa2xa2", $1;
pack "ncccccNa*",
$date[2], $mon{$date[1]}, @date[0,3,4,5],
++$stabilizer, $_;
} do {
my ($fn, $ifh) = $ARGV[0];
open $ifh, "<", $fn # $ifh declared here, closes at end of scope
or die "Could not open $fn for reading: $!\n";
rename( $fn, $fn . ".bak" )
or die "Could not rename $fn to $fn.bak: $!\n";
open $ofh, ">", $fn # $ofh declared up above, explicitly closed
or die "Could not open $fn for writing: $!\n";
<$ifh>;
};
close $ofh or die "Couldn't close $ARGV[0]: $!\n";
__END__
While this code hasn't been tested, I don't see any reason for it not to
work.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Sun, 01 Jul 2001 08:18:10 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Create unique file in dir?
Message-Id: <3B3F1502.468375E5@earthlink.net>
Zur Aougav wrote:
[snip]
> You can use
> my $filename = time().substr("".rand(),2);
>
> rand() returns a number between 0 and 1. Example: 0.95208740234375.
> substr("".rand(),2) with the example will returns 95208740234375.
> time() returns a number. Example: 993940359 (change every second).
Firstly, is there a point to uding "". before rand()? Surely perl is
smart enough to do the right thing. Secondly, what garuntee do you have
the the generated filename won't be generated by another script? Sure,
it's /unlikely/ but it's still possible.
Even in a single-process environment, consider if this script is run
twice within one second. It's still possible to have a collision with a
file left from the previous run.
> $filename with the above example will be: 99394035995208740234375.
Is there really a need to remove the "." from the rand() string?
>
> Zur
>
> P.S. Lock and retry (with a new name) is a must in multi-processor
> environment. Safe coding (even if you don't have this kind of
> environment) is highly recommended.
Or better yet, use the O_EXCL flag with sysopen.
use Fcntl;
sub mktmp {
my $a = "/tmp/" . time . "." . $$ . rand . ".";
my $b = "0";
my $fh;
++$b until sysopen $fh, $a.$b, O_CREAT | O_EXCL | O_RDWR;
if( wantarray ) {
return ($fh, $a.$b);
} else {
unlink $a.$b;
return $fh;
}
}
Having the rand() in there makes it highly likely to succeed on the
first try, having the counter ($b) makes it so that if it doesn't
succeed at first, it will eventually, assuming /tmp/ is writable.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Sun, 01 Jul 2001 07:42:21 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Faster yet way to count lines in a file (or at least cooler)
Message-Id: <3B3F0C9D.AA72EAEA@earthlink.net>
R. McGillis wrote:
>
> I use the following to count lines in a file:
>
> !#/usr/local/bin/perl -n
>
> END{print "$.\n"};
Cute script, but it forces perl to search for newlines, split on them,
and increment $. for each one. Counting newlines can be done faster
with:
#!/usr/local/bin/perl
$/ = \( 1<<10 );
$. += tr/\n// while <>;
print "$.\n";
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Sun, 01 Jul 2001 09:01:45 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: getting a defined value from a html page
Message-Id: <3B3F1F39.F2A7AE9A@earthlink.net>
TuNNe|ing wrote:
>
> Thanks.
> Ok. So, is this better?
> #!/usr/bin/perl -w
>
> {
> local $/ = undef;
> open(FILE,"newsletter.htm");
> $_ = <FILE>;
> close(FILE);
> while(/<Temperatuur>(.+?)<\/Temperatuur>/sg) {
> print $1;
> }
> }
In addition to comments others have made, FILE is a dynamic, rather than
lexical variable, and it hasn't been localized. So if something else
uses FILE as a filehandle, you end up stomping on it. You can either do
"local *FILE" or else use a lexical for a filehandle. So:
#!/usr/bin/perl -w
use strict;
{
local $_ = do { local $/;
open my $fh, "newsletter.htm"
or die "Couldn't open newsletter.htm: $!\n";
<$fh> };
while( m[<Temperatuur>(.+?)</Temperatuur>]sg ) {
print $1;
};
}
__END__
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Sun, 01 Jul 2001 07:24:08 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: how to dynamic append row in table with perl CGI module?
Message-Id: <3B3F0858.D5F190A2@earthlink.net>
jackkon wrote:
>
> hi all:
> I want to read data from access and put it into the table by cgi.
> I use the CGI module.
> Now, I can read the data correctly.
> But I fail to put the data to the table by cgi.
> My code is below.
> It is the only one method that I can think(I am a newer in cgi).
> Dose any better method to make the mission?
> Thanks for your help.
> ============================================================================
> ==
use strict;
use warnings;
> use CGI;
use CGI::Carp qw(fatalsToBrowser);
> use Win32::ODBC;
> my $cgi=new CGI;
Since only one CGI object is ever used, you'd be better off removing
this line, and removing "$cgi->" from all the places it's used.
> print $cgi->header;
> print $cgi->start_html;
print header, start_html;
> my $DSN='myaccess';
> my $TABLE='cust';
> if(!($dbm=new Win32::ODBC($DSN))){
> print "Reason: " . Win32::ODBC::Error(). "\n";
> exit;
> }
1) You ought to declare $dbm, 2) you should avoid indirect syntax, even
when it's just a call to new, and 3) the syntax you're using isn't
perlish.
my $dbm = Win32::ODBC->new $DSN
or die "Reason: ". Win32::ODBC::Error(). "\n";
> my @data=undef;
> my @title=undef;
This populates each of @data and @title with a one element array, the
value of that element being undef. Ie, it's as if you'd done:
my @data = (undef);
my @title = (undef);
What you really want is for them to be empty arrays -- which you can
accomplish by not assigning anything to them.
my (@data, @title);
> if(! $dbm->Sql("SELECT * FROM $TABLE")){
Are you sure that what you want is "if(!" ? If this is indeed what you
want, it would probably look better as:
if( $dbm->Sql("SELECT * FROM $TABLE") == 0 ) {
Actually, since you most likely want the program to exit if this call
fails, this is probably not what you want... consider something like:
$dbm->Sql("SELECT * FROM $TABLE") == 0 or die "$^E\n"
> @title=$dbm->fieldnames();
> while($dbm->fetchrow()){
> my %row_hash=$dbm->DataHash();
> my @row_array=values %row_hash;
> push(@data, \@row_array);
> }
What makes you think that values %row_hash will be in any particular
order? It will be the same order as keys %row_hash would be, but you
never check that... What you probably want here is
@title = $dbm->fieldnames;
push @data, \@{$dbm->DataHash}{@title} while( $dbm->fetchrow );
> }
> my $MYTABLE=undef;
> $MYTABLE.='
> print $cgi->table(
> {-border=>2},
> $cgi->caption({-align=>top}, "FROM DATABASE",),
> $cgi->Tr(
> {-align=>center, -valign=>top},
> [
> $cgi->th(\@title),';
> for($i=0; $i<=$#data; $i++){
> $MYTABLE.='$cgi->td('.$data[$i].'),';
> }
> $MYTABLE.='
> ],
> ),
> );';
> eval ($MYTABLE); ## not work
eval is evil. What's wrong with doing this in a normal way?
print table {-border->2},
caption( {-align=>top}, "From Database" ),
Tr( {-align=>center, -valign=>top}, [
th( \@table ),
map { td $_ } @data,
] );
> print $cgi->end_html;
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Sun, 1 Jul 2001 06:10:16 -0500
From: "Rich" <bigrich318@yahoo.com>
Subject: Re: inline average
Message-Id: <tju1btnbp33b17@corp.supernews.com>
"David Frauzel" <nogard@gnosrehtaew.ten> wrote in message
news:9hm1cs$2h15$1@news.aros.net...
> This is perhaps esoteric, but I'm curious.
<snip, see previous posts>
You could tie the scalar variable $values{average}.
#!/usr/bin/perl -w
package Average;
sub TIESCALAR {
my ($class, $hashref) = @_;
return bless $hashref, $class;
}
sub STORE {
#called when value assigned to tied variable
#not sure what you'd do here in this case
return;
}
sub FETCH {
my $self = shift;
my $total = 0;
my $colors = 0; #number of valid color values to average
foreach my $color (keys %$self) {
if ($color ne "average"
&&
# Don't use value of $values{$color} unless it's a number
$$self{$color} =~ /^-?(?:(?:\d+\.?\d*)|(?:\d*\.\d+))$/) {
$total += $$self{$color};
$colors++;
}
}
return sprintf("%.2f", $total /= $colors);
}
package main;
my %values = (
red => 5.0,
orange => 4.0,
yellow => 5.5,
);
tie ($values{average}, "Average", \%values);
#don't need to pass the hashref, you could access
#the hash vals directly if you wanted
print "The average is $values{average}\n\n"; #prints 4.83
$values{red} = 7.0;
print "The average is $values{average}\n\n"; #prints 5.50
$values{red} = 5.0; #back to original value
print "The average is $values{average}\n\n"; #prints 4.83
__END__
Or, if you didn't want to go through the trouble of "tie"ing, you could do
something like:
#!/usr/bin/perl -w
use strict;
my %values = (
red => 5.0,
orange => 4.0,
yellow => 5.5,
);
$values{average} = sub {
my $total = 0;
my $colors = 0; #number of valid color values to average
foreach my $color (keys %values) {
if ($color ne "average"
&&
# Don't use value of $values{$color} unless it's a number
$values{$color} =~ /^-?(?:(?:\d+\.?\d*)|(?:\d*\.\d+))$/) {
$total += $values{$color};
$colors++;
}
}
return sprintf("%.2f", $total /= $colors);
};
print "The average is ".$values{average}->()."\n\n"; #prints 4.83
$values{red} = 7.0;
print "The average is ".$values{average}->()."\n\n"; #prints 5.50
$values{red} = 5.0; #back to original value
print "The average is ".$values{average}->()."\n\n"; #prints 4.83
__END__
I apologize again for not thoroughly reading your post.
For more info on the first example above, study up on tied variables
The second example is one way to assign functions to hash keys.
HTH,
Rich
------------------------------
Date: Sun, 01 Jul 2001 14:01:43 GMT
From: Laszlo Gerencser <laszlo.gerencser@portologic.com>
Subject: Re: limiting cgi input from specific IP's
Message-Id: <3B3F2D80.C0945647@portologic.com>
"Godzilla!" wrote:
>
> Andras Malatinszky wrote:
>
> > Gordon Vrdoljak wrote:
>
> (snippage)
>
> > > Is it possible to limit some perl/cgi scripts so that they can only be run from
> > > certain ip addresses?
>
> > Your script could read the remote_host() environment variable and then execute or
> > exit based on what it finds. Read the docs for CGI.pm for details.
>
> Many local servers have remote host name lookup disabled for
> efficiency. Just as many remote servers do not provide a
> host name. Caution is advised pertaining to reliance upon
> a host name for critical program operations.
>
> Godzilla!
You have right. The env. var REMOTE_ADDR what he needs. This is the IP
address of the client (as specified by the CGI 1.0/1.1)
Note: the remote_host() is not an environment variable, but a CGI module
method. The var. that remote_host() uses is REMOTE_HOST, but it tries to
resolve IP address in many other ways based on the value of REMOTE_ADDR
if REMOTE_HOST is not given.
I recommend everyone who is new in CGI scripting to read the
http://hoohoo.ncsa.uiuc.edu/cgi/overview.html
It's not complicated nor too long to read.
And gives the good feeling of knowing how these scripts work.
--
Laszlo Gerencser
PortoLogic Ltd.
------------------------------
Date: Sun, 01 Jul 2001 12:55:27 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Merging two hash tables
Message-Id: <sg7ujt0j3p44os7arqmhaho2cc557vc7f0@4ax.com>
Alan J. Flavell wrote:
>Uh-uh: see http://www.oreilly.com/catalog/lperl2/errata/lperl2.499
>
> {70} In the 5th paragraph in "Hash Slices" section, line of code used
> to read:
>
> @league{keys %score} = values %score;
>
> It now reads:
>
> %league{keys %score} = values %score;
They're getting ready for Perl6. ;-)
--
Bart.
------------------------------
Date: Sat, 30 Jun 2001 13:18:20 GMT
From: alex@arcfan.demon.co.uk (Alex McLintock)
Subject: NNTP->Web software
Message-Id: <3b3dc9ff.75811981@news.demon.co.uk>
Hi folks,
I know of the basic Net::NNTP module and have a script to read the news headers
in a particular news group - but I'd like to provide archives and web front ends
for several newsgroups. Can anyone recommend software to do this?
Perl would be prefered but can handle other languages.
Alex
Alex McLintock
http://www.OWAL.co.uk/ Internet *Software* Consultancy
http://www.DiverseBooks.com/ SF/COMPUTING BOOK REVIEWS
Competition to win Dr Who Goodies
------------------------------
Date: Sun, 01 Jul 2001 06:28:44 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Open or Die - is die the only choice?
Message-Id: <3B3EFB5C.2A1CF7E8@earthlink.net>
Gary wrote:
>
> Every book I have shows "open or die". Isn't there any other way
> to determine if the open succeeded? I have been checking for
> existence using if (-f $file) first, but I'd still rather know the
> open succeeded.
You could test if the resulting filehandle is valid.
open( FH, "somefile" );
if( defined fileno(FH) ) {
# succeeded
}
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Sun, 01 Jul 2001 15:45:31 +0200
From: Philip Newton <pne-news-20010701@newton.digitalspace.net>
Subject: Re: Perl *is* strongly typed (was Re: Perl description)
Message-Id: <r9aujtolhm6jd107eqh1ovj3apdrjjpsgl@4ax.com>
On Thu, 28 Jun 2001 11:08:32 +0800, "John Lin" <johnlin@chttl.com.tw>
wrote:
> "Abigail" wrote
>
> > This one will eventually loop:
> > perl -wle '$var = 3; while (1) {print ++ $var}'
> >
> > This one never loops:
> > perl -wle '$var = "3"; while (1) {print ++ $var}'
>
> Sorry, I don't know what you mean.
> I got the same result (endless loop). Do you have any typo?
Neither of the scripts will stop running, but in the first script, the
cycle of numbers will start repeating at some point, while the second
script will produce numbers that never repeat.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Sun, 01 Jul 2001 06:42:25 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: PlRPC causing trouble with STDIN/OUT
Message-Id: <3B3EFE91.F9FBE802@earthlink.net>
Aaron Baugher wrote:
[snip]
> I also tried replacing the cumbersome file io above using
> IPC::Open2, with:
>
> my( $in, $out ) = (FileHandle->new, FileHandle->new);
> my $pid = open2( $in, $out, "/usr/local/bin/php" );
> $out->print($text);
> $out->close;
> print join '', <$in>;
>
> And I still get my CGI script back on the input filehandle,
> just like above.
Are you absolutely sure that what you are sending to php ($text) is
actually what you intend it to be?
Oh, and you should actually look at if $pid is defined, and die
otherwise, and you should probably not be slurping <$in>, but rather
doing print while <$in>; or somesuch, and you should be doing a waitpid
on $pid and dieing if $? is set.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Sun, 1 Jul 2001 12:01:03 +0200
From: "Marinus Israel" <marinus@nwsoft.net>
Subject: String question
Message-Id: <9hmsk5$8l6e$1@reader01.wxs.nl>
Hi!
I'm writing a sorting algorithm that sorts a list of strings alphabetically,
but I have 2 small problems...
1st: How do I get a certain letter from a string? Like, I want the 3rd
letter from string $x to be in variable $y. If string $x would be: "Hello!"
then I would want $y to be "l".
2nd: How do you swap the values of two variables around? Like $var1=$var2;
$var2=$var1;
Any help is appreciated!
Thanks!
Marinus Israel
------------------------------
Date: 1 Jul 2001 11:22:22 GMT
From: Wolfram Pfeiffer <wolfram.pfeiffer@bigfoot.com>
Subject: Re: String question
Message-Id: <9hn15e$jpk$1@news.rz.uni-karlsruhe.de>
Marinus Israel <marinus@nwsoft.net> wrote:
[snip]
> 1st: How do I get a certain letter from a string? Like, I want the 3rd
> letter from string $x to be in variable $y. If string $x would be: "Hello!"
> then I would want $y to be "l".
Have a look at "substr". In your case:
my $x = "Hello!";
my $y = substr $x, 2, 1; # 2 is offset (3rd char), 1 is number of char's
I guess there is also a more efficient way to extract a single
character, I just don't know it.
> 2nd: How do you swap the values of two variables around? Like $var1=$var2;
> $var2=$var1;
($var1, $var2) = ($var2, $var1);
Wolfram
------------------------------
Date: Sun, 1 Jul 2001 06:30:53 -0500
From: "Rich" <bigrich318@yahoo.com>
Subject: Re: String question
Message-Id: <tju2gp9km2i75b@corp.supernews.com>
"Marinus Israel" <marinus@nwsoft.net> wrote in message
news:9hmsk5$8l6e$1@reader01.wxs.nl...
> Hi!
>
> I'm writing a sorting algorithm that sorts a list of strings
alphabetically,
Doesn't @sorted_strings = sort @strings; work?
> but I have 2 small problems...
>
> 1st: How do I get a certain letter from a string? Like, I want the 3rd
> letter from string $x to be in variable $y. If string $x would be: "Hello!"
> then I would want $y to be "l".
my $string = "Hello!";
my $y = substr($string, 2, 1); #see perlfunc
> 2nd: How do you swap the values of two variables around? Like $var1=$var2;
> $var2=$var1;
($var2, $var1) = ($var1, $var2) ;
I'd be willing to bet that the sorting algorithm you are working on has
already been developed.
Rich
------------------------------
Date: Sun, 1 Jul 2001 13:37:44 +0200
From: "Marinus Israel" <marinus@nwsoft.net>
Subject: Re: String question
Message-Id: <9hn29d$9hej$1@reader02.wxs.nl>
> Doesn't @sorted_strings = sort @strings; work?
No, not in the script I'm using.
> I'd be willing to bet that the sorting algorithm you are working on has
> already been developed.
Thanks for the help, yes, the algorithm I made has probably been developped
by someone else but I made it so that it fits perfectly into my program!
Cheers,
Marinus
------------------------------
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 1226
***************************************