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]#!perl[/gray][/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][link http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/link] [blue]$file[/blue] = [red]'[/red][purple]path/to/file.txt[/purple][red]'[/red][red];[/red][/li]
[li][black][b]my[/b][/black] [blue]$newline[/blue] = [red]"[/red][purple]In general, if you think something isn't in Perl, try it out, because it usually is.[/purple][red]"[/red][red];[/red] [/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]$file[/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][blue]$.[/blue] == [fuchsia]1[/fuchsia][red])[/red] [red]{[/red][/li]
[li] [link http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/link] [red]"[/red][purple][blue]$newline[/blue][blue]$/[/blue][/purple][red]"[/red][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]
[/ol]
#!perl
use strict;
use warnings;
my $file = 'path/to/file.txt';
my $newline = "In general, if you think something isn't in Perl, try it out, because it usually is.";
{
local @ARGV = ($file);
local $^I = '.bac';
while(<>){
if ($. == 1) {
print "$newline$/";
}
else {
print;
}
}
}