Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: number array with space

by CountZero (Bishop)
on Jun 20, 2013 at 06:15 UTC ( [id://1039888]=note: print w/replies, xml ) Need Help??


in reply to Re: number array with space
in thread number array with space

Or a more Perlish way of using indexes (works only in a fairly recent version of Perl):
use Modern::Perl; my @array = qw/een twee drie vier vijf zes zeven/; for my $index (keys @array) { say "$index: $array[$index]"; }

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Replies are listed 'Best First'.
Re^3: number array with space
by 2teez (Vicar) on Jun 20, 2013 at 06:21 UTC

    (works only in a fairly recent version of Perl):
    of course yes! in Perl 5.12 or better !!!. Nice one...

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
      Hey

      one more question that how to check whether the element in an array is a number or not . is there any function in perl

        See Scalar::Util, and its function "looks_like_number". The module is core, meaning it ships with Perl.


        Dave

        See looks_like_number in Scalar::Util like thus:

        use Scalar::Util qw(looks_like_number); for(qw(1 perl 25 monks)){ looks_like_number $_ ? print $_," is a Number",$/ : print $_," is not a Number",$/; }
        Update:
        Awooooshhhh! davido, beat me to it.....

        If you tell me, I'll forget.
        If you show me, I'll remember.
        if you involve me, I'll understand.
        --- Author unknown to me

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1039888]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-25 19:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found