How can I iterate through nested arrays?

后端 未结 5 664
独厮守ぢ
独厮守ぢ 2021-01-22 03:59

I have created an array as follows

while (defined ($line = ``))

        {
        chomp ($line);
        push @stack,($line);
        }
         


        
5条回答
  •  暖寄归人
    2021-01-22 04:17

    #!/usr/bin/perl
    
    while ($line = ) {
        chomp ($line);
        push @stack, $line;
    }
    
    # prints each line
    foreach $line (@stack) {
        print "$line\n";
    }
    
    # splits each line into items using ' ' as separator
    # and prints the items
    foreach $line (@stack) {
        @items = split / /, $line;
    
        foreach $item (@items) {
            print $item . "\n";
        }
    }
    

提交回复
热议问题