App-Cheats
view release on metacpan or search on metacpan
## Cmake
#############################################################
# Exit from cmake
return()
# Print a message in cmake
message( "PROJECT_NAME: ${PROJECT_NAME}" )
# Assign variable in cmake
set(GENERATE_OUTPUT_DIR "${CMAKE_BINARY_DIR}/src_generated/")
# Remove files from a folder using cmake
file(GLOB REMOVE_FILES "${CMAKE_BINARY_DIR}/*")
message("REMOVE_FILES: ${REMOVE_FILES}")
file(REMOVE_RECURSE ${REMOVE_FILES})
# Include submodules in *.cmake
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/tools/cmake")
include(macros_internal)
include(macros_public)
perl -E 'eval qq(# line 123 myfile.txt\ndie "My bad"); say $@'
My bad at myfile.txt line 123.
# Perl File Syntax
# When opened for reading, the special
# filename âââ refers to STDIN. When
# opened for writing, the same special
# filename refers to STDOUT.
# Normally, these are specified as â<ââ and â>ââ,
# respectively.
open(INPUT, "â" ) || die; # reâopen standard input for reading
open(INPUT, "<â") || die; # same thing, but explicit
open(OUTPUT, ">â") || die; # reâopen standard output for writing
# Can always use / for files in perl (even on DOS).
my $path = "a\b\c.txt";
my $path = "a/b/c.txt";
# Read piped output in perl.
open PIPE, "-|", "perl out.pl" or die $!;
while( my $line = <PIPE> ){
print $line;
}
#############################################################
## Perl Functions - fork
#############################################################
# Run a child in a separate process and wait for it.
perl -E 'my $PID = fork; if (!$PID){ sleep 2; say "child"; exit 0 } waitpid $PID, 0; say "parent"'
# Send data from forked child back to parent using pipes.
perl -E 'pipe(INPUT,OUTPUT); my $PID = fork; if (!$PID){ close INPUT; sleep 1; say "child"; say OUTPUT "42"; close OUTPUT; exit 0 } close OUTPUT; waitpid $PID, 0; say "parent"; my ($Data) = <INPUT>; say "[$Data]"'
# Run multiple processes and collect their data.
perl -MMojo::Util=dumper -E 'use strict; use warnings; local $| = 1; my @Wait; for my $Count (1..5){ my($In,$Out); pipe($In,$Out); my $PID = fork; if (!$PID){ close $In; sleep int(rand(5)); say "Running child $Count"; say $Out "From-$Count"; close $O...
Running child 2
Running child 3
Running child 4
Running child 5
Running child 1
parent is reading now pid: 593943
parent is reading now pid: 593944
( run in 0.350 second using v1.01-cache-2.11-cpan-4e96b696675 )