[22790] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5011 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 20 11:10:38 2003

Date: Tue, 20 May 2003 08:10:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 20 May 2003     Volume: 10 Number: 5011

Today's topics:
    Re: Searching and replacing strings in a file <tore@aursand.no>
    Re: Searching and replacing strings in a file (Anno Siegel)
    Re: Searching and replacing strings in a file <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: Searching and replacing strings in a file (Veky)
    Re: Searching and replacing strings in a file <kutte@uni.de>
    Re: Searching and replacing strings in a file <bigj@kamelfreund.de>
    Re: Searching and replacing strings in a file (Tad McClellan)
    Re: Searching and replacing strings in a file (Tad McClellan)
    Re: Sending email with perl. <chip@afcoms.NOSPAM.com>
    Re: Sending email with perl. <chip@afcoms.NOSPAM.com>
    Re: Sending email with perl. <chip@afcoms.NOSPAM.com>
    Re: Uppercase question <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: Uppercase question (Anno Siegel)
    Re: Uppercase question <bigj@kamelfreund.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 20 May 2003 12:58:14 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Searching and replacing strings in a file
Message-Id: <pan.2003.05.20.10.58.14.593970@aursand.no>

On Tue, 20 May 2003 02:05:19 -0700, Vinod. K wrote:
> 1.) In unix environment, I got a text file in which I need to search
> and replace a string/s. Is there any specific module or command ????

Doesn't 'cat | tr string1 string2' work as expected?


-- 
Tore Aursand <tore@aursand.no>


------------------------------

Date: 20 May 2003 11:19:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Searching and replacing strings in a file
Message-Id: <bad2vf$pph$2@mamenchi.zrz.TU-Berlin.DE>

Tore Aursand  <tore@aursand.no> wrote in comp.lang.perl.misc:
> On Tue, 20 May 2003 02:05:19 -0700, Vinod. K wrote:
> > 1.) In unix environment, I got a text file in which I need to search
> > and replace a string/s. Is there any specific module or command ????
> 
> Doesn't 'cat | tr string1 string2' work as expected?

Only if the replacement is of the limited type tr can handle.  In
general, you need sed or awk (or perl) instead.

Anno


------------------------------

Date: Tue, 20 May 2003 11:24:19 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Searching and replacing strings in a file
Message-Id: <Xns9381880C67B69elhber1lidotechnet@62.89.127.66>

Anno Siegel wrote:

> Tore Aursand  <tore@aursand.no> wrote in comp.lang.perl.misc:
>> On Tue, 20 May 2003 02:05:19 -0700, Vinod. K wrote:
>> > 1.) In unix environment, I got a text file in which I need to search
>> > and replace a string/s. Is there any specific module or command ????
>> 
>> Doesn't 'cat | tr string1 string2' work as expected?
> 
> Only if the replacement is of the limited type tr can handle.  In
> general, you need sed or awk (or perl) instead.


Shouldn't that read:


  "[...]you need Perl (or sed or awk) instead."


?


:-)


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



------------------------------

Date: Tue, 20 May 2003 11:46:46 +0000 (UTC)
From: veky@cromath.math.hr (Veky)
Subject: Re: Searching and replacing strings in a file
Message-Id: <bad4j6$vqp$1@bagan.srce.hr>

Dok je Veky citao comp.lang.perl.misc, pod PIDom 24845 (290406 off, 1 to go...),
primijetio je kreaturu zvanu pkvinu@indiatimes.com (Vinod. K),
ispod cijih su prstiju izasle (izmedu ostalih) sljedece rijeci:

|1.) In unix environment, I got a text file in which I need to search
|and replace a string/s. Is there any specific module or command ????

perl -i.bak -pe 's/str_to_find/str_to_replace/g' path_to_file

|2.) I want to create some text file which I can able to open in
|windows word application. I mean - read a input file and create output
|file which should be a word document. is this possible to create the
|word document??? and other question is - is it possible to insert a
|log into this document or any other text file ???

Formally, there is not, and there mustn't be. .doc is proprietary
Microsoft's format, specification of which is not publicly available.

-- 
\#{%	Sad gradi svoj grad iz snova... znaj da mozes i znaj da znas...


------------------------------

Date: Tue, 20 May 2003 13:32:35 +0200
From: Michael Korte <kutte@uni.de>
Subject: Re: Searching and replacing strings in a file
Message-Id: <3ECA1253.E990594A@uni.de>


"Vinod. K" schrieb:

> 1.) In unix environment, I got a text file in which I need to search
> and replace a string/s. Is there any specific module or command ????

You donīt need any module - you can use regular expr.
look at -> man perlre		# regular expressions
or      -> man perlretut	# regular expr. tutor

> 2.) I want to create some text file which I can able to open in
> windows word application. I mean - read a input file and create output
> file which should be a word document. is this possible to create the
> word document??? 

I donīt know how MS Word Documents are crypted, but you should have a
look on www.sourceforge.com.
OPEN OFFICE can handle with MS Docs, purhaps U will find  your answer
there...

>and other question is - is it possible to insert a
> log into this document or any other text file ???

of course - you can easily append something to textfiles.

open(FILEHANDLE,">> txt.txt);	# ">>" opens a file for appending

print FILEHANDLE "something";

close(FILEHANDEL);


thats it :-)

HTH
Michael korte


------------------------------

Date: Tue, 20 May 2003 12:55:10 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Searching and replacing strings in a file
Message-Id: <pan.2003.05.20.10.55.10.294545@kamelfreund.de>

Vinod. K wrote at Tue, 20 May 2003 02:05:19 -0700:

> 1.) In unix environment, I got a text file in which I need to search
> and replace a string/s. Is there any specific module or command ????

And in addition to the others,
have a look to the unix utility
sed


Greetings,
Janek


------------------------------

Date: Tue, 20 May 2003 08:28:00 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Searching and replacing strings in a file
Message-Id: <slrnbckbb0.1mo.tadmc@magna.augustmail.com>

Tore Aursand <tore@aursand.no> wrote:
> On Tue, 20 May 2003 02:05:19 -0700, Vinod. K wrote:
>> 1.) In unix environment, I got a text file in which I need to search
>> and replace a string/s. Is there any specific module or command ????
       ^^^^^^^^^^^^^^^^
       ^^^^^^^^^^^^^^^^
> Doesn't 'cat | tr string1 string2' work as expected?


tr does not replace strings.

tr replaces characters.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Tue, 20 May 2003 08:29:31 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Searching and replacing strings in a file
Message-Id: <slrnbckbdr.1mo.tadmc@magna.augustmail.com>

Vinod. K <pkvinu@indiatimes.com> wrote:

> 1.) In unix environment, I got a text file in which I need to search
> and replace a string/s. Is there any specific module or command ????


Perl FAQ, part 5:

      "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?"


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Tue, 20 May 2003 12:42:20 GMT
From: "Chip" <chip@afcoms.NOSPAM.com>
Subject: Re: Sending email with perl.
Message-Id: <Mopya.52$bO6.117807@news1.news.adelphia.net>

Hi Eric,

Yes that was what I was thinking, and trying.

Could not get open() to work so I went with Mail::Sendmail
and it works fine.

I read the perldoc -f open but did not realy understand how it
would work.  Can you explain it a little beter for me?

I would prefer to not use a module and just program it
in the script if possible.

Thanks
Chip

"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
news:Xns93813AF26470Csdn.comcast@216.166.71.239...
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> "Chip" <chip@afcoms.NOSPAM.com> wrote in news:4Bgya.1313$7S2.1028589
> @news1.news.adelphia.net:
>
> > I am trying to have a simple script email me when a
> > server is not responding to ping.
> >
> > I can run mailx from the command line and it works
> > fine but the script never sends mail.
>
>
> >             system("mailx administrator@host.com", "Alert", "Server $_
is
> > down", ".", " ");
>
>
> So read the documentation on system().  Additional arguments to system()
> are not passed on stdin, if that's what you're thinking.`
>
> Try using open(), with the | character.  open("mailx you@there.com |").
> See 'perldoc -f open' for details.
>
> - -- 
> Eric
> print scalar reverse sort qw p ekca lre reh
> ts uJ p, $/.r, map $_.$", qw e p h tona e;
>
> -----BEGIN xxx SIGNATURE-----
> Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
>
> iQA/AwUBPsn5t2PeouIeTNHoEQIeIQCeMIurAyDB/T2fjbCbZdSlBWcWqlsAmQHD
> CcT3m8RGvvrPApXOQl6gnHei
> =9BVF
> -----END PGP SIGNATURE-----




------------------------------

Date: Tue, 20 May 2003 12:43:37 GMT
From: "Chip" <chip@afcoms.NOSPAM.com>
Subject: Re: Sending email with perl.
Message-Id: <Zppya.53$bO6.118450@news1.news.adelphia.net>

Thanks Rodney,

Went with Mail::Sendmail.

Chip
"Rodney" <palladium@spinn.net> wrote in message
news:vcj95q6k95fn8d@corp.supernews.com...
> "Chip" <chip@afcoms.NOSPAM.com> wrote in message
> news:4Bgya.1313$7S2.1028589@news1.news.adelphia.net...
> > I am trying to have a simple script email me when a
> > server is not responding to ping.
> >
> > I can run mailx from the command line and it works
> > fine but the script never sends mail.
> >
> > I also tried Net::smtp with no luck.
> >
> >
> >
> > #!/usr/bin/perl
> > #
> > use Net::Ping;
> >
> > @hosts = ("192.168.0.1", "192.168.0.2", "192.168.0.3");
> >
> > while (1)
> >   {
> >     $p = Net::Ping->new();
> >     foreach (@hosts)
> >       {
> >         if ($p->ping($_))
> >           {
> >             print "$_ is alive\n";
> >           }
> >         else
> >           {
> >             print "$_ is DOWN!.\n";
> >             system("mailx administrator@host.com", "Alert", "Server $_
is
> > down", ".", " ");
> >           }
> >         $p->close();
> >         sleep 15;
> >       }
> >   }
> >
> > Any and all help is greatly appriceated,
> > Chip
> >
> >
> How about Mail::Mailer or Net::SMTP ?
>
>
>




------------------------------

Date: Tue, 20 May 2003 12:45:14 GMT
From: "Chip" <chip@afcoms.NOSPAM.com>
Subject: Re: Sending email with perl.
Message-Id: <urpya.60$bO6.118430@news1.news.adelphia.net>

Thanks Andrew,

I tried this one but it did not work for me.

I have only used mailx on my Slackware box before.

Chip
"Andrew Rich" <andrew.rich@bigpond.com> wrote in message
news:pan.2003.05.20.06.18.04.557063@bigpond.com...
> #!/usr/bin/perl
>     use Net::Ping;
>     $host="192.168.0.3";
>     $p = Net::Ping->new();
>     if ($p->ping($host))
>     {
>     print "$host is alive.\n";
>     }
>     else
>     {
>     system ("mail -v -s HOST_DOWN email@address");
>     }
>     $p->close();
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> #!/usr/bin/perl
> foreach my $file (<*.pl>)
> {
> next unless -f $file;
> open FILE, $file or die "Can not open $file $!\n";
> print "Processing ".$file." ......\n";
> system ("mail -v -s $file email@address < $file ");
> system ("mail -v -s $file email@address < $file ");
> sleep 2;
> }
>




------------------------------

Date: Tue, 20 May 2003 10:06:46 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Uppercase question
Message-Id: <Xns93817AE6E3B6Belhber1lidotechnet@62.89.127.66>

Jon Rogers wrote:

> Hello
> 
> $name="jonathan";
> 
> If I want to make the first - and only the first - letter uppercase, is
> there an easier way than splitting into array, 'uc' array[0], and then
> join again?


perldoc -f ucfirst


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



------------------------------

Date: 20 May 2003 10:10:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Uppercase question
Message-Id: <bacuvf$jsd$4@mamenchi.zrz.TU-Berlin.DE>

Jon Rogers  <jon@rogers.tv> wrote in comp.lang.perl.misc:
> Hello
> 
> $name="jonathan";
> 
> If I want to make the first - and only the first - letter uppercase, is
> there an easier way than splitting into array, 'uc' array[0], and then
> join again?

It's probably simpler to use substr() or a regex to isolate the first
character.  However, there's ucfirst() which does exactly what you want.

Anno


------------------------------

Date: Tue, 20 May 2003 09:25:01 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Uppercase question
Message-Id: <pan.2003.05.20.07.25.01.950654@kamelfreund.de>

Jon Rogers wrote at Tue, 20 May 2003 12:13:31 +0200:

> $name="jonathan";
> 
> If I want to make the first - and only the first - letter uppercase, is
> there an easier way than splitting into array, 'uc' array[0], and then
> join again?

perldoc -f ucfirst


Greetings,
Janek


------------------------------

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 5011
***************************************


home help back first fref pref prev next nref lref last post