[Perl] Re: QUESTION

Ido Trivizki ido at hotmail.com
Thu Jun 6 14:49:10 PDT 2002


You could use inplace editting not only from the prompt using the -i
switch - You should use the $^I variable:
#!perl -w
use strict;
($^I, at ARGV)=('.bak','Temp.c');
while(<>){s/Einat/Shalom/g}continue{print}


----- Original Message -----
From: <perl-request at perl.org.il>
To: <perl at perl.org.il>
Sent: Thursday, June 06, 2002 11:01 AM
Subject: Perl digest, Vol 1 #76 - 2 msgs


> Send Perl mailing list submissions to
> perl at perl.org.il
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://www.perl.org.il/cgi/listinfo/perl
> or, via email, send a message with subject or body 'help' to
> perl-request at perl.org.il
>
> You can reach the person managing the list at
> perl-admin at perl.org.il
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Perl digest..."
>
>
> Today's Topics:
>
>    1. RE:  Question (Einat Wizeman)
>    2. Re: RE:  Question (Gabor Szabo)
>
> --__--__--
>
> Message: 1
> From: Einat Wizeman <EINATWI at Amdocs.com>
> To: perl at perl.org.il
> Date: Wed, 5 Jun 2002 10:18:22 +0200
> Subject: [Perl] RE:  Question
> Reply-To: perl at perl.org.il
>
> --=_IS_MIME_Boundary
> Content-Type: multipart/alternative;
> boundary="----_=_NextPart_001_01C20C69.8EFB52D0"
>
> This message is in MIME format. Since your mail reader does not understand
> this format, some or all of this message may not be legible.
>
> ------_=_NextPart_001_01C20C69.8EFB52D0
> Content-Type: text/plain;
> charset="iso-8859-1"
>
> Thanks ,
>
>
> But I don't need it from the unix prompt , I can use simple sed for that .
>
> I need to write in a simple script in perl .
>
> Can you help ?
>
> Thanks
>
> >  -----Original Message-----
> > From: Einat Wizeman
> > Sent: Tuesday, June 04, 2002 2:59 PM
> > To: 'perl at perl.org.il'
> > Subject: Question
> >
> >
> >
> > Hi ,
> >
> >
> > I would like to know how can I replace one string to another  in a
> > file
> >
> >
> > For example:
> >
> > Temp.c        ----->        Temp.c
> >
> > Print "Einat";               Print "Shalom";
> >
> >
> > Thanks in advance !!!!
> >
> > Einat
>
> ------_=_NextPart_001_01C20C69.8EFB52D0
> Content-Type: text/html;
> charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
> <HTML>
> <HEAD>
> <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
> charset=3Diso-8859-1">
> <META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
> 5.5.2653.12">
> <TITLE>RE:  Question</TITLE>
> </HEAD>
> <BODY>
>
> <P><FONT COLOR=3D"#000080" FACE=3D"Bookman Old Style">Thanks ,</FONT>
> </P>
> <BR>
>
> <P><FONT COLOR=3D"#000080" FACE=3D"Bookman Old Style">But I don't need =
> it from the unix prompt , I can use simple sed for that .</FONT>
> </P>
>
> <P><FONT COLOR=3D"#000080" FACE=3D"Bookman Old Style">I need to write =
> in a simple script in perl .</FONT>
> </P>
>
> <P><FONT COLOR=3D"#000080" FACE=3D"Bookman Old Style">Can you help =
> ?</FONT>
> </P>
>
> <P><FONT COLOR=3D"#000080" FACE=3D"Bookman Old Style">Thanks </FONT>
> </P>
> <UL>
> <P><FONT FACE=3D"Bookman Old Style"></FONT>&nbsp;<FONT SIZE=3D1 =
> FACE=3D"Tahoma">-----Original Message-----</FONT>
> <BR><B><FONT SIZE=3D1 FACE=3D"Tahoma">From: &nbsp;</FONT></B> <FONT =
> SIZE=3D1 FACE=3D"Tahoma">Einat Wizeman&nbsp; </FONT>
> <BR><B><FONT SIZE=3D1 FACE=3D"Tahoma">Sent:&nbsp;&nbsp;</FONT></B> =
> <FONT SIZE=3D1 FACE=3D"Tahoma">Tuesday, June 04, 2002 2:59 PM</FONT>
> <BR><B><FONT SIZE=3D1 =
> FACE=3D"Tahoma">To:&nbsp;&nbsp;&nbsp;&nbsp;</FONT></B> <FONT SIZE=3D1 =
> FACE=3D"Tahoma">'perl at perl.org.il'</FONT>
> <BR><B><FONT SIZE=3D1 =
> FACE=3D"Tahoma">Subject:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT=
> ></B>&nbsp;<FONT SIZE=3D1 FACE=3D"Tahoma"> Question</FONT>
> </P>
> <BR>
> <BR>
> <UL>
> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR=3D"#000080" =
> FACE=3D"Bookman Old Style">Hi ,</FONT>
> </P>
> <BR>
>
> <P><FONT COLOR=3D"#000080" FACE=3D"Bookman Old Style">I would like to =
> know how can I replace one string to another&nbsp; in a file </FONT>
> </P>
> <BR>
>
> <P><FONT COLOR=3D"#000080" FACE=3D"Bookman Old Style">For =
> example:</FONT>
> </P>
>
> <P><U><FONT COLOR=3D"#000080" FACE=3D"Bookman Old =
> Style">Temp.c</FONT></U> <FONT COLOR=3D"#000080" FACE=3D"Bookman Old =
> Style">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
> -----&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT><U> <FONT =
> COLOR=3D"#000080" FACE=3D"Bookman Old Style">Temp.c</FONT></U><FONT =
> COLOR=3D"#000080" FACE=3D"Bookman Old Style"> </FONT>
> </P>
>
> <P><FONT COLOR=3D"#000080" FACE=3D"Bookman Old Style">Print =
> &quot;Einat&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Print &quot;Shalom&quot;;</FONT>
> <BR><FONT COLOR=3D"#000080" FACE=3D"Bookman Old Style">&nbsp;</FONT>
> </P>
>
> <P><FONT COLOR=3D"#000080" FACE=3D"Bookman Old Style">Thanks in advance =
> !!!!</FONT>
> </P>
>
> <P><FONT COLOR=3D"#000080" FACE=3D"Bookman Old Style">Einat </FONT>
> </P>
> </UL></UL>
> </BODY>
> </HTML>
> ------_=_NextPart_001_01C20C69.8EFB52D0--
> --=_IS_MIME_Boundary
> Content-Type: text/plain;charset=us-ascii
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
>
> --------------------------------------------------------------------------
-----------
>
> The information contained in this message is proprietary of Amdocs,
>
> protected from disclosure, and may be privileged.
>
> The information is intended to be conveyed only to the designated
recipient(s)
>
> of the message. If the reader of this message is not the intended
recipient,
>
> you are hereby notified that any dissemination, use, distribution or
copying of
>
> this communication is strictly prohibited and may be unlawful.
>
> If you have received this communication in error, please notify us
immediately
>
> by replying to the message and deleting it from your computer.
>
> Thank you.
>
> --------------------------------------------------------------------------
-----------
>
> --=_IS_MIME_Boundary--
>
> --__--__--
>
> Message: 2
> Date: Wed, 5 Jun 2002 13:29:27 +0300 (IDT)
> From: Gabor Szabo <gabor at tracert.com>
> To: <perl at perl.org.il>
> Subject: Re: [Perl] RE:  Question
> Reply-To: perl at perl.org.il
>
> >
> > But I don't need it from the unix prompt , I can use simple sed for that
.
> >
> > I need to write in a simple script in perl .
> >
> > Can you help ?
> Sure though if you look at the documentation I mentioned
> I think you can already write it.
>
> Here is one solution.
>
> $filename = "Temp.c";  # holds the name of your file where do you get it
> from ?
>
> open FILE, "< $filename" or die "Cannot open $filename\n";
> @lines = <FILE>;
> close FILE;
>
> open FILE, "> $filename" or die "Cannot open $filename to write\n";
> foreach $line (@lines) {
>   $line =~ s/Einat/Shalom/g;
>   print FILE $line;
> }
> close FILE;
>
> -- Gabor
>
>
>
> --__--__--
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://www.perl.org.il/cgi/listinfo/perl
>
>
> End of Perl Digest
>



More information about the Perl mailing list