How would you test if an element exists? I have a file that is read in and splits the line up into and array based on commas. Im looking for the data that exists in the 6th element. Some lines are blank or just has a comma. How would I have the script check to see if the 6th element exists before it processes the line? Here's my code below and also a copy of what the file looks like:
heres what the file looks like:
20060819,02159,045488061,00 ,0000118,0000000,0000000,0000118,0000000,0
+000000,Zachary ,G
20060819,02159,045775830,00 ,0000649,0000028,0000000,0000649,0000028,0
+000000,
,
20060819,02161,023416381,09 ,0000034,0000000,0000000,0000034,0000000,0
+000000,Erinne ,H
Here's the code I have:
while ($line = <OUTF>) {
my @array = split(/,/ , $line);
$test = @array;
print "$array[5] offers and $test is number of elements\n";
if ($array[5] =~ /0000000/ || $array[5] =~ //) { # the 2nd part is
+ obviously wrong
print "$store_number is not BCE Store\n";
} else {
$store_number = $array[1];
print "Store # $store_number\n";
push(@st_n, $store_number);
}
}
I need it to capture the line with just the comma, or if its a blank line. Let me know if you have any questions....
Thanks,
Bob
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.