Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

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

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":



  • 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 sharing their wisdom with the Monastery: (6)
As of 2024-04-23 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found