hsmyers has asked for the wisdom of the Perl Monks concerning the following question:
In the code below, the sub article_title1 shows the error I made and sub article_title2 shows the hack that fixed it. Given this, I've two questions:
#!/perl/bin/perl # use strict; use warnings; use diagnostics; my @text_master = <DATA>; chomp @text_master; my @text = @text_master; article_title1(); print "\n"; @text = @text_master; article_title2(); sub article_title1 { local $_ = shift(@text); # left in for side effect if (@text) { for (@text) { print "# TEXT-1 = '$_'\n"; last if (/^$/); shift(@text); } } print "# TEXT-2 = '$_'\n" for @text; } sub article_title2 { local $_ = shift(@text); # left in for side effect if (@text) { my @text_copy = @text; for (@text) { print "# TEXT-1 = '$_'\n"; last if (/^$/); shift(@text_copy); } @text = @text_copy; } print "# TEXT-2 = '$_'\n" for @text; } __DATA__ ==Play Chess: Click the join icon to play Matches_Sought.gif Matches Sought Graph You can also start a game by clicking a dot in the Matches Sought grap +h. Rest the mouse pointer over a dot. Games on ICC are often described by their time limits.
Which results in:
# TEXT-1 = 'Click the join icon to play' # TEXT-1 = 'Matches_Sought.gif Matches Sought Graph' # TEXT-1 = 'You can also start by clicking a dot in the graph.' # TEXT-1 = 'Rest the mouse pointer over a dot.' # TEXT-1 = 'Games on ICC are often described by their time limits.' # TEXT-2 = '' # TEXT-2 = 'Rest the mouse pointer over a dot.' # TEXT-2 = '' # TEXT-2 = 'Games on ICC are often described by their time limits.' # TEXT-1 = 'Click the join icon to play' # TEXT-1 = '' # TEXT-2 = '' # TEXT-2 = 'Matches_Sought.gif Matches Sought Graph' # TEXT-2 = '' # TEXT-2 = 'You can also start by clicking a dot in the graph.' # TEXT-2 = '' # TEXT-2 = 'Rest the mouse pointer over a dot.' # TEXT-2 = '' # TEXT-2 = 'Games on ICC are often described by their time limits.'
--hsm
"Never try to teach a pig to sing...it wastes your time and it annoys the pig."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: for mistake with shift
by cees (Curate) on Dec 31, 2003 at 05:32 UTC | |
by hsmyers (Canon) on Dec 31, 2003 at 06:46 UTC | |
|
Re: for mistake with shift
by NetWallah (Canon) on Dec 31, 2003 at 05:52 UTC | |
|
Re: for mistake with shift
by Roger (Parson) on Dec 31, 2003 at 11:09 UTC | |
by hsmyers (Canon) on Dec 31, 2003 at 15:00 UTC | |
by hsmyers (Canon) on Dec 31, 2003 at 15:25 UTC | |
|
Re: for mistake with shift
by Roy Johnson (Monsignor) on Dec 31, 2003 at 19:40 UTC |