class interface PERLISH
feature(s) from PERLISH
-- {PERLISH}
prefix "#<>": STRING
-- emulates the Perl diamond operator <>. Command line arguments
-- are treated as input file names and read a line at a time.
-- Seamlessly transitions from one file to the next. If there are
-- no command line arguments, data will be read from std_input.
--
-- If input is pending, #<> returns a string representing the
-- current line. As a side effect, #<> sets the reference
-- returned by #$_.
-- Else returns Void.
-- As a prefix operator, #<> needs to precede a PERLISH object
-- such as the feature "p".
-- To test for success and not actually get the string,
-- compare the return value with Void.
-- Unlike the Perl <> operator, EOL character(s) are stripped off.
-- Sometimes this is a good, thing, sometimes not.
--
-- example: this loop implements a simple-minded cat program.
-- from
-- until
-- #<> p = Void
-- loop
-- print(#$_ p + "%N")
-- end
ensure
Result /= Void implies last_string.is_equal(Result)
prefix "#": STRING
-- If std_input text is pending, return a string representing the
-- current line. Sets the ref returned by #$_ as a side
-- effect.
-- Else returns void
-- Similar to #<> in needing an object like "p" to prefix and in
-- its handling of EOL characters.
ensure
Result /= Void implies last_string.is_equal(Result)
infix "#=~" (args: COLLECTION[STRING]): BOOLEAN
-- #=~ implements a rough equivalent of the Perl =~
-- operator. Expects two arguments. The first is a
-- pattern to match. The second is a target for
-- the pattern. If the second argument is Void or not
-- present, the value from #$_ is used as the target.
-- Example:
-- if ( p #=~ ( << "bark", # p >> )) then
-- print ("Dog, be quiet.%N")
-- end
require
args.count >= 1;
args.first /= Void
prefix "#$_": STRING
-- #$_ is equivalent, roughly, to the the Perl variable $_
-- It references the last string read by the diamond operators
-- #<> or # above.
--
-- It also needs to prefix a PERLISH object.
-- See the simple cat loop above for an example
infix "#s/" (args: TUPLE[STRING,STRING,STRING]): STRING
-- #s/ implements simple string substitution.
-- It's meant to be equivalent to the Perl operation
-- s/old pattern/replacement text/
-- Here the arguments are supposed to be:
-- first => old pattern
-- second => replacement text
-- third => target string.
-- If the third parameter is void, the reference from #$_
-- is used.
-- The result of the replacement is returned.
require
valid_args: args.first /= Void and args.second /= Void
glob (path: STRING): ARRAY[STRING]
-- glob
-- Emulation of the Perl glob function. Given a path
-- that may contain wild cards, return an array of all
-- files that match.
chomp (input_string: STRING)
-- emulate the Perl chomp function. Strip EOL characters
-- from the end of a string.
--
-- chomp is less useful than you might expect.
-- Std eiffel library conventions automatically stripe EOL
-- characters when performing line by line input. But it is
-- relatively easy to implement.
require
has_target: input_string /= Void or else #$_ Current /= Void
infix "#-d" (path: STRING): BOOLEAN
-- Implement the -d test for a path name.
-- returns true if the path resolves to a directory.
-- Example:
-- if p #-d "c:\program files" then
-- print ("Program files exist!%N")
-- end
require
valid_path: path /= Void
infix "#-f" (path: STRING): BOOLEAN
-- implements the -f test for a path name.
-- Returns true if the path resolves to a plain file.
-- Example
-- if p #-f "c:\autoexec.bat" then
-- print ("Found autoexec.bat!%N")
-- end
require
valid_path: path /= Void and then path.count > 0
infix "#-M" (path: STRING): DOUBLE
-- Implements the -M operation, returning
-- the age of a file as a DOUBLE representation
-- of the number of days. Twelve hours would equal 0.5
-- Example:
-- if ( #-M path) > 7.0 then
-- print ("This " + path + " is getting really old%N")
-- end
--
require
path /= Void and then file_exists(path)
is_directory (path: STRING): BOOLEAN
-- is_directory returns true if the input path
-- resolves to a directory.
-- A more Eiffel-like implementation of the
-- #-d operator
require
valid_path: path /= Void and then path.count >= 1
p: PERLISH
-- provide a convenient placeholder for prefix
-- and infix perlish operators
-- Example: substitute all occurences of "for"
-- with "rof"
-- from
-- until #<> p = Void -- prefix usage
-- loop
-- -- infix #s/ usage, followed by prefix #$_ useage
-- print ( p #s/ ([ "for", "orf", #$_ p ]) + "%N")
-- end
replace (target, pattern, replacement: STRING)
-- A more eiffel-like interface for string
-- substitution. This version modifies the input
-- target.
-- Example
-- foo := clone ("This is a test")
-- replace (foo, "\ba\b", "my")
-- print (foo + "%N") -- prints "This is my test%N"
sub (target, pattern, replacement: STRING): STRING
-- preform a replacement, but keep the input string intact
get_new_system (cmd: STRING): PERLISH_SYSTEM
-- make a new Perlish system class that can have
-- redirection set, and execution started, by the
--client.
open_new_system (cmd: STRING): PERLISH_SYSTEM
-- make a new Perlish system class that runs
-- immediately, using "|" notation to denote
-- I/O redirection of the child.
end of PERLISH