Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: ask about array and hash

by xtype (Deacon)
on Jan 17, 2002 at 09:04 UTC ( [id://139446]=note: print w/replies, xml ) Need Help??


in reply to ask about array and hash

Or you can loop through them to print the elements:
#!/usr/bin/perl -w use strict; my @array = qw(a b c d e f g); my %hash = ( '1st' , 'a', '2nd' , 'b', '3rd' , 'c', ); while (<@array>) { print; } foreach my $key (sort keys %hash) { print "$key: $hash{$key}\n"; }

Replies are listed 'Best First'.
(crazyinsomniac) Re^2: ask about array and hash
by crazyinsomniac (Prior) on Jan 17, 2002 at 10:01 UTC
      Indeed. I wanted to show that there was more than one way to print and or access the data in an array or hash. Hence my using a foreach loop in the second example, also showing use of sort(). I am sorry if my globbing offended you in anyway. -xtype

Log In?
Username:
Password:

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

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

    No recent polls found