AnyCompiler

Closing Thoughts

Ye course ek aisi language cover karta hai jo is site ki har doosri cheez se genuinely alag tarike se kaam karti hai: sigils jo data type ko directly variable ke naam mein encode karte hain ($scalar, @array, %hash); context, jahan wahi exact same expression alag-alag matlab rakhta hai depend karta hai ki Perl ko ek value chahiye ya unki ek list; regular expressions jo language ke apne grammar mein built hain, library ke taur par bolt-on nahi; aur references, jo Perl ke teen flat core types ko arbitrarily deep nested structures mein combine hone dete hain.

Wo last idea — references ka flat types ko kuch richer mein stitch karna — ek aur baar combined dekhne layak hai: hash references ka ek array, foreach se iterate kiya gaya, -> arrow se har ek ke andar reach kiya gaya, aur map se ek plain list mein reduce kiya gaya.

use strict;
use warnings;

my @inventory = (
    { name => "Widget", qty => 4 },
    { name => "Gadget", qty => 7 },
);

my $total = 0;
$total += $_->{qty} for @inventory;

my @names = map { $_->{name} } @inventory;

print "Items: @names\n";
print "Total quantity: $total\n";
Output
Items: Widget Gadget
Total quantity: 11

Yahi idiomatic Perl ka core hai: sigils aur context bohot sa quiet, implicit kaam karte hain, regex aur list-processing functions wo heavy lifting karte hain jo warna ek loop ko karni padti, aur references underneath poori structure ko saath mein hold karte hain. Naye lessons regularly add hote hain — is lesson ko poora karne ke liye thanks.

Practice exercise

my %scores = (Alice => 90, Bob => 75, Carol => 88) diya gaya hai, har name aur score print karo, highest score pehle, ek line par ek "Name: Score" ke taur par.

← Error HandlingAur lessons jald aa rahe hain