可以有人解释我如何使用像sed这样的linux功能来剪切一些字符串.例如,我有刺痛
THIS-some-string-zzz-55.xml
Run Code Online (Sandbox Code Playgroud)
如何剪切".xml"?
结果应该是这样的:
THIS-some-string-zzz-55
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在编写一个脚本来从我的博客帖子中获取URL并运行curl -I
它们以便我可以检查它们是否仍然很好.但是我在编写grep模式时遇到了麻烦.
<p><a href="http://example.com/fujipol/2004/may/5/16:10:47/400x345">foobar</a></p>
Run Code Online (Sandbox Code Playgroud)
所以我想在这里http://example.com/fujipol/2004/may/5/16:10:47/400x345
.
或者在降价时:
[Example markdown link](https://example.com)
Run Code Online (Sandbox Code Playgroud)
想 https://example.com
<http://example.com/?foo=bar>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我需要 http://example.com/?foo=bar
我正在尝试使这个脚本过滤来自ps的行...它几乎完成的脚本,只有这行丢失.
例如,这是我需要过滤的一行:
803 ? (many spaces here) 00:00:00 atd
Run Code Online (Sandbox Code Playgroud)
我需要这样看起来像这样:
803 atd
Run Code Online (Sandbox Code Playgroud)
我已经尝试了所有的东西,但似乎一个简单的sed参数不能这样做..如果sed检测到必须被删除的东西,它会删除它之后的整行...如果我错了请纠正我并感谢你的时间..
目前我用
import XMonad.Layout.NoBorders
...
xmonad $ defaultConfig { layoutHook = noBorders $ layoutHook defaultConfig }
Run Code Online (Sandbox Code Playgroud)
但这会产生noBorder
所有布局,而不仅仅是" Full
".
我知道,我可以简单地layoutHook
从默认配置复制定义并noBorder
在" Full
" 之前添加,但我想要美丽的方式,希望Haskell为它提供一些方法.
有each_pair
方法允许在每次循环迭代时获得对散列:
{ 1 => "a", 2 => "b" }.each_pair do |key, value|
# do something with #{key} and #{value}
end
Run Code Online (Sandbox Code Playgroud)
如何在每次循环迭代中知道当前数组元素的索引?
array.each do |element|
# what is element index in array?
end
Run Code Online (Sandbox Code Playgroud)
使用一些递增迭代器有一个无聊的解决方案.但是迭代器应该在循环之前分配,并且应该在每次迭代时手动递增.这显然很无聊.
这将是巨大的,如果是有某种方式来压缩一些阵列,1..
阵列和得到这样的元组阵列["b", "d", "e"] ? [(1,"b"), (2,"d"), (3,"e")] and
than pattern matched each element of the pair in
| |`声明.
所以,最后,我正在寻找的是一些功能f
,即:
f(["a"]) do |index, element|
# index == 1, element == "a"
end
Run Code Online (Sandbox Code Playgroud) 我有一个使用monad-list构建函数的问题
> multab 4
["1*1=1","1*2=2","1*3=3","1*4=4","2*2=4","2*3=6","2*4=8","3*3=9","3*4=12","4*4=16"]
Run Code Online (Sandbox Code Playgroud)
所以我想开始:
multab :: Integer -> [String]
Run Code Online (Sandbox Code Playgroud)
对于其他人,你想提出任何建议吗?
提前致谢.
我写了这个小函数来检索列表的尾部:
let getTail l = if length l > 0 then tail l else "empty list"
Run Code Online (Sandbox Code Playgroud)
传递[]
给getTail
返回empty list
但传递[1,2,3]
给出以下错误:
<interactive>:1:14:
No instance for (Num Char)
arising from the literal `3'
Possible fix: add an instance declaration for (Num Char)
In the expression: 3
In the first argument of `getTail', namely `[1, 2, 3]'
In the expression: getTail [1, 2, 3]
Run Code Online (Sandbox Code Playgroud)
我无法理解那个错误意味着什么.问题是什么?使用GHCi 7.0.4
class Class
def attr_accessor_with_history(attr_name)
attr_name = attr_name.to_s
attr_reader attr_name
attr_reader attr_name + "_history"
class_eval %Q{
def #{attr_name}=(new_value)
@#{attr_name}_history = [nil] if @#{attr_name}_history.nil?
@#{attr_name}_history << @#{attr_name} = new_value
end
}
end
end
class Example
attr_accessor_with_history :foo
attr_accessor_with_history :bar
end
Run Code Online (Sandbox Code Playgroud)
有一种Class.attr_accessor_with_history
方法可以提供相同的功能,attr_accessor
但也跟踪属性所具有的每个值.
> a = Example.new; a.foo = 2; a.foo = "test"; a.foo_history
=> [nil, 2, "test"]
Run Code Online (Sandbox Code Playgroud)
但,
> a = Example.new; a.foo_history
=> nil
Run Code Online (Sandbox Code Playgroud)
它应该是[nil
.
如何initialize
为Example
每个…_history
值初始化的类
定义单个方法[nil]
?
我想调用这个函数
glShaderSource ::
GLuint
-> GLsizei
-> GHC.Ptr.Ptr (GHC.Ptr.Ptr GLchar)
-> GHC.Ptr.Ptr GLint
-> IO ()
Run Code Online (Sandbox Code Playgroud)
第三个参数是着色器程序,它是我程序中的Haskell字符串.如何将Haskell String
转换为GHC.Ptr.Ptr (GHC.Ptr.Ptr GLchar)
可以调用的glShaderSource
?