Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Others have pointed out that the OPed code seems to work just fine once the
    my $first_novel = $novel_list->[$first_book];
statement is fixed to be
    my $first_novel = $novel_list[$first_book];

Somewhat off-topic, may I suggest that a better approach might be to use a hash:

use strict; use warnings; my @novel_list = <DATA>; chomp @novel_list; my %characters = ( Bink => 'M1, M2, m3, m4, 6, m7, M9, m11, m13, 14, 17, m19, m21, M2 +2, m23, m31, 35, 36, m37, m40, m41', Quan => '0', ); for my $character (sort keys %characters) { my @appearances = split m{ \s* , \s* }xms, $characters{$character}; my $first_book = $appearances[0]; my $first_type = $first_book =~ /^M/ ? 'major' : $first_book =~ /^m/ + ? 'mentioned' : undef; (my $i_first_novel = $first_book) =~ s/\D+//g; my $first_novel = $i_first_novel ? qq{"$novel_list[$i_first_novel]"} : "[$novel_list[$i_first_novel]]" ; print "$first_novel is the first novel '$character' was in. \n"; } __DATA__ Other source A Spell for Chameleon The Source of Magic Castle Roogna Centaur Aisle Ogre, Ogre Night Mare Dragon on a Pedestal Crewel Lye: A Caustic Yarn Golem in the Gears Vale of the Vole Heaven Cent Man from Mundania Isle of View Question Quest The Color of Her Demons Don't Dream Harpy Thyme Geis of the Gargoyle Roc and a Hard Place Yon Ill Wind Faun and Games Zombie Lover Xone of Contention The Dastard Swell Foop Up in a Heaval Cube Route Currant Events Pet Peeve Stork Naked Air Apparent Two to the Fifth Jumper Cable Knot Gneiss Well-Tempered Clavicle Luck of the Draw Esrever Doom Board Stiff Five Portraits Isis Orb Ghost Writer in the Sky
c:\@Work\Perl\monks\Lady_Aleena>perl "A Spell for Chameleon" is the first novel 'Bink' was in. [Other source] is the first novel 'Quan' was in.

Give a man a fish:  <%-{-{-{-<

In reply to Re: How to get 0 to initialize a value by AnomalousMonk
in thread How to get 0 to initialize a value by Lady_Aleena

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (6)
    As of 2019-10-23 05:41 GMT
    Find Nodes?
      Voting Booth?