Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: number array with space

by packetstormer (Monk)
on Jun 20, 2013 at 11:42 UTC ( #1039958=note: print w/replies, xml ) Need Help??

in reply to number array with space

Another way, will only work for later versions of Perl

#!/usr/bin/perl use strict; my @arr = ("making","each","day","of","the","year","1"); while ( my($idx,$val) = each (@arr) ){ print "Index is: $idx. Value is: $val\n"; if($val =~ /^\d+$/){ do_my_function($val) } } sub do_my_function { my $v = shift; print "We're in the sub for value: $v\n" }
EDIT: Not sure what happened with my initial post but the comment I had about the regex was, as pointed out by AnomalousMonk, incorrect!

Replies are listed 'Best First'.
Re^2: number array with space
by AnomalousMonk (Canon) on Jun 20, 2013 at 12:48 UTC
    ... the ... regex will fail for an element value of say "222test001" ... it would fire the function ...

    But the regex doesn't seem to match that string at all, so how would it fire the function?. (Have you been naughty and updated your post without making a note of the change?)

    >perl -wMstrict -le "my $val = '222test001'; print $val =~ /^\d+$/ ? 'fire' : 'no match'; " no match

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039958]
[marinersk]: That has always been its behavior, but I'm a visual/spacial- awareness guy. When the node disappears, it messes with my head, even though it is on the right margin.
[marinersk]: I was hoping there was a way to turn it on and make it stay on.
[LanX]: what is the intention of your question?
[LanX]: why do you need to see the nodelet without votes left???

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2017-05-29 13:49 GMT
Find Nodes?
    Voting Booth?