m

 

$ less metest.pl
use strict;
use warnings;

my $find = “this”;
my $replace = “that”;
my $substr=’Here’;
my $file = ‘data.txt’;
open my $info, $file or die “Could not open $file: $!”;

while( my $line = <$info>) {
if (index($line, $substr) != -1) {
$line=~ s/$find/$replace/g;
print $line;
}
}

close $info;

 

 

$ less data.txt
Here it is the case-1 , this can be avoided.
Here it is the case-2 , this can be avoided
Here it is the case-3
it is the case-4:

 

 

oye

my $message = <<‘END_MESSAGE’;my $message = <<‘END_MESSAGE’;this is a message .Here it is the case-1 , This can be avoided.Here it is the case-2 , This can be avoided.it is the case-3 , This can be avoided.END_MESSAGE
if (index($string, $substring) != -1) {   print “‘$string’ contains ‘$substring’\n”;} print $message;

use strict;use warnings; my $substring=’this’;my $substring2=’that’;
my $filename = ‘data.txt’;if (open(my $fh, ‘<:encoding(UTF-8)’, $filename)) {  while (my $row = <$fh>) {    chomp $row; if (index($row, $substring) != -1) { my $newString = $old =~ s/$substring/$substring2/r;   print $newString;}  }} else {  warn “Could not open file ‘$filename’ $!”;}

run vs start java

Per StackOverflow

 

 

public class StartVSRun {public static void main(String[] args) { Me  me2=new Me(); Thread me=new Thread(me2); /* me.start(); me.start(); class java.lang.Thread Exception in thread “main” java.lang.IllegalThreadStateException at java.lang.Thread.start(Unknown Source) at StartVSRun.main(StartVSRun.java:9) Picked up _JAVA_OPTIONS: -Xmx512M*/ me.run(); me.run(); System.out.println(“—————“); me.start(); //me.start(); //me.start(); //me.start();
}}
class Me implements Runnable{
@Override public void run() { System.out.println(Thread.currentThread().getName()); } }

main
main
—————
Thread-0
Picked up _JAVA_OPTIONS: -Xmx512M

 

The difference is that Thread.start() starts a thread, while Runnable.run() just calls a method.

Here run() always results in main ,start will gives thread-0,thread-1 etc.

 

up vote202down voteaccepted

First example: No multiple threads. Both execute in single (existing) thread. No thread creation.

R1 r1 = new R1();
R2 r2 = new R2();

r1 and r2 are just two different objects of the class that implements the Runnable interfaces which have that run() method. When you call r1.run() you are executing it in the current thread.

Second example: Two separate threads.

Thread t1 = new Thread(r1);
Thread t2 = new Thread(r2);

t1 and t2 are the objects of the class Thread. When you call t1.start(), it starts a new thread and calls the run() method of r1 internally to execute it within that new thread.