Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[ol]
[li][gray]#!/usr/bin/perl[/gray][/li]
[li][/li]
[li][link http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/link] [green]strict[/green][red];[/red][/li]
[li][black][b]use[/b][/black] [green]warnings[/green][red];[/red][/li]
[li][/li]
[li][link http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/link] [blue]$filename[/blue] = [red]'[/red][purple]some_file.txt[/purple][red]'[/red][red];[/red][/li]
[li][black][b]my[/b][/black] [blue]$find[/blue] = [red]'[/red][purple]this[/purple][red]'[/red][red];[/red][/li]
[li][black][b]my[/b][/black] [blue]$replace[/blue] = [red]'[/red][purple]that[/purple][red]'[/red][red];[/red][/li]
[li][/li]
[li][red]{[/red][/li]
[li] [link http://perldoc.perl.org/functions/local.html][black][b]local[/b][/black][/link] [blue]@ARGV[/blue] = [red]([/red][blue]$filename[/blue][red])[/red][red];[/red][/li]
[li] [black][b]local[/b][/black] [blue]$^I[/blue] = [red]'[/red][purple].bac[/purple][red]'[/red][red];[/red][/li]
[li] [olive][b]while[/b][/olive][red]([/red] <> [red])[/red][red]{[/red][/li]
[li] [olive][b]if[/b][/olive][red]([/red] [red]s/[/red][purple][blue]$find[/blue][/purple][red]/[/red][purple][blue]$replace[/blue][/purple][red]/[/red][red]ig[/red] [red])[/red] [red]{[/red][/li]
[li] [link http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/link][red];[/red][/li]
[li] [red]}[/red][/li]
[li] [olive][b]else[/b][/olive] [red]{[/red][/li]
[li] [black][b]print[/b][/black][red];[/red][/li]
[li] [red]}[/red][/li]
[li] [red]}[/red][/li]
[li][red]}[/red][/li]
[li][black][b]print[/b][/black] [red]"[/red][purple]Finished[/purple][red]"[/red][red];[/red][/li]
[/ol]
#!/usr/bin/perl
use strict;
use warnings;
my $filename = 'some_file.txt';
my $find = 'this';
my $replace = 'that';
{
local @ARGV = ($filename);
local $^I = '.bac';
while( <> ){
if( s/$find/$replace/ig ) {
print;
}
else {
print;
}
}
}