[16758] in Perl-Users-Digest
Perl-Users Digest, Issue: 4170 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 29 21:10:43 2000
Date: Tue, 29 Aug 2000 18:10:26 -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: <967597826-v9-i4170@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 29 Aug 2000 Volume: 9 Number: 4170
Today's topics:
Re: How do I manipulate each element of an array? <elephant@squirrelgroup.com>
I need help! <nedoac2@tin.it>
Re: Implementing the join relational database operation (Abigail)
Re: Is perl powerful enough to create cybermoney? (Craig Berry)
Re: Just another silly post. <madings@baladi.bmrb.wisc.edu>
Re: Just another silly post. <madings@baladi.bmrb.wisc.edu>
Re: making sure you all have the documentation <star@sonic.net>
Re: making sure you all have the documentation (Martien Verbruggen)
Re: method="get" <reich@pants.internetcds.com>
Re: method="get" (Tony L. Svanstrom)
Re: output fun <uri@sysarch.com>
Re: output fun <lr@hpl.hp.com>
Re: perl prob. <dietmar.staab@t-online.de>
Re: perl prob. <mtaylorlrim@my-deja.com>
Re: perl prob. (Robert Hallgren)
Re: Perl Temperature Grabber (Tony L. Svanstrom)
Re: Perl Temperature Grabber <lauren_smith13@hotmail.com>
Re: Problems editing text with Perl itgirl57@my-deja.com
Re: Problems editing text with Perl <lr@hpl.hp.com>
Re: reading a line from the serial port <dale@icr.com.au>
Re: reading a line from the serial port (David Efflandt)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 29 Aug 2000 23:12:07 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: How do I manipulate each element of an array?
Message-Id: <MPG.1416e0bd4634e3db989726@localhost>
Colin Keith <newsgroups@ckeith.clara.net> wrote ..
>In article <8od8tj$hd$1@qnsgh006.europe.nortel.com>, "Lincoln Marr" <lincolnmar
>>I'm having a little trouble at getting at all elements of an array at the
>>same time.... I'm no perl wizard so this is probably pretty simple.
>>
>>All I want to do is say 'foreach element of @array, if the element is empty
>>then set it to otherwise leave it as it is'.
>>
>>Simple enough??
>
>Uh huh. That's one of the advantages of Perl, its syntax is pretty English
>like, so if you understand that then you have an advantage. Translate what
>you said:
>
> foreach $element (@array){
> if($element eq ""){
> $element = ' ';
> }
> }
>
>You were only 1 word ('of') away from writing it in text :)
>Of course, if you want to show off:
>
> @array = map { $_ ? $_ : ' ' } @array;
you really shouldn't have
@array = ( '0', '', 'blah' );
@array = map { $_ ? $_ : ' ' } @array;
print "@array";
oops
[ lines exceeding 80 chars truncated ]
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Wed, 30 Aug 2000 01:29:24 +0200
From: "Nicola" <nedoac2@tin.it>
Subject: I need help!
Message-Id: <8ohh73$b2b$1@nslave2.tin.it>
I'm an Italian programmer.
I'm trying to make a webmail program, but i'm not very expert with perl
language and so i have some problems.
The first problem is this:
I'm searching for an example of a script using the modul Mime::Lite.
Does somebody can post me a simple to send some text and a file attachment?
Please help me!!!!!
I'm sorry for my english...........is it very bad???
Ciao
Nicola
------------------------------
Date: 29 Aug 2000 22:56:06 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Implementing the join relational database operation
Message-Id: <slrn8qofqm.bbg.abigail@alexandra.foad.org>
Andrei Heilper (heilper@il.ibm.com) wrote on MMDLV September MCMXCIII in
<URL:news:39ABA5DF.104AF571@il.ibm.com>:
'' I want to implement in Perl the join relational database operation.
''
'' For start, I would like to handle the simplest case.
'' The database rows are represented by array entries, where each entry is
'' separated into 2 fields - key and value - by a special character
'' (usually semicolon).
''
'' Any suggestions?
What do you have so far?
Abigail
--
:;$:=~s:
-:;another Perl Hacker
:;chop
$:;$:=~y
:;::d;print+Just.
$:;
------------------------------
Date: Tue, 29 Aug 2000 22:33:14 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Is perl powerful enough to create cybermoney?
Message-Id: <sqoeham6c5d73@corp.supernews.com>
pohanl@my-deja.com wrote:
: The future of money.
I hope said future involves more of it drifting my way. :)
: As we move into the new century, the money system is being changed.
: The value of currency is now being based on a subjective (demand
: based) rather than an objective (backed by gold) basis.
Actually, this has been practically true throughout the history of money
(since the value of gold is itself subjective), and entirely true for the
USA for most of the 20th century (since the gold standard was abandoned).
: Before, when the government prints new money, they hold the same value
: in gold in a vault somewhere.
Again, this system has not been in effect for quite a long time, in any of
the "developed" countries.
: Now, the government prints new money when inflation rate is low or loan
: interest rate is high.
This is called "monetary policy", and it's been around quite a while, too.
: The banks make money from the difference in interest rates on the loan
: (you pay higher interest, and they collect the difference between
: your rate and the rate they pay to the government).
And of course take a higher risk that you will default.
[snip]
: But have you noticed something? In the same case as the government
: making cash out of thin air, the companies are creating cash out of
: thin air.
Well, yes, in a sense. What is really being done is the creation of
capital (tangible value) out of "thin air" (the more efficient combination
and utilization of existing resources). This is what drives per-capita
economic expansion. More money is then placed in circulation to prevent
deflationary pressures.
: The government prints new money (ANY amount they want).
: Likewise, the companies creates stocks (ANY amount they want).
Well, not quite. Their are SEC limitations, exchange rules, and of course
if the numbers don't work out reasonably nobody will purchase the stock.
: Whereas the banks purchase the new money (as a loan), the public
: at large is purchasing the stocks (not a loan).
Stocks are a quasi-loan, in important ways. You are buying a share of
future profits, if any, with the risk there will be none, and get a
premium on value as a result of that risk. Mechanically it looks a lot
like a loan with variable interest and whose principal is never repaid.
But this is desperately off-topic, so I'll stop now. :)
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Every force evolves a form."
| - Shriekback
------------------------------
Date: 29 Aug 2000 23:30:47 GMT
From: Steve Mading <madings@baladi.bmrb.wisc.edu>
Subject: Re: Just another silly post.
Message-Id: <8ohh37$i52$1@news.doit.wisc.edu>
Logan Shaw <logan@cs.utexas.edu> wrote:
: That's because the former is intended as a short-hand, convenient,
: terse form whereas the second one is the full version. Actually,
: the two syntaxes are quite different since
[snip]
This is merely an explanation of how it was implemented to
be that way, not why. Inversion is unnecessary if the goal
was merely to provide a shorthand version. I can understand
the desire to make the squiggles mandatory, because of the
mess that happens when they are left out. When you have
(in C) if(expr) stmt1; and want to add a stmt2 to the body,
you might forget the squiggles and get perfectly valid syntax
that doesn't really do what you meant. But this is identical
to what you can get with Perl's inverted ifs: You could make
the exacy same mistake this way:
stmt1 if(expr); ---add a line---> stmt1; stmt2 if (expr);
This has exactly the same problem. That's why I don't buy into
"It's just so that the shorthand version is less error prone"
as the explanation for the difference.
: That's by design. I haven't personally asked him, but I have assumed
: that it was Larry Wall's contention that orthogonal grammars are
: unnatural. Human beings are best at dealing with grammars that are not
: orthogonal because the irregularity gives them context and cues as to
: what's going on.
My brain doesn't work that way. If I learn that dropping a ball
makes it fall down, I expect this behaviour to work universally,
not to suddenly change because now I'm standing on grass when
before I was standing on pavement. Orthogonal behaviour should be
the norm, with exceptions having a good, clear reason. (Like, this
time the ball didn't fall, but that's because it's been filled with
helium gas.)
:> What I want to
:>do: %outerhash{$outerkey} should refer to the inner hash at
:>that point, but the syntax won't let me do that. It insists
:>on $outerhash{$outerkey}, which then isn't interpeted as a
:>hash. This is kind of icky.
: Of course it insists on that. This is because there is no such thing
: as nested hashes. Nested hashes do not exist in Perl.
: Instead, hashes' values are allowed to be references. So, hash values
: can refer to other anonymous hashes. They don't really contain them,
: though.
That's a trivial distinction. *All* aggregates of other aggregates
in pretty much any language have to be implemented behind the scenes
as references or pointers.
: Anyway, the point is that $outerhash{$outerkey} is a reference to
: another hash. If you want to treat it like a hash and not just a
: reference to one, you have to dereference it. Putting a % in front of
: a reference will dereference it as a hash. So, you need to do this:
: %{ $outerhash{$outerkey} }
: The outer squiggly brackets are there for grouping purposes. I'm not
: sure what the operator precedence is, so I always just put them in.
: If the precedence is right, then you can do this:
: %$outerhash{$outerkey}
This never, ever worked when I tried it, and that is part of why I
was mad at Perl's syntax. This is exactly what led me to say
A hash of hashes (or a hash of references to hashes if you want to
get technical) is icky in Perl. I was unaware of the "{}" syntax
for de-referencing and casting, however. If that works, then this
makes it tolerable. I'll have to remember that and try it the next
time this comes up. Thank you.
: I'm almost certain you can do this:
: $ref = $outerhash{$outerkey};
: and have %$ref be the hash.
: I will agree that it's a little confusing that
: $outerhash{$outerkey}{$innerkey}
This never worked for me either.
: means exactly the same thing as
: $outerhash{$outerkey}->{$innerkey}
: The second one is the one that makes sense given what the data
: structures involved actually are. I guess the first is easier enough
: to type that maybe it's worth it.
: - Logan
--
-- ------------------------------------------------------------------
Steven L. Mading at BioMagResBank (BMRB). UW-Madison
Programmer/Analyst/(acting SysAdmin) mailto:madings@bmrb.wisc.edu
B1108C, Biochem Addition / 433 Babcock Dr / Madison, WI 53706-1544
------------------------------
Date: 29 Aug 2000 23:34:21 GMT
From: Steve Mading <madings@baladi.bmrb.wisc.edu>
Subject: Re: Just another silly post.
Message-Id: <8ohh9t$i52$2@news.doit.wisc.edu>
Abigail <abigail@foad.org> wrote:
: Steve Mading (madings@baladi.bmrb.wisc.edu) wrote on MMDLII September
: MCMXCIII in <URL:news:8o752v$ipq$2@news.doit.wisc.edu>:
: :: Abigail <abigail@foad.org> wrote:
: ::
: :: : No, it won't. It's a common misconception that $ matches the end of a
: :: : string. It might, but it doesn't have to. $ matches the end of a *line*.
: :: : And it can do so before a newline. Hence, ".\n" and "..\n", which are
: :: : perfectly valid filenames, will be filtered out by the grep.
: ::
: :: This is configurable behaviour that can be fixed trivially. Perl
: :: regex's can be told to match $ to end-of-string with a switch.
: You got me there. Can to tell us which switch that is? I can't find
: it in man perlrun.
This is from "man perlre", the perl regex page. In the documentation
for the switches you can put at the end of the epression (for example,
the /i for case insensitive), there is this /s switch:
s Treat string as single line. That is, change "." to
match any character whatsoever, even a newline, which
it normally would not match.
The /s and /m modifiers both override the $* setting.
That is, no matter what $* contains, /s without /m
will force "^" to match only at the beginning of the
string and "$" to match only at the end (or just
before a newline at the end) of the string. Together,
as /ms, they let the "." match any character
whatsoever, while yet allowing "^" and "$" to match,
respectively, just after and just before newlines
within the string.
------------------------------
Date: Tue, 29 Aug 2000 22:18:31 GMT
From: arthur <star@sonic.net>
Subject: Re: making sure you all have the documentation
Message-Id: <B5D0335A.76E2%star@sonic.net>
>
> There's no need to go on the net to read the documentation. All the
> documentation you need comes with Perl. After installation, I've
> 6.6 Mb of man pages. No web wowser needed.
>
>
>
> Abigail
what if you are on a Mac with MacPerl?
------------------------------
Date: Tue, 29 Aug 2000 23:04:42 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: making sure you all have the documentation
Message-Id: <slrn8qocr2.ra.mgjv@verbruggen.comdyn.com.au>
On Tue, 29 Aug 2000 22:18:31 GMT,
arthur <star@sonic.net> wrote:
[attribution to Abigail's lines were absent in post I am responding
to]
> >
> > There's no need to go on the net to read the documentation. All the
> > documentation you need comes with Perl. After installation, I've
> > 6.6 Mb of man pages. No web wowser needed.
>
> what if you are on a Mac with MacPerl?
I just learned a few days ago that on a Mac the documentation is
available with some program called Shuck IIRC. A Perl distribution
without documentation is broken.
Martien
--
Martien Verbruggen |
Interactive Media Division | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd. | enough features yet.
NSW, Australia |
------------------------------
Date: Tue, 29 Aug 2000 17:18:03 -0700
From: "Mahlon" <reich@pants.internetcds.com>
Subject: Re: method="get"
Message-Id: <39ac5299$0$2285$692ed6a5@newsread-01.meganews.com>
use CGI qw(:standard);
The CGI module handles all of this for you.
Erik <e.hofstra@student.utwente.nl> wrote in message
news:8ogjj5$4p7$1@dinkel.civ.utwente.nl...
> How can i read the values from a form that is sent
> with method="get" in Perl?
>
>
> Erik
>
>
------------------------------
Date: Wed, 30 Aug 2000 02:57:46 +0200
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: method="get"
Message-Id: <1eg5oww.q6lnq81fu86jyN%tony@svanstrom.com>
Alan J. Flavell <flavell@mail.cern.ch> wrote:
> On Tue, 29 Aug 2000, Tony L. Svanstrom wrote:
> > No, you don't search for a module when all you want is
> > $ENV{'QUERY_STRING'}
>
> Well, there's a little bit of Perl in that...
>
> But the next question is likely to be "what to do with these %xx things in
> the query string", and "what if the method is POST instead", and other
> things like that. Might as well point them at CGI.pm already. But no
> need to search CPAN for that: a version comes with any recent Perl
> installation already.
Well, you might be right, but he did ask how to get 'em in Perl; and if
he doesn't know anything about Perl then he's asked for something
knowing that he wont be able to use it... hmmm... OTOH... if he did know
know something about Perl he'd be able to search and find the answer
without asking.
Ok, Alan, you win, you're right and I'm wrong... surprise, surprise...
I'll just go and sit quietly in the corner now. ;-)
/Tony
--
/\___/\ Who would you like to read your messages today? /\___/\
\_@ @_/ Protect your privacy: <http://www.pgpi.com/> \_@ @_/
--oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
on the verge of frenzy - i think my mask of sanity is about to slip
---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
\O/ \O/ ©99-00 <http://www.svanstrom.com/?ref=news> \O/ \O/
------------------------------
Date: Tue, 29 Aug 2000 23:25:06 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: output fun
Message-Id: <x73djnsl9q.fsf@home.sysarch.com>
>>>>> "RG" == Rafael Garcia-Suarez <rgarciasuarez@free.fr> writes:
RG> ankban4@my-deja.com wrote in comp.lang.perl.misc:
>> HI
>> Without using the formatting features , how do i print an output like
>> this . i tried but my code is too huge and ugly.
>>
>> ABCDEFGFEDCBA
>> ABCDEF FEDCBA
>> ABCDE EDCBA
>> ABCD DCBA
>> ABC CBA
>> AB BA
>> A A
>>
>> Thanks for your time.
RG> $_="ABCDEFGFEDCBA\n";print;print while y/G/ /||s/(\w)( *)\1/'
RG> 'x(2+length$2)/eg;
simplified:
$_="ABCDEFGFEDCBA\n";print;print while y/G/ /||s/.( +)\S/ $1 /g;
that was the direction i was going anyway.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Tue, 29 Aug 2000 17:04:02 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: output fun
Message-Id: <MPG.1415ef4ba94891bf98acf9@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <x73djnsl9q.fsf@home.sysarch.com> on Tue, 29 Aug 2000
23:25:06 GMT, Uri Guttman <uri@sysarch.com> says...
...
> simplified:
>
> $_="ABCDEFGFEDCBA\n";print;print while y/G/ /||s/.( +)\S/ $1 /g;
Shortened:
$_="ABCDEFGFEDCBA\n";do{print}while y/G/ /||s/.( +)\S/ $1 /g;
Heh, heh, heh! Just call me 'Tiger'!
> that was the direction i was going anyway.
But not far enough. :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 30 Aug 2000 01:54:40 +0100
From: "Dietmar Staab" <dietmar.staab@t-online.de>
Subject: Re: perl prob.
Message-Id: <8ohik4$dip$16$1@news.t-online.com>
In article <39AC211E.71DA2001@byu.edu>, desi <desi@byu.edu> wrote:
> I am trying to find if the substring $items1 (a value I get from the
> text box of a form) exists in the string $data[i](0<=i<15). data is an
> array which has the item name and a price list as each element of the
> array.
Could you give an example for @data - is each element a list? If so, you
can't match a list with a string - I guess you mean $data[$i][0], but I'm
not sure.
BTW is your @data array longer than 15 items? You could even use foreach
with a condition instead of the C-like for-loop.
D.
------------------------------
Date: Wed, 30 Aug 2000 00:41:01 GMT
From: Mark <mtaylorlrim@my-deja.com>
Subject: Re: perl prob.
Message-Id: <8ohl6p$n6a$1@nnrp1.deja.com>
for each programmer in the world you will likely find a different way
of doing this...
One possible way...
@temp = grep (/$items1/,@data);
$count = @temp;
print "There are $count matches.\n\n";
foreach $line (@temp){
print $line;
}
Your way only gets the first 15. Will you always have a fixed number of
entries in @data? Just an idea for you..
Mark
In article <39AC211E.71DA2001@byu.edu>,
desi@byu.edu wrote:
> I am trying to find if the substring $items1 (a value I get from the
> text box of a form) exists in the string $data[i](0<=i<15). data is an
> array which has the item name and a price list as each element of the
> array.
> [FYI: I am doing this in Perl5]
>
> for ($i=0;$i<15;$i++)
> { if ($data[$i] =~ m/$items1/)
> { print "match ".$items1;
> }
> }
>
> Please let me know what is wrong with this or is there any alternate
way
> to do this.
>
> Thanks,
> Santosh.
>
>
--
Please reply to this newsgroup as my Deja mail
is used as a spam catcher only!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 30 Aug 2000 00:55:52 GMT
From: sandhall@swipnet.se (Robert Hallgren)
Subject: Re: perl prob.
Message-Id: <slrn8qomu9.l84.sandhall@poetry.lipogram>
On Tue, 29 Aug 2000 14:46:22 -0600, desi <desi@byu.edu> wrote:
> I am trying to find if the substring $items1 (a value I get from the
> text box of a form) exists in the string $data[i](0<=i<15). data is an
> array which has the item name and a price list as each element of the
> array.
> [FYI: I am doing this in Perl5]
>
> for ($i=0;$i<15;$i++)
> { if ($data[$i] =~ m/$items1/)
> { print "match ".$items1;
> }
> }
>
> Please let me know what is wrong with this ...
Don't know what's wrong with it. Depends on what you're trying to do. How
does this code not do what you want?
> ... or is there any aClternate way to do this.
Yes, there is. I would go for the builtin function grep[1]. Assuming
you want to evaluate each element of @data, the following code will
do the same as your code does:
print "match $items1" x grep /$items1/, @data;
We can speed it up a little (speed is perhaps not a big matter here,
but we'll do it anyway - just for fun) if $items1 is not going to
change during the iteration. We can add the o-modifier to tell Perl
only to compile the search-pattern once:
print "match $items1" x grep /$items1/o, @data;
A benchmark[2] with 1000 iterations shows:
Rate Alt 1 Alt 2 Alt 3
Alt 1 840/s -- -64% -75%
Alt 2 2326/s 177% -- -30%
Alt 3 3333/s 297% 43% --
Alt 3 is almost three times faster than the original code.
But then again - this is perhaps not what you want to do? I wouldn't
know.
[1] 'perldoc -f grep'
[2] Using the Benchmark module - 'perldoc Benchmark'
Robert
--
Robert Hallgren <sandhall@swipnet.se>
PGP: http://www.lipogram.com/pgpkey.asc
5F1E 95C2 F0D8 25A3 D1BE 0F16 D426 34BD 166A 566C
------------------------------
Date: Wed, 30 Aug 2000 00:14:02 +0200
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Perl Temperature Grabber
Message-Id: <1eg5hy3.ahoxqbpl44rN%tony@svanstrom.com>
> Posted via CNET Help.com
> http://www.help.com/
There goes the neighbourhood...
/Tony
--
/\___/\ Who would you like to read your messages today? /\___/\
\_@ @_/ Protect your privacy: <http://www.pgpi.com/> \_@ @_/
--oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
on the verge of frenzy - i think my mask of sanity is about to slip
---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
\O/ \O/ ©99-00 <http://www.svanstrom.com/?ref=news> \O/ \O/
------------------------------
Date: Tue, 29 Aug 2000 16:40:55 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: Perl Temperature Grabber
Message-Id: <8ohj6i$vpf$1@brokaw.wa.com>
Jeff <yodajeff@hotmail.com> wrote in message
news:sqoap8kvc5d45@corp.supernews.com...
> I'm looking for a perl script to get the current temperature for a pre-
> selected city or zipcode. I've seen some, but all of them retrieve more
> information then just the temperature, which is what I want. It can be
> taken from weather.com or http://iwin.nws.noaa.gov/ Just have $temp or
> something equal the current temperature. Don't worry about the output, I
> just need a code to retrieve the current temperature with $zip=90210 or
> something similar so I can configure the zip code as needed. I have the
> code ready to print it onto a screen in html format so I'll add all the
> print information. I just need a simple code to retreive the temperature
> as $temp (or something similar) for $zip, and I'll configure the rest.
>
If you have a script (or seen one that you could presumably get) that can
download *more* information than you need, wouldn't it be elementary to weed
out the stuff you don't want and keep what you do want?
$str = "The current temperature is 72 degrees";
$temp = $1 if $str =~ /The current temperature is (\d+) degrees/;
print $temp;
Lauren
--
print grep ord $_,map{y/a-zA-Z//d;$x.="+ $_";chr(eval $x)}
'J74u43-s2tA1-84n33o45th1er5-12-P3e13-82r48l21H13-a6-76
c40k25er2wx8-y6z13-81'=~m#([^!\n]{3})#g#tr/-0-9//d;print
------------------------------
Date: Tue, 29 Aug 2000 23:47:36 GMT
From: itgirl57@my-deja.com
Subject: Re: Problems editing text with Perl
Message-Id: <8ohi2h$j65$1@nnrp1.deja.com>
In article <MPG.1415b75dd0f5cab98acf3@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>
> For all the details, see:
>
> perlfaq5: "How do I change one line in a file/delete a line in a
> file/insert a line in the middle of a file/append to the beginning of
a
> file?"
Thank you VERY much for referring me to this faq. I found the solution
to my problem here.
>
> For as simple a problem as you show, a simple command will do it:
>
> Unix only:
>
> perl -pi -e 's/abc/def/g' filename
This works in a command line, but not within a script, which is where I
need it. Also, the -e option doesn't seem to work with Solaris 2.5.1.
However, the faq had another suggestion, which I use below.
Here is my revised code:
======Begin code=====
$oldtext = "abc";
$newtext = "def";
$file = "myfile";
$old = "$file";
$new = "file.tmp.$$";
open(OLD, "< $old") || die "Can't open $old: $!";
open(NEW, "> $new") || die "Can't open $new: $!";
while(<OLD>) {
s/$oldtext/$newtext/i;
(print NEW $_) || die "Can't write to $new $!";
}
close(OLD) || die "Can't close $old $!";
close(NEW) || die "Can't close $new $!";
rename($old, $bak) || die "Can't rename $old to $bak: $!";
rename($new, $old) || die "Can't rename $new to $old: $!";
=======End Code======
This WORKS, but it seems like a convoluted way to get such a simple
thing done. I can do basically the same thing with just three lines in
a shell script using sed. Do you know of a better way to do this in
Perl?
Thanks!
Itgirl
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 29 Aug 2000 17:30:16 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Problems editing text with Perl
Message-Id: <MPG.1415f5712c20690d98acfb@nntp.hpl.hp.com>
In article <8ohi2h$j65$1@nnrp1.deja.com> on Tue, 29 Aug 2000 23:47:36
GMT, itgirl57@my-deja.com <itgirl57@my-deja.com> says...
> In article <MPG.1415b75dd0f5cab98acf3@nntp.hpl.hp.com>,
> Larry Rosler <lr@hpl.hp.com> wrote:
>
> > For all the details, see:
> >
> > perlfaq5: "How do I change one line in a file/delete a line in a
> > file/insert a line in the middle of a file/append to the beginning of
> > a file?"
>
> Thank you VERY much for referring me to this faq. I found the solution
> to my problem here.
That's what the FAQs are for.
> > For as simple a problem as you show, a simple command will do it:
> >
> > Unix only:
> >
> > perl -pi -e 's/abc/def/g' filename
>
> This works in a command line, but not within a script, which is where I
> need it. Also, the -e option doesn't seem to work with Solaris 2.5.1.
> However, the faq had another suggestion, which I use below.
...
> This WORKS, but it seems like a convoluted way to get such a simple
> thing done. I can do basically the same thing with just three lines in
> a shell script using sed. Do you know of a better way to do this in
> Perl?
Yes. I showed you a one-line Perl command. What is wrong with it?
I cannot accept a statement that 'the -e option doesn't seem to work
with Solaris 2.5.1', but I can't verify it either. No one would allow
perl to be broken that badly, on any machine.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 30 Aug 2000 08:28:24 +1000
From: Dale Walker <dale@icr.com.au>
Subject: Re: reading a line from the serial port
Message-Id: <39AC3908.3560C1E6@icr.com.au>
Greg Bacon wrote:
>
> In article <39ABCA71.6595D445@icr.com.au>,
> Dale Walker <dale@icr.com.au> wrote:
>
> : Hi guys, I'm trying to read and manipulate the logging output from our
> : phone system (attached via serial port)...
>
> Have you seen the entry in Section 8 of the FAQ that deals with
> serial communication?
>
> Greg
The script I've been trying lately is based on the sample from Jamie
Zawinski in the faq.
-----------------------------------------------------------------------------
#!/usr/bin/perl -w
use IPC::Open2;
my ($cc,$dp,$ext,$num,$date,$time,$dur,$unit,$tetn,$ch,$seq);
my $stty = `/bin/stty -g`;
my $modem_device = "/dev/cuaa1" ;
open2( \*MODEM_IN, "cu -l$modem_device -s2400 2>&1");
system("/bin/stty $stty");
LINE: while (<MODEM_IN>) {
chop;
next LINE unless /^00 00/;
($cc,$dp,$ext,$num,$date,$time,$dur,$unit,$tetn,$ch,$seq) =
split / /;
print "$cc $dp $ext $num\n";
}
-------------------------------------------------------------------------------
output looks like this:
-------------------------------------------------------
root@testbed# ./test1
open2: exec of failed at ./test1 line 10
root@testbed#
--------------------------------------------------------
Any suggestions????
--
Dale Walker dale@icr.com.au
------------------------------
Date: Wed, 30 Aug 2000 00:18:09 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: reading a line from the serial port
Message-Id: <slrn8qokle.vrh.efflandt@efflandt.xnet.com>
On Wed, 30 Aug 2000 08:28:24 +1000, Dale Walker <dale@icr.com.au> wrote:
>Greg Bacon wrote:
>>
>> In article <39ABCA71.6595D445@icr.com.au>,
>> Dale Walker <dale@icr.com.au> wrote:
>>
>> : Hi guys, I'm trying to read and manipulate the logging output from our
>> : phone system (attached via serial port)...
>>
>> Have you seen the entry in Section 8 of the FAQ that deals with
>> serial communication?
>>
>> Greg
>
>The script I've been trying lately is based on the sample from Jamie
>Zawinski in the faq.
(snip)
>Any suggestions????
Have you checked out the Device::SerialPort module? I was able to talk to
a modem with it (AT commands) in Linux. It is a Unix port of
Win32::SerialPort.
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/ http://cgi-help.virtualave.net/
------------------------------
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 4170
**************************************