1st..excellent site. I have only tonight stumbled upon what appears to be the plethora of perl information I have been searching for. I am late in life starting my programming journey, however there is no time like the present to start. Perl is my first language and the learning curve seems steep indeed. I am self-teaching using both the Sam's 24 book and the "Camel" book. I am in the first chapters.

With the assistance of Cingular, and cut/paste, I have created a file of all the phone numbers I've called. With my first real code, I would like to open that file and simply identify how many times I've called a particular number. Adding the minutes and such will come at a later time I suppose. I printed the file and manually determined the number of times I have called a number ending with 9432 to be 84 out of nearly 300 entries (for error checking purposes). The code I have written thus far follows:

open (CINGULAR, "c:/documents and Settings/david price/my documents/cingular.txt") || die "cannot open: $!"; @number=<CINGULAR>; close (CINGULAR); $count=0; while ($count<100) { if (@number=~[/^9432$/g]) { print "match found"; } else { print "match failed"; } $count++; }

Upon running, I receive the following errors:

Applying pattern match (m//) to @array will act on scalar (@array)at cingular.pl line 9....and Use of uninitialized value in pattern match +(m//) at cingular.pl line 9.

Obviously my code isn't running, but I'm not sure as to why. I've bound using ~...am looking from beginning to end of line for 9432....each time I look through a line the count in incrementing. Any help would be most welcome.

Thank you.

Edited by davido: Rescued formatting, supplied code tags.


In reply to help manipulating data in an array. by nightfreightpilot

Title:
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, 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:
    & &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.