如何比较两个perl对象值?

发布于 2025-02-11 14:26:04 字数 593 浏览 0 评论 0 原文

我需要比较两个perl对象值,一个是来自一个变量,另一个是来自阵列值

即时编号,并且数据包含路径指令值(c:\ users \ public \ document \ public \ document),

while (length(basename(dirname(($immediateParent)))) > 1)
{
    $immediateParent = (dirname(($immediateParent)));
    my ($dictionaryitem) = $';
    my $boolean =0;

    foreach $dictionaryitem (@data)
    {
        if ($immediateParent eq $dictionaryitem->[0])
        {
            $boolean = 1;
            last;
        }
    }
        
    if ($boolean)
    {
        last;
    }
}

我试图比较两个路径目录的值,但是这种情况总是返回的,因此无效。您是否友好地建议我如何比较两个路径值?

I need to compare two Perl object values, one is from a variable and another one is from an array value

ImmediateParent and data contain path directive values(C:\Users\Public\Documents)

while (length(basename(dirname(($immediateParent)))) > 1)
{
    $immediateParent = (dirname(($immediateParent)));
    my ($dictionaryitem) = 

I attempted to compare the values of two paths directories, but the condition always returned true, so it was ineffective. Would you kindly advise me on how to compare two path values?

; my $boolean =0; foreach $dictionaryitem (@data) { if ($immediateParent eq $dictionaryitem->[0]) { $boolean = 1; last; } } if ($boolean) { last; } }

I attempted to compare the values of two paths directories, but the condition always returned true, so it was ineffective. Would you kindly advise me on how to compare two path values?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

篱下浅笙歌 2025-02-18 14:26:04

如果 data :: data :: Dumper

$immediateParent = 'C:\\Users\\Public';
$dictionaryitem  = 'C:\\Users\\Public';

则显示您应该直接进行比较而无需阵列,则删除 - > [0]

if ($immediateParent eq $dictionaryitem)

perl让您放置字符串的事实很奇怪。您是否不使用严格

If Data::Dumper shows

$immediateParent = 'C:\\Users\\Public';
$dictionaryitem  = 'C:\\Users\\Public';

then you should compare them directly without array dereference, i.e. remove the ->[0]:

if ($immediateParent eq $dictionaryitem)

The fact that Perl let you dereference a string is weird. Are you not using strict?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文