I applaud your willingness to post an actual example script and actual example data. Please allow me to offer a number of points:
- It's often better to specify a minimum version of perl. See also Perl::MinimumVersion.
- A small amount of sample data is often as good as more.
- Limit lines to
78 columns.
Continuations are okay. If I really did
need to hardcode a big paragraph, though, I might
read it in from <DATA>. See perldata, Special Literals.
- Proper indentation and spacing go a long way toward making code readable.
- Use interpolating quotes only when you want to interpolate.
- atcroft is correct in that your original script attempts to perform substitution on $_ ("it"); if successful, the expression evaluates to the number of substitutions performed.
The following script attempts to illustrate each of the points above.
use 5.010000;
use strict;
use warnings;
use diagnostics;
my @foo = (qw| Pear Apple AppleTomatoApple |);
for ( @foo ) {
my $text = 'Apple has determined, '
. 'the iPod nano '
. 'may overheat. '
;
my $assign = 'Blueberry jam vendor!';
$text =~ s/Apple/Mango/g; # sub's on $text
$assign = s/Apple/Mango/g; # sub's on $_ and yields num of su
+ccess
say '$text: ', $text, "\t", '$assign: ', $assign, "\t", '$_: ', $_
+;
};
I'm not the guy you kill, I'm the guy you buy. —Michael Clayton
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.