Author:
erics , January 17th, 2025
Have you ever found yourself frustrated when copying and pasting commands in the Apple terminal no longer behaves as expected? If you used to work with Bash on older macOS versions, you might recall that pasting a command into the terminal automatically executed it—no extra steps required. However, with the switch to Zsh as the […]
Categories: How-To's , Technology Tags: auto-return , Copy , copy-and-paste , Enter , Exec , Execute , howto , paste , Return , run , tips , zsh
| No comments
Author:
erics , March 9th, 2021
The trick to using eval to catch shell execution is to return twice, once inside the eval and once outside:
sub isMaintenance {
my $ return = eval {
my $ err = system ( "check_policy.sh | grep 'Policy is MAINTENANCE' >/dev/null 2>/dev/null" ) ;
& debug ( "perl error code: $err" ) ;
$ err = $ err / 256 ;
& debug ( "system error code: $err" ) ;
if ( $ err != 0 ) {
# Not Maintenance
if ( $ verbose ) { warn "policy is NOT MAINTENANCE\n" ; }
return 0 ;
} else { return 1 ; }
} ;
return $ return ;
}
Neat!
Categories: How-To's , Technology Tags: Code , eval , Exit , Exit Code , howto , perl , Return , System
| No comments
Author:
erics , January 11th, 2012
You must use all three lines together for it to work…YMMV:
$ escaped = str_replace ( chr ( 10 ) , '\n' , $ original_value ) ;
$ escaped = str_replace ( chr ( 13 ) , '\r' , $ escaped ) ;
$ escaped = preg_replace ( "/(\r?\n)/" , "\n" , $ escaped ) ;
Categories: How-To's , Technology Tags: Backslash , break , carriage return , control-m , Escape , javascript , JS , line break , Newline , php , Return
| No comments
Author:
erics , May 5th, 2011
my $ value = $ self -> myFunction ( ) -> { 'result' } ;
Where :
sub myFunction {
my $ self = shift ;
. . . code here . . .
return {
'status' = > 0 ,
'result' = > 'Hello World' ,
} ;
}
Categories: How-To's , Technology Tags: Hash , howto , perl , Return , Subroutine
| No comments