Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I haven't written perl in a while, so I've forgotten how to tell perl that 0 is valid to initialize a value.

The warning Use of uninitialized value is bugging me a lot. I don't like having any warnings.

I have a list of characters who have appeared in one or more books. There is one character whose first book notation is the number 0. The split on line 10 is said to be uninitialized. On line 12, $first_book in the $first_type is also uninitialized. On line 13, the removal of the non-digit characters in the $first_book, also says $first_book is an uninitialized value. That value is in fact initialized. Because the first book can contain alphabetical characters, I can't simply add a +0 to it.

Any suggestions on how to tell perl that 0 initializes the string?

I did not come up with this notation system, but I can't think of anything to replace it that won't make the data too long. I feel silly asking this, but I can't think of anything right now. Also, if you know who Bink is or recognize the titles of the novels and want to ask me what I am doing; please use PMs. Thanks! 8)

use strict; use warnings; my @novel_list = map { chomp $_; $_ } <DATA>; my $Bink_books = 'M1, M2, m3, m4, 6, m7, M9, m11, m13, 14, 17, m19, m2 +1, M22, m23, m31, 35, 36, m37, m40, m41'; my $Quan_books = '0'; for my $books ($Bink_books, $Quan_books) { my @novels = split(/, /, $books); # $books is initialized for Quan e +ven though the value is 0. my $first_book = $novels[0]; my $first_type = $first_book =~ /^M/ ? 'major' : $first_book =~ /^m/ + ? 'mentioned' : undef; $first_book =~ s/\D//g; my $first_novel = $novel_list[$first_book]; # was my $first_novel = +$novel_list->[$first_book]; print "$first_novel is the first novel the 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
No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

In reply to How to get 0 to initialize a value by Lady_Aleena

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found