Sponsored Content
Top Forums Shell Programming and Scripting Replacement of sentence in perl Post 302264862 by otheus on Friday 5th of December 2008 04:17:31 AM
Old 12-05-2008
You were close. I think this should work.
Code:
for (my $i=0; $i <= $#arr1; ++$i) 
{
		if($arr1[ $i ] eq $arr2[ $i ])
                {
                      print "<br> $i matched <br>";
                }
                else { 
                      $arr1[ $i ] = $arr3[ $i ];
                      print "<br> $i replaced <br>";
		}
}
foreach $str1 (@arr1) { 
	print "<br> *** $str1 <br>";
}

If you want to use foreach () then you should also shift @arr2 each time.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

String Replacement with Perl

I want to replace a string within a file using perl. We have a line that gets commented out, and I want to replace that line now matter how it was commented out. for example, I'd want to replace ###ES=PR1A with ES=PR1A or ##LJW(9/16/26)ES=PR1A with ES=PR1A I tried: perl... (4 Replies)
Discussion started by: Lindarella
4 Replies

2. Shell Programming and Scripting

Replacement of sed with perl

Hi using the below cmd i am identifying wheether last character in each line in thousands of files as semicolon or not.If last character is semicolon i am removing semicolon .If last character is not semicolon then i am appending next line to present line . For example my input file consists of... (4 Replies)
Discussion started by: dbsurf
4 Replies

3. Shell Programming and Scripting

Replacement for eval in Perl??????

I used the eval command in shell programming for assigning a value to a stored value of a variable. Example: VAR="Unix_Id" eval $VAR="101" eval echo $"$VAR" How can i assign a value to a stored value of a variable in perl OR how i can write above code in Perl? I need your help... (4 Replies)
Discussion started by: kunal_dixit
4 Replies

4. Shell Programming and Scripting

perl as awk replacement in a script.

Hey all, Im trying to write a script on windows, which Im not too familiar with. Im generally a bash scripting guy but am using perl for this case. My question is... I have this exact output: 2 Dir(s) 6,380,429,312 bytes free and I just need to get the number out... (4 Replies)
Discussion started by: trey85stang
4 Replies

5. Shell Programming and Scripting

How to remove duplicate sentence/string in perl?

Hi, I have two strings like this in an array: For example: @a=("Brain aging is associated with a progressive imbalance between intracellular concentration of Reactive Oxygen Species","Brain aging is associated with a progressive imbalance between intracellular concentration of Reactive... (9 Replies)
Discussion started by: vanitham
9 Replies

6. UNIX for Dummies Questions & Answers

Script to ask for a sentence and then count number of spaces in the sentence

Hi People, I need some Help to write a unix script that asks for a sentence to be typed out then with the sentence. Counts the number of spaces within the sentence and then echo's out "The Number Of Spaces In The Sentence is 4" as a example Thanks Danielle (12 Replies)
Discussion started by: charlie101208
12 Replies

7. Shell Programming and Scripting

need a perl replacement for this double for loop

hi everybody, can you help me with this? important: it has to be a pure perl code. zz.lis: accessibility arabic archivers astro audio benchmarks . . . "ls accessibility | grep -v Makefile" outputs accerciser at-poke at-spi at-spi-reference (6 Replies)
Discussion started by: pseudocoder
6 Replies

8. Shell Programming and Scripting

Perl Array Elements Replacement

Hello, I have the following perl array: @longname = (Fasthernet0/0 Fasthernet0/1 Serial0/1/0 Serial0/2/1 Tunnel55 Tunnel77) with the followinh array: @shortname = (Fa0/0 Fa0/1 Se0/1/0 Se0/2/1 Tu55 Tu77) in other words, I need to remove the following from each element in the array... (4 Replies)
Discussion started by: ahmed_zaher
4 Replies

9. Shell Programming and Scripting

Word replacement in Perl

I have the following string : Cat dog fox catepillar bear foxy I need to replace "cat" and "fox" words from this sentence to word "animal" I do the following: $Str1="cat"; $Str2="fox"; $NewStr="animal"; open(F1, "<$inputFile") or die "Error: $!"; open(F2, ">$outputFile") or... (1 Reply)
Discussion started by: AIX_30
1 Replies

10. Shell Programming and Scripting

Sentence delimiter in perl: modifications needed

Hello, I found this Perl Script on the EuroParl website which does Sentence Splitting. #!/usr/bin/perl -w # Based on Preprocessor written by Philipp Koehn binmode(STDIN, ":utf8"); binmode(STDOUT, ":utf8"); binmode(STDERR, ":utf8"); use FindBin qw($Bin); use strict; my $mydir =... (0 Replies)
Discussion started by: gimley
0 Replies
CLOSE(2)							System Calls Manual							  CLOSE(2)

NAME
close - delete a descriptor SYNOPSIS
close(d) int d; DESCRIPTION
The close call deletes a descriptor from the per-process object reference table. If this is the last reference to the underlying object, then it will be deactivated. For example, on the last close of a file the current seek pointer associated with the file is lost; on the last close of a socket(2) associated naming information and queued data are discarded; on the last close of a file holding an advisory lock the lock is released (see further flock(2)). A close of all of a process's descriptors is automatic on exit, but since there is a limit on the number of active descriptors per process, close is necessary for programs that deal with many descriptors. When a process forks (see fork(2)), all descriptors for the new child process reference the same objects as they did in the parent before the fork. If a new process is then to be run using execve(2), the process would normally inherit these descriptors. Most of the descrip- tors can be rearranged with dup2(2) or deleted with close before the execve is attempted, but if some of these descriptors will still be needed if the execve fails, it is necessary to arrange for them to be closed if the execve succeeds. For this reason, the call ``fcntl(d, F_SETFD, 1)'' is provided, which arranges that a descriptor will be closed after a successful execve; the call ``fcntl(d, F_SETFD, 0)'' restores the default, which is to not close the descriptor. RETURN VALUE
Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and the global integer variable errno is set to indicate the error. ERRORS
Close will fail if: [EBADF] D is not an active descriptor. SEE ALSO
accept(2), flock(2), open(2), pipe(2), socket(2), socketpair(2), execve(2), fcntl(2) 4th Berkeley Distribution May 22, 1986 CLOSE(2)
All times are GMT -4. The time now is 07:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy