Beefy Boxes and Bandwidth Generously Provided by pair Networks BBQ
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Extra Stuff

by traveler (Parson)
on Apr 16, 2001 at 22:25 UTC ( [id://72978]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Extra Stuff

Some monks have suggested an array, but that is not always the best data structure (and splitting to lists of names in encouraged in the Camel book). I have used (expecting 3 fields):
my $count = my ($fa, $fb, $fc, $stuff) = split; die if $count != 3;
Of course, you needn't die and you can use the $stuff in an error message.

--traveler

Replies are listed 'Best First'.
Re: Re: Extra Stuff
by qball (Beadle) on Apr 16, 2001 at 22:32 UTC
    Well, here's my solution:
    foreach $rec (@CUSTDATA) { chomp $rec; @array = split(/,/,$rec); #count number of elements in array for error checking $num_of_elements = scalar @array; if($num_of_elements == '14'){ do whatever... @array[0]...@array[10]... } }

    Should work well...I'm currently testing it now, so we'll see what happens.

    qball~"I have node idea?!"

      You may want to clean this code up a bit. Namely, the $num_of_elements variable is unnecessary and your check for '14' items should check for 14 items instead. Something like:
      #make sure we have the right number of elements carp "Incorrect number of elements" if @array != 14; #continue with the program...
      Since you're checking the @array against a number it's automatically in scalar context. Also, putting it in one line allows you to continue your program without wrapping a large chunk of code in an if statement, which could confuse readability (where did this `}' come from?).

      Hope That Helps,
      jynx

      So you are dropping data, don't know why, and have chosen to not log or investigate?

      I am glad that is not my data!

      Before going with a band-aid like this, you should go through the files looking for lines that don't split into 14 parts and try to figure out the cause...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://72978]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.