akio_outori has asked for the wisdom of the Perl Monks concerning the following question:
In this example, @test3 ends up being a single element array with element[0] being "md1". I was wondering if anyone could point me to documentation showing why this would happen, and possibly a fix? I've had no luck finding the cause.#!/usr/bin/perl use strict; use warnings; my @test = ('md1', 'md2', 'md3', 'md4'); my $test2 = ""; my @test3 = (); foreach my $line (@test) { if ($line =~ /md/) { push @test3, $line; } } printf @test3;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Seemingly odd issue with push in foreach loops?
by hdb (Monsignor) on Apr 23, 2015 at 21:15 UTC | |
|
Re: Seemingly odd issue with push in foreach loops?
by BrowserUk (Patriarch) on Apr 23, 2015 at 21:13 UTC | |
|
Re: Seemingly odd issue with push in foreach loops?
by einhverfr (Friar) on Apr 24, 2015 at 06:44 UTC | |
|
Re: Seemingly odd issue with push in foreach loops?
by akio_outori (Initiate) on Apr 23, 2015 at 21:36 UTC |