Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Greetings all,
A few suggestions...
To access the variables that reside in your @number array you will need to refer to them as scalars so $number[0] would give you the first element of your array.
To get the size of your array use scalar @number
Now going through an array can be accomplished in a myriad of different ways but here are two of the more common ones aside from the while loop you already have.
#the foreach style sets a variable, in this case $num, to #each element of your array. If you did not specify a #variable, then the special variable $_ would be set #each time through. foreach my $num (@number){ if($num =~ /9432$/){ print "match found"; }else{ print "match failed"; } } #a C-style for loop in which case you will be using #the $i variable to count from 0 to the end of your array #based on how big it is which we now know is scalar @number. for(my $i=0 ; $i < scalar @number ; $i++){ if($number[$i] =~ /9432$/){ print "match found"; }else{ print "match failed"; } }
One last thing if you are looking for number ending in some sequence of digits, in this case '9432' you do not need to use the ^ anchor, just the $ anchor, since the ^ indicates to the regexp engine that you are checking from the beginning of the string. The $ indicates the end of the string, so your pattern would be /9432$/ since you are trying to match the end.
I hope that helps.

-InjunJoel

"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

In reply to Re: help manipulating data in an array. by injunjoel
in thread 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 perusing the Monastery: (6)
As of 2024-03-29 14:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found