小编ar.*_*dll的帖子

Perl正则表达式替换相同的情况

如果你在perl中有一个简单的正则表达式替换,如下所示:

($line =~ s/JAM/AAA/g){
Run Code Online (Sandbox Code Playgroud)

我将如何修改它以便它查看匹配并使替换与匹配的情况相同,例如:

'JAM'将成为'AAA','jam'将成为'aaa'

regex perl replace case

7
推荐指数
1
解决办法
1548
查看次数

perl if line匹配正则表达式,忽略行并移动到文件中的下一行

你会如何在perl中执行以下操作:

for $line (@lines) {
    if ($line =~ m/ImportantLineNotToBeChanged/){
        #break out of the for loop, move onto the next line of the file being processed
        #start the loop again
    }
    if ($line =~ s/SUMMER/WINTER/g){
        print ".";
    }
}
Run Code Online (Sandbox Code Playgroud)

更新以显示更多代码,这是我正在尝试做的事情:

sub ChangeSeason(){

    if (-f and /.log?/) {
        $file = $_;
        open FILE, $file;
        @lines = <FILE>;
        close FILE;

        for $line (@lines) {
            if ($line =~ m/'?Don't touch this line'?/) {
                last;
            }
            if ($line =~ m/'?Or this line'?/){
                last;
            }
            if …
Run Code Online (Sandbox Code Playgroud)

perl ignore line

6
推荐指数
3
解决办法
5万
查看次数

调试 Azure Function - 未找到 VoidMethodInvoker.cs

在此输入图像描述

每当我尝试在 VS2017 中调试 azure 函数时,我都会收到此消息,但我不明白为什么。

任何意见或帮助表示赞赏。

它似乎正在寻找某种天蓝色的网络作业库:

在此输入图像描述

azure azure-functions

6
推荐指数
1
解决办法
5113
查看次数


Powershell解析包含冒号的属性文件

如果我有一个包含目录(包含冒号)的.properties文件:

some_dir=f:\some\dir\etc
another_dir=d:\dir\some\bin
Run Code Online (Sandbox Code Playgroud)

然后使用ConvertFrom-StringData将Key = Value对从所述属性文件转换为哈希表:

$props_file = Get-Content "F:\dir\etc\props.properties"
$props = ConvertFrom-StringData ($props_file)
$the_dir = $props.'some_dir'
Write-Host $the_dir
Run Code Online (Sandbox Code Playgroud)

Powershell抛出一个错误(不喜欢冒号):

ConvertFrom-StringData : Cannot convert 'System.Object[]' to the type 'System.String'    required by parameter 'StringData'. Specified method is not supported.
At line:3 char:32
+ $props = ConvertFrom-StringData <<<<  ($props_file)
+ CategoryInfo          : InvalidArgument: (:) [ConvertFrom-StringData],     ParameterBindingException
+ FullyQualifiedErrorId :     CannotConvertArgument,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand
Run Code Online (Sandbox Code Playgroud)

你怎么绕这个?我希望能够使用它来引用目录.符号:

$props.'some_dir'
Run Code Online (Sandbox Code Playgroud)

powershell hashtable properties-file

5
推荐指数
1
解决办法
6314
查看次数

使用powershell在注册表项中获取特定字符串值的值

使用以下powershell脚本:

Get-ChildItem hkcu:\Test\Universe\Datawink\Switch1\Devices | ForEach-Object {Get-ItemProperty $_.pspath}
Run Code Online (Sandbox Code Playgroud)

我能够得到以下输出:

PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Test\Universe\Datawink\Switch1\Devices\Entry1
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Test\Universe\Datawink\Switch1\Devices
PSChildName  : Entry1
PSProvider   : Microsoft.PowerShell.Core\Registry
Device       : 2882881001
Recordable   : Yes
Active       : Yes

PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Test\Universe\Datawink\Switch1\Devices\Entry2
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Test\Universe\Datawink\Switch1\Devices
PSChildName  : Entry2
PSProvider   : Microsoft.PowerShell.Core\Registry
Device       : 2882881002

PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Test\Universe\Datawink\Switch1\Devices\Entry3
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Test\Universe\Datawink\Switch1\Devices
PSChildName  : Entry3
PSProvider   : Microsoft.PowerShell.Core\Registry
Device       : 2882881003
Run Code Online (Sandbox Code Playgroud)

哪个好,它向我显示了我想要的信息,但我真正需要的是名为'Device'的字符串条目的值,所以我真正想要的是脚本的输出如下所示:

Device       : 2882881001
Device       : 2882881002
Device       : 2882881003
Run Code Online (Sandbox Code Playgroud)

或理想情况下,这:

2882881001
2882881002
2882881003
Run Code Online (Sandbox Code Playgroud)

实现这一目标的最简单方法是什么?

registry powershell key

2
推荐指数
1
解决办法
2万
查看次数

AWK,Perl还是Shell?3列数据文件中的唯一字符串及其最大值

我有一个包含如下数据的文件:

2012-01-02 GREEN 4
2012-01-02 GREEN 6
2012-01-02 GREEN 7
2012-01-02 BLUE 4
2012-01-02 BLUE 3
2012-01-02 GREEN 4
2012-01-02 RED 4
2012-01-02 RED 8
2012-01-02 GREEN 4
2012-01-02 YELLOW 5
2012-01-02 YELLOW 2
Run Code Online (Sandbox Code Playgroud)

我不能总是预测第二列中的字符串是什么(所以在上面的例子中有颜色,但数据文件可以包含第二列中的任何字符串).但是在第三列中总是有一个数字(我希望第二列中的特定字符串的最大值).是不是能够:

  1. 拉出第2列中的每个独特字符串?
  2. 对于每个唯一的字符串,获得最大的相关值(所以使用上面的内容,你最终得到以下内容)?:

    2012-01-02 GREEN 7
    2012-01-02 BLUE 4
    2012-01-02 RED 8
    2012-01-02 YELLOW 5
    
    Run Code Online (Sandbox Code Playgroud)

或者使用Perl(甚至是shell)会更容易吗?任何代码示例非常感谢!

string shell perl awk unique

2
推荐指数
2
解决办法
1018
查看次数

在面向对象编程中复制对象的目的是什么?

我已经学习 c# 大约 3 个月了,今天我遇到的一件事是对象上的深拷贝和浅拷贝构造函数的概念(刚刚习惯了基类、继承和实例化的概念——多态性仍然没有)老实说,它真的沉没了......我离题了)。

当看到基类(在本例中为用户类)上的深度复制构造函数时,我的第一个想法是“你到底为什么要复制一个对象?”。我看过的文章解释了如何做以及它是如何工作的,但我仍然无法找到任何实际示例来说明为什么要这样做。如果我有一个 person 类,我肯定会创建一个 person 类的新实例吗?

我很欣赏这里可能缺少一些基本的东西,但如果有人能填补空白,那就太好了。一个真实的例子来证明它的有用性会更好!干杯!

oop constructor object deep-copy

2
推荐指数
1
解决办法
1035
查看次数

创建一个返回一系列随机值的方法

请考虑以下代码.基本思想是返回一个逗号分隔的20个数字列表,其中任何一个数字都可以是介于0和最大允许值之间的值.在每次通过循环时,列表​​中下一个值允许的潜在最大值减少了所选择的最后一个随机值.

所以它有效...但它很糟糕.问题是它总是会产生这样的输出:

"22,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"

"17,3,3,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"

"23,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"

如何修改以允许在整个范围内更均匀地分配值?

    public static string RandomRangeOfValuesMaker(int total)
    {
        var remainingTotal = total + 1;

        const int numberOfValues = 20;

        var rand = new Random();

        var builder = new StringBuilder();

        for (var i = 1; i < numberOfValues + 1; i++)
        {
            var currentRandomNumber = rand.Next(remainingTotal);

            remainingTotal = remainingTotal - currentRandomNumber;

            builder.Append(currentRandomNumber + ",");
        }

        var rangeOfValues = builder.ToString().Remove(builder.ToString().Length - 1);

        return rangeOfValues;
    }
Run Code Online (Sandbox Code Playgroud)

c# random range

0
推荐指数
1
解决办法
306
查看次数