Anonymous user
Kernighans large earthquake problem: Difference between revisions
Kernighans large earthquake problem (view source)
Revision as of 18:15, 6 November 2018
, 5 years ago→PHP version
Line 330:
map { .say if .words[2] > 6 }, .lines;</lang>
=={{header|PHP}}==
Parse using PHP's fscanf().
<lang php><?php
// make sure filename was specified on command line
if ( ! isset( $argv[1] ) )
die( 'Data file name required' );
// open file and check for success
if ( ! $fh = fopen( $argv[1], 'r' ) )
die ( 'Cannot open file: ' . $argv[1] );
while ( list( $date, $loc, $mag ) = fscanf( $fh, "%s %s %f\n" ) ) {
if ( $mag > 6 ) {
printf( "% -12s % -19s %.1f\n", $date, $loc, $mag );
}
}
fclose( $fh );
</lang>
Usage: Specify file name on command line. Ex:
<code>php eq.php data.txt</code>
{{Out}}
<pre style="font-size:84%">
8/27/1883 Krakatoa 8.8
5/18/1980 MountStHelens 7.6
</pre>
=={{header|Phix}}==
|