Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Re: Initialize array

by aijin (Monk)
on Jul 03, 2001 at 23:12 UTC ( #93640=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Initialize array
in thread Initialize array

Instead of your if ($number > $#lines | $number <=0) section, you could try something like this:

if (defined $lines[$number1 - 1]) { print $lines[$number1 - 1]; print "\n"; } else { print "No link at that index\n"; }

This will check if there's a value at the spot in the array. This will benefit you if, in the future, you expand your code to delete links, or if you accidentally have blank lines in your input file.

As always, TMTOWTDI.


Comment on Re: Re: Re: Initialize array
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://93640]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2014-09-16 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (13 votes), past polls