[16289] in Perl-Users-Digest
Perl-Users Digest, Issue: 3701 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 18 00:10:28 2000
Date: Mon, 17 Jul 2000 21:10:15 -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: <963893415-v9-i3701@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 17 Jul 2000 Volume: 9 Number: 3701
Today's topics:
Re: Perl can't add ! (Abigail)
Re: problem with socket/webmail client (Keith Calvert Ivey)
Re: Shortcut for non-defined variables (Abigail)
Small job for someone. <dan@dlna.com>
Re: sound editing aaronp@removeme-shore.net
Re: String and Hash question...rather urgent <anuragmenon@my-deja.com>
Re: String and Hash question...rather urgent <stephenk@cc.gatech.edu>
Re: Unable to append <jaurangNOjaSPAM@crosswinds.net.invalid>
Re: Unable to append <jaurangNOjaSPAM@crosswinds.net.invalid>
Re: Unable to append (Abigail)
Unflattening a multi-dimensional array <matt.stoker@motorola.com>
Re: Unflattening a multi-dimensional array (Randal L. Schwartz)
Re: Unflattening a multi-dimensional array (Neil Kandalgaonkar)
Re: Unflattening a multi-dimensional array (Neil Kandalgaonkar)
very dumb DBI question jblatz2@my-deja.com
Re: very dumb DBI question (Prasanth A. Kumar)
warn not working after re-opening STDERR scottbeck@my-deja.com
Re: warn not working after re-opening STDERR (jason)
Yet another string manipulation question - <anuragmenon@my-deja.com>
Re: Yet another string manipulation question - (jason)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Jul 2000 22:38:10 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Perl can't add !
Message-Id: <slrn8n7hpb.ibq.abigail@alexandra.delanet.com>
Logan Shaw (logan@cs.utexas.edu) wrote on MMDXII September MCMXCIII in
<URL:news:8l05qi$nk2$1@provolone.cs.utexas.edu>:
"" In article <slrn8n75h5.ibq.abigail@alexandra.delanet.com>,
"" Abigail <abigail@delanet.com> wrote:
"" >jcano@mmcnet.com (jcano@mmcnet.com) wrote on MMDXII September MCMXCIII in
"" ><URL:news:lzlmz1cypc.fsf@mmcnet.com>:
"" >``
"" >`` Now if you need perfect representation combined with irrational
"" >`` numbers you are in trouble.
"" >
"" >
"" >Algebraic numbers can be represented perfectly in finite amount of memory.
"" >After all, algebraic numbers are roots of finite degree polynooms,
"" >with integer coordinates. The square root of 2 for instance is a root
"" >of f(x):x^2 - 2.
""
"" Hmm...
""
"" If you can represent them, that's great. But, can you do arithmetic on
"" them? You can always do things symbolically, but ultimately you may
"" want to have an actual value for your expression.
Yes, you can (the set algebraic numbers is closed under addition,
multiplication, subtraction, division and root extraction). There was
an (invited) talk at the Canadian Conference for Computational Geometry
(Waterloo, 1993) by Chee Yap where he did exactly this. Unfortunally, the
paper doesn't appear in the conference proceedings and I have forgotten
the details.
Polynomes with integer coordinates can be representated as simple
lists of integers. x^3 + x - 3, for instance, can be represented
as [-3, 1, 0, 1].
"" Furthermore, it's really handy if the representation of the result of
"" an operation isn't more complicated than the representation of the
"" operands. If it is more complicated (or if there isn't an upper bound
"" on how complicated it'll get), you have the disheartening property that
"" running time is more than proportional to the number of arithmetic
"" operations to be performed.
Considering that you cannot represent sqrt(2) as a (binary) float using
finite precision, I'm not quite sure what you mean by "more complicated".
Some things are easy. For instance, if z is a root of the polynome
a_n x^n + a_(n-1) x^(n-1) + ... + a_1 x + a_0
then 1/z is a root of the polynome
a_0 x^n + a_1 x^(n-1) + ... + a_(n-1) x + a_n
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
------------------------------
Date: Tue, 18 Jul 2000 02:12:27 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: problem with socket/webmail client
Message-Id: <3977bba2.7967101@news.newsguy.com>
fgont@my-deja.com wrote:
>Well, my script will only get "Fernando Ariel Gont" (i.e., it will
>not get the string "<fernandogont@softhome.net>").
Are you looking at the string in a Web browser? If so, have you
changed all < to < before printing it? If you haven't, then
most browsers will hide the stuff in <> from you. Use "View
Source" to see whether there's something there you're not
seeing.
[too-long example snipped]
If I haven't guessed right, and no one else finds your problem,
try cutting your script down to the minimum necessary to show
the problem. Not many people will want to read through 200
lines to help you.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
(Free at last from the forced spamsig of
Newsfeeds.com, cursed be their name)
------------------------------
Date: 17 Jul 2000 22:49:06 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Shortcut for non-defined variables
Message-Id: <slrn8n7iea.ibq.abigail@alexandra.delanet.com>
James Weisberg (chadbour@wwa.com) wrote on MMDXIII September MCMXCIII in
<URL:news:nKNc5.4338$IZ1.41877@iad-read.news.verio.net>:
##
## Since my original post, as per suggestion, I took a look at the
## defconfaq at www.perl.com and familiarized myself with the arguments
## that surround the introduction of the ?? operator.
I'd say the letters 'faq' are a misnomer in the title of the document.
It's an emotional, polital document, and hilarious if the arguments are
applied to things that are getting introduced to Perl anyway. ("our", for
instance). The defconfaq mainly states opinions of one person, and is
not a peer reviewed document.
## As you might expect,
## I didn't realize they were as involved as they are. On the surface,
## use of a ?? as an initializer almost seems like a natural operator
## given the || operator and the rich (perhaps too rich) syntactical
## structure already present.
## It looks to me that the majority of the debate surrounding the
## introduction of the ?? operator centers on its possible misuse in
## situations that are non-assigning, like "if ($a ?? $b)" and/or its
## use in non-scalar context (@a = @b ?? @c).
Bogus arguments. One could misuse any binary operator in boolean context.
if ($a + $b) seldomly makes sense, but that doesn't mean + isn't useful.
The results of @a = @b || @c or @a = @a && @b aren't obvious either,
yet noone makes an issue of that. And furthermore, when was the last
time you saw a posting here that discussed problems with the use of ||
or && in list context? OTOH, people having problems with scoping aren't
uncommon, but murkying the waters with "our" wasn't a problem.
Abigail
--
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";
------------------------------
Date: Mon, 17 Jul 2000 20:31:18 -0700
From: "Danny Lipman" <dan@dlna.com>
Subject: Small job for someone.
Message-Id: <biQc5.150$wi7.90264@news.pacbell.net>
I need a search script edited to only search on one of the fields in the
database.
The script workds now based on 9 fields in the database. It's a small
change I'm sure and it will pay small change. If you are interested contact
me.
--
Sincerely,
Danny Lipman
------------------------------
Date: Tue, 18 Jul 2000 03:01:11 GMT
From: aaronp@removeme-shore.net
Subject: Re: sound editing
Message-Id: <XLPc5.439$y5.65103@news.shore.net>
The modules didnt quite do what I needed, but I did use some perl to
patch together a bunch of little apps which do. I use the linux driver for
winradio (www.linradio.com - perl code is available for controlling it)
and pump it into my sb pro 16, yarec to record (sox rec doesnt have a
timer function), sox to convert to DAT, then some perl to parse the
headers a bit, then gnuplot to throw up a graph. I put it together in a
perl script which automatically updates a web page with the data every 4
minutes. It works well. I also found the wplot function in the wavetools
package, but its not sensitive enough for the signals I'm receiving (its
darn fast though!). You can see how it all came together to record a solar
flare today at http://www.theendoftheworld.org/flare/july17.html
Thanks to all who helped.
Aaron Price, Technical Assistant, UNIX, CGI.
American Association of Variable Star Observers
http://www.aavso.org
------------------------------
Date: Tue, 18 Jul 2000 01:21:56 GMT
From: Vinod K. Menon <anuragmenon@my-deja.com>
Subject: Re: String and Hash question...rather urgent
Message-Id: <8l0bf7$njo$1@nnrp1.deja.com>
> using qw() you probably mean
>
> %hash1 = qw( a 10101
> b 20202 ); # no extra quotes...
the value that I plan to retrieve has spaces in the sense that the value
of the Key a is a string which is "1.0 2.0 3.0". If the extra quotes
cannot be used, then will
%hash1 = qw(a 1.0 2.0 3.0
b 2.0 3.0 4.0);
work or do I have to use individual assignment statements
like $hash1("a") = "1.0 2.0 3.0";
and so on for all keys?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 17 Jul 2000 22:12:18 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: String and Hash question...rather urgent
Message-Id: <3973BD02.CAFDBD13@cc.gatech.edu>
"Vinod K. Menon" wrote:
> > using qw() you probably mean
> >
> > %hash1 = qw( a 10101
> > b 20202 ); # no extra quotes...
>
> the value that I plan to retrieve has spaces in the sense that the value
> of the Key a is a string which is "1.0 2.0 3.0". If the extra quotes
> cannot be used, then will
>
> %hash1 = qw(a 1.0 2.0 3.0
> b 2.0 3.0 4.0);
> work or do I have to use individual assignment statements
>
> like $hash1("a") = "1.0 2.0 3.0";
>
> and so on for all keys?
>
qw() splits on a space, regardless of what other delimeters(e.g. ["'()])
appear. If you need to store strings with internal spaces, don't use qw().
Instead, use:
%hash1 = (a => "1.0 2.0 3.0",
b => "2.0 3.0 4.0");
--
Stephen Kloder | "I say what it occurs to me to say.
stephenk@cc.gatech.edu | More I cannot say."
Phone 404-874-6584 | -- The Man in the Shack
ICQ #65153895 | be :- think.
------------------------------
Date: Mon, 17 Jul 2000 19:33:03 -0700
From: Taurean <jaurangNOjaSPAM@crosswinds.net.invalid>
Subject: Re: Unable to append
Message-Id: <176f8e61.3226a73d@usw-ex0108-061.remarq.com>
When I add the following line:
use strict;
I get an error message:
'somepath\advert_add.pl' script produced no output
How do I solve this problem?
* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful
------------------------------
Date: Mon, 17 Jul 2000 20:02:08 -0700
From: Taurean <jaurangNOjaSPAM@crosswinds.net.invalid>
Subject: Re: Unable to append
Message-Id: <0d47c5ff.39bd7001@usw-ex0108-061.remarq.com>
Still no joy!
The problem is unable to append. I've checked the text
file. No database is used. When I run advert_pl, the
records are displayed correctly. I think the problem lies
with advert_add.pl.
When I add the -T switch or the use strict line, I get the
following message:
'somepath\advert_add.pl' script produced no output
I hope you can help me with this problem.
* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful
------------------------------
Date: 17 Jul 2000 23:37:31 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Unable to append
Message-Id: <slrn8n7l8f.v90.abigail@alexandra.delanet.com>
Taurean (jaurangNOjaSPAM@crosswinds.net.invalid) wrote on MMDXIII
September MCMXCIII in <URL:news:176f8e61.3226a73d@usw-ex0108-061.remarq.com>:
'' When I add the following line:
''
'' use strict;
''
'' I get an error message:
''
'' 'somepath\advert_add.pl' script produced no output
''
'' How do I solve this problem?
Add the following at the top of your program:
BEGIN {print "Output!\n"}
HTH. HAND.
Abigail
--
BEGIN {$^H {join "" => ("a" .. "z") [8, 13, 19, 4, 6, 4, 17]} = sub
{["", "Just ", "another ", "Perl ", "Hacker\n"] -> [shift]};
$^H = hex join "" => reverse map {int ($_ / 2)} 0 .. 4}
print 1, 2, 3, 4;
------------------------------
Date: Mon, 17 Jul 2000 18:28:20 -0700
From: Matthew Stoker <matt.stoker@motorola.com>
Subject: Unflattening a multi-dimensional array
Message-Id: <3973B2B4.F68CB68A@motorola.com>
I appologize if I overlooked this in a FAQ somewhere, but I have the
following problem.
I have an array (@data_set) that is read from a file. I need to parse
this large flat array into a multidimensional array (a list of lists in
perlspeak). Anyway, what makes it tricky is that I don't know beforehand
how many dimensions the multidimensional array should have or the number
of elements in each dimension. These are also read from the file into a
second array @dim. Therefore:
@dim = the desired number of dimensions
$dim[0] = the number of elements in the 1st dimension
$dim[1] = the number of elements in the 2nd dimension
.
.
.
$dim[$#dim]= the number of elements in the last dimension
If I knew the number of dimensions beforehand, it would be easy to use a
series of nested "for" loops as follows:
#!/usr/local/bin/perl -w
#
# example for creating a 3d array
#
use strict;
my ($i, $j, @data_set, @dim, @multi_array);
open(INP, "input_file.inp") or die "Can't open input_file.inp";
@dim = split (" ",<INP>);
while (<INP>)
{
push @data_set, split;
}
for $i (0..$dim[2]-1)
{
for $j (0..$dim[1]-1)
{
$multi_array[$i][$j] = [splice (@data_set,0,$dim[0])];
}
}
# Now print out the results:
for $i (0..$dim[2]-1)
{
print "ith dimension: $i\n";
for $j (0..$dim[1]-1)
{
print "jth = $j @{$multi_array[$i][$j]} \n";
}
}
But since I don't know how many dimensions, I don't know how many nested
loops to put in the code. Any suggestions?
thanks
--
/------------------------------------------------------------------\
| Matt Stoker | email: matt.stoker@motorola.com |
| Unit Process Modeling | Mail Drop: M360 |
| DigitalDNA(TM) Laboratories| Phone: (480)655-3301 |
| Motorola, SPS | Fax: (480)655-5013 |
| 2200 W Broadway Road | Pager: (888)699-8803 |
| Mesa, AZ 85202 | |
\------------------------------------------------------------------/
------------------------------
Date: 17 Jul 2000 19:28:18 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Unflattening a multi-dimensional array
Message-Id: <m1aefg9np9.fsf@halfdome.holdit.com>
>>>>> "Matthew" == Matthew Stoker <matt.stoker@motorola.com> writes:
Matthew> @dim = the desired number of dimensions
Matthew> $dim[0] = the number of elements in the 1st dimension
Matthew> $dim[1] = the number of elements in the 2nd dimension
Matthew> .
Matthew> .
Matthew> .
Matthew> $dim[$#dim]= the number of elements in the last dimension
Well, the array can be defined recursively fairly easily, so a recursive
subroutine would be the most straightforward way to me to built it.
@data = (1..30);
@dims = (5,2,3);
my @result = reformat(@dims);
sub reformat {
my $count = shift;
if (@_) { # more recursion needed
map { [reformat(@_)] } 1..$count;
} else {
splice(@data, 0, $count);
}
}
use Data::Dumper;
print Dumper(\@result);
There are probably far more efficient solutions, but if you're not
doing this every 5 seconds, who cares? :) I didn't do any error
checking to ensure that @dims conforms to the original size of @data,
so beware.
print map $_, "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Tue, 18 Jul 2000 03:31:32 GMT
From: neil@brevity.org (Neil Kandalgaonkar)
Subject: Re: Unflattening a multi-dimensional array
Message-Id: <8l0imr$3ot$1@localhost.localdomain>
In article <3973B2B4.F68CB68A@motorola.com>,
Matthew Stoker <matt.stoker@motorola.com> wrote:
>I appologize if I overlooked this in a FAQ somewhere, but I have the
>following problem.
>
>I have an array (@data_set) that is read from a file. I need to parse
>this large flat array into a multidimensional array (a list of lists in
>perlspeak). Anyway, what makes it tricky is that I don't know beforehand
>how many dimensions the multidimensional array should have or the number
>of elements in each dimension. These are also read from the file into a
>second array @dim. Therefore:
>
>@dim = the desired number of dimensions
>$dim[0] = the number of elements in the 1st dimension
>$dim[1] = the number of elements in the 2nd dimension
>.
>.
>.
>$dim[$#dim]= the number of elements in the last dimension
>
>If I knew the number of dimensions beforehand, it would be easy to use a
>series of nested "for" loops as follows:
>
>#!/usr/local/bin/perl -w
>#
># example for creating a 3d array
>#
>
>use strict;
>my ($i, $j, @data_set, @dim, @multi_array);
>
>open(INP, "input_file.inp") or die "Can't open input_file.inp";
>@dim = split (" ",<INP>);
>while (<INP>)
>{
> push @data_set, split;
>}
>
>for $i (0..$dim[2]-1)
>{
> for $j (0..$dim[1]-1)
> {
> $multi_array[$i][$j] = [splice (@data_set,0,$dim[0])];
> }
>}
>
># Now print out the results:
>for $i (0..$dim[2]-1)
>{
> print "ith dimension: $i\n";
> for $j (0..$dim[1]-1)
> {
> print "jth = $j @{$multi_array[$i][$j]} \n";
> }
>}
>
>But since I don't know how many dimensions, I don't know how many nested
>loops to put in the code. Any suggestions?
>
>thanks
>
>--
>/------------------------------------------------------------------\
>| Matt Stoker | email: matt.stoker@motorola.com |
>| Unit Process Modeling | Mail Drop: M360 |
>| DigitalDNA(TM) Laboratories| Phone: (480)655-3301 |
>| Motorola, SPS | Fax: (480)655-5013 |
>| 2200 W Broadway Road | Pager: (888)699-8803 |
>| Mesa, AZ 85202 | |
>\------------------------------------------------------------------/
--
Neil Kandalgaonkar <neil@brevity.org>
------------------------------
Date: Tue, 18 Jul 2000 03:37:46 GMT
From: neil@brevity.org (Neil Kandalgaonkar)
Subject: Re: Unflattening a multi-dimensional array
Message-Id: <8l0j1c$3pl$1@localhost.localdomain>
Sorry for the posting... for some reason I still can't cancel my
own posts. Will investigate.
Anyway, my answer was basically the same as Randal's (no really, here
it is:)
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my $input = "input_file.inp";
# open(INP, "< $input") or die "Can't open $input: $!";
*INP = *DATA; # just for this example.
my (@data_set, @dim);
# the first line tells us what the structure is;
# 4 2 3 means, take (4 sets of (2 sets of (3 items)))
@dim = split " " , <INP>;
# make @data_set a lonnng array of the rest of the stuff in the file.
while (<INP>) {
push @data_set, split;
}
my @results;
while (@data_set) {
push @results, deep_lol (\@data_set, @dim);
}
print (Dumper \@results);
sub deep_lol {
my ($data_set, @dim) = @_;
my $n = shift @dim; # here's how many thingies we need.
if (@dim) { # if there are any @dim left we should...
# get N deep_lol's with the structure
# of the lexical @dim
my @temp;
for (1..$n) {
push @temp, deep_lol( $data_set, @dim );
}
return \@temp; # and return the array ref
} else { # otherwise, we are at the last @dim item...
# shift off N dataset items,
# and return that arrayref
return [ splice (@$data_set, 0, $n) ];
}
}
__DATA__
2 1 3 4
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
--
Neil Kandalgaonkar <neil@brevity.org>
------------------------------
Date: Tue, 18 Jul 2000 00:56:11 GMT
From: jblatz2@my-deja.com
Subject: very dumb DBI question
Message-Id: <8l09v5$mlk$1@nnrp1.deja.com>
I want to access my Informix database from my perl script. I downloaded
the DBD driver and the README file says that I need DBI ver 1.13 or
later. I have absolutely no idea where to get the DBI software. I'm on
a Unix platform. Is DBI something I download? buy from Informix? buy
from our hardware vendor??
Help!
While I'm at it - where should I install DBD? I'm sure it goes in the
directory with the perl software, but exactly where? In lib?
Thanks - sorry to sound so dumb. It's actually pretty embarrassing!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 18 Jul 2000 02:32:03 GMT
From: kumar1@home.com (Prasanth A. Kumar)
Subject: Re: very dumb DBI question
Message-Id: <m3aefgcgnw.fsf@C654771-a.frmt1.sfba.home.com>
jblatz2@my-deja.com writes:
> I want to access my Informix database from my perl script. I downloaded
> the DBD driver and the README file says that I need DBI ver 1.13 or
> later. I have absolutely no idea where to get the DBI software. I'm on
> a Unix platform. Is DBI something I download? buy from Informix? buy
> from our hardware vendor??
DBI is the database independent part while DBD is the database
dependent or specific part. You can get DBI from the Perl website.
>
> Help!
>
> While I'm at it - where should I install DBD? I'm sure it goes in the
> directory with the perl software, but exactly where? In lib?
There should be a make/install script in there.
>
> Thanks - sorry to sound so dumb. It's actually pretty embarrassing!
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
--
Prasanth Kumar
kumar1@home.com
------------------------------
Date: Tue, 18 Jul 2000 02:25:43 GMT
From: scottbeck@my-deja.com
Subject: warn not working after re-opening STDERR
Message-Id: <8l0f6q$qbe$1@nnrp1.deja.com>
#!/usr/bin/perl -w
open STDSAVE, ">&STDOUT";
open ERRSAVE, ">&STDERR";
close STDOUT;
close STDERR;
print "This should not show up!\n";
open STDOUT, ">&STDSAVE";
open STDERR, ">&ERRSAVE";
print "This is stdout and you should see this!\n";
warn "This is a warn and you should see it!\n";
print STDERR "I am printing to STDERR!\n";
The warn line does not produce output to STDERR
but the print to STDERR does. Is this a bug or
a dumb mistake?
Thanks,
Scott
--
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 18 Jul 2000 02:48:19 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: warn not working after re-opening STDERR
Message-Id: <MPG.13de62c553bf1db89896e1@news>
scottbeck@my-deja.com wrote ..
>#!/usr/bin/perl -w
>open STDSAVE, ">&STDOUT";
>open ERRSAVE, ">&STDERR";
>close STDOUT;
>close STDERR;
>print "This should not show up!\n";
>
>open STDOUT, ">&STDSAVE";
>open STDERR, ">&ERRSAVE";
>print "This is stdout and you should see this!\n";
>warn "This is a warn and you should see it!\n";
>print STDERR "I am printing to STDERR!\n";
>
>
>The warn line does not produce output to STDERR
>but the print to STDERR does. Is this a bug or
>a dumb mistake?
works for me as expected with Perl 5.005_03 on WinNT .. all three lines
produce output to the console
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Tue, 18 Jul 2000 02:21:16 GMT
From: Vinod K. Menon <anuragmenon@my-deja.com>
Subject: Yet another string manipulation question -
Message-Id: <8l0euh$q1h$1@nnrp1.deja.com>
Ok..here it is... there is an input string $String1
the string is actually a code string..in the sense that there are a few
conditions about what character should come after which one.
For example, a can be followed by b or c
but, if in the input string a is not followed by b or c, I want an X
inserted between them.
Let me give an example:
One Rule says 'a' can be followed by 'b'or 'e'
Another Rule says 'c' can be followed only by 'd'
Yet another Rule is 'e' can be followed only by 'k' or 'l'
Considering those rules, if the input string is abcd, things are fine
But if the input string ad, I want the string to be made aXd
and if the input string is aece, the string should be made aeXcXe
and so on...
is there an easy function whatever in perl that can be used to achieve
this. I can do a series of "if"s to do this..but is that the best way?
any suggestions?
I hope I am somewhat clear with that problem..
do let me know..I appreciate all your help...I have to do this in perl
and am a newbie with very little time..thanks for all ur patience..
Vinod.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 18 Jul 2000 02:45:08 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: Yet another string manipulation question -
Message-Id: <MPG.13de6209e7a8d3e79896e0@news>
Vinod K. Menon wrote ..
>Ok..here it is... there is an input string $String1
>
>the string is actually a code string..in the sense that there are a few
>conditions about what character should come after which one.
>
>For example, a can be followed by b or c
>but, if in the input string a is not followed by b or c, I want an X
>inserted between them.
>
>Let me give an example:
>
>One Rule says 'a' can be followed by 'b'or 'e'
>Another Rule says 'c' can be followed only by 'd'
>Yet another Rule is 'e' can be followed only by 'k' or 'l'
my %rules = ( a => 'be', c => 'd', e => 'kl' );
my $char = 'X';
for my $key (keys %rules)
{
$String1 =~ s/$key([^$rules{$key}])/$key$char$1/g;
}
>is there an easy function whatever in perl that can be used to achieve
>this. I can do a series of "if"s to do this..but is that the best way?
>any suggestions?
a reasonably simple regex will handle those sorts of rules .. basically
the above will work with any number of those types of rules
what we're using here is a negative character class .. for the first
rule - the above regex becomes
$String1 =~ s/a([^be])/aX$1/g;
so the [^be] matches any character other than 'b' or 'e' .. and the
substitution is made .. we put capturing parens so that we can use $1 in
the substitution to put whatever character back in place
the hash is just an easy way of storing those rules - and iterating
through them
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3701
**************************************