Help, please, convert PERL to PHP: 1)

#!/usr/bin/perl -w use strict; use 5.014; use CGI qw(:all); print "Content-Type: text/plain; charset=utf-8\n\n"; open FILE, "text.txt" or die "Cen't open file: $!"; my @fl = <FILE>; close FILE; if ( @fl [0] >= 10) { say "Hello!!!!!"; exit; } unless (param('i') == 1) { say @fl [0]; } else { open FL, ">text.txt" or die "Cen't open file: $!"; print FL @fl [0]+1; close FL; say @fl [0]+1; } 

2)

  #!/usr/bin/perl -w use strict; print "Content-Type: text/plain; charset=utf-8\n\n"; open FILE, ">text.txt" or die "Cen't open file: $!"; close FILE; print "Wozzup!"; 

    1 answer 1

    I would first of all bring your code to a normal perltidy perl.

     #1)=============== !/usr/ bin / perl -w use strict; use 5.014; use CGI qw(:all); print "Content-Type: text/plain; charset=utf-8\n\n"; open FILE, "text.txt" or die "Cen't open file: $!"; my @fl = <FILE>; close FILE; if ( @fl [0] >= 10 ) { say "Hello!!!!!"; exit; } if ( param('i') != 1 ) { say @fl [0]; } else { open FL, ">text.txt" or die "Cen't open file: $!"; print FL @fl [0] + 1; close FL; say @fl [0] + 1; } #=========== 

    and you can edit prettier

     #!/usr/ bin / perl -w use 5.014; use CGI qw(:all); use File::Slurp qw/read_file/; print "Content-Type: text/plain; charset=utf-8\n\n"; my @fl = read_file('text.txt'); my $first_line = @fl [0]; if ( $first_line >= 10 ) { say "Hello!!!!!"; exit; } if ( param('i') == 1 ) { my $next_value = $first_line + 1; write_file( 'filename', $next_value ); say $next_value; } else { say $first_line; } #=========== 

    It is also much clearer what he does. Well, then at least in php even in Java.

    Next, I think you can: Perl / Php Translation .

    I would make the final version of your counter

     #!/usr/bin/perl -w use 5.014; use CGI qw(:all); use File::Slurp qw/read_file write_file/; #use Carp; use CGI::Carp qw(fatalsToBrowser); print "Content-Type: text/plain; charset=utf-8\n\n"; my ($param) = $ARGV[0] || param('i'); #check if input parameters is correct carp("ERROR: \$param=*$param* is not defined or not number") if !defined $param || $param !~ /^\d+$/xms; my $file_name = 'text.txt'; my @fl = read_file($file_name); my $first_line = $fl[0]; say make_work( $param || 1, $file_name, $first_line ); #say make_work( param('i') || 1, $file_name, $first_line ); #say make_work( 1, $file_name, $first_line ); sub make_work { my ( $param, $file_name, $first_line ) = @_ ; given ($param) { when ('1') { write_file( $file_name, ++$first_line ); continue; } when ( $_ >= 10 ) { return 'Hello!!!!!' } default { return $first_line } } }