in reply to Re: Re: loop control
in thread loop control
I get the output#!/usr/bin/perl -w use strict; my $out = '<?xml version="1.0" encoding="utf-8"?>'; my @tmp = split /</, $out; foreach(@tmp) { if (substr($_, 0, 1) eq "?") { print "conditionA matched - looping!\n"; next; } elsif (substr($_, 0, 1) eq "!") { print "conditionB matched\n"; } print "End of loop\n"; }
as expected. (Note that the split is returning a list of two scalars, not just one: the 0 characters before the < and the n characters after it.)End of loop conditionA matched - looping!
Side note: That feels a lot like C. Changing your tests to if (/^\?/) and if (/^!/) would feel perlier. Should work either way, though.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: loop control
by Galen (Beadle) on May 22, 2002 at 17:34 UTC |