lost array element in 5.8

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Farhad

    lost array element in 5.8

    Hi,

    in the following example there is a output difference in version 5.00 and
    5.8 of Perl. In case of a missmatch in element 2, the whole element gets
    lost instead of an "undef" value. Does anybody know why in version 5.8 we
    lost the element and is that an error in Perl interpreter or does it work as
    designed.

    Thanks
    Farhad

    ----------------------------------

    #!/usr/local/bin/perl -w

    my $var="Test";
    my @list=('a', # Element 1
    $var=~m/\n/, # Element 2
    $var=~m/es/ # Element 3
    );

    print scalar(@list)." (should be 3)\n";

    push @list, {
    'd' => $var=~m/\n/, # Element 4
    };


    print scalar(@list)." (should be 4)\n"



  • Steve Grazzini

    #2
    Re: lost array element in 5.8

    Farhad <farhad.fouladi @dresdner-bank.com> wrote:[color=blue]
    > my $var="Test";
    > my @list=('a', # Element 1
    > $var=~m/\n/, # Element 2
    > $var=~m/es/ # Element 3
    > );
    >
    > print scalar(@list)." (should be 3)\n";[/color]

    No, it should be 2. m// in list context returns an empty list when
    the match fails.

    --
    Steve

    Comment

    • Jim

      #3
      Re: lost array element in 5.8

      Hi Farhad,

      i believe 5.8 works as designed.

      try running your script in the debugger:
      perl -d yourscriptname. pl

      step through the commands using s, the first time, then return.

      in the debugger, try:
      p $var =~ /\n/
      and
      p $var =~ /es/

      also, play with:
      x @list

      i do not see why $var would match a newline.

      hope this helps, good luck.

      Jim

      "Farhad" <farhad.fouladi @dresdner-bank.com> wrote in message news:<bkev06$gc s2@news-1.bank.dresdner .net>...[color=blue]
      > Hi,
      >
      > in the following example there is a output difference in version 5.00 and
      > 5.8 of Perl. In case of a missmatch in element 2, the whole element gets
      > lost instead of an "undef" value. Does anybody know why in version 5.8 we
      > lost the element and is that an error in Perl interpreter or does it work as
      > designed.
      >
      > Thanks
      > Farhad
      >
      > ----------------------------------
      >
      > #!/usr/local/bin/perl -w
      >
      > my $var="Test";
      > my @list=('a', # Element 1
      > $var=~m/\n/, # Element 2
      > $var=~m/es/ # Element 3
      > );
      >
      > print scalar(@list)." (should be 3)\n";
      >
      > push @list, {
      > 'd' => $var=~m/\n/, # Element 4
      > };
      >
      >
      > print scalar(@list)." (should be 4)\n"[/color]

      Comment

      Working...